awslabs / amazon-kinesis-video-streams-webrtc-sdk-ios

iOS SDK for interfacing with the Amazon Kinesis Video Streams Signaling Service.
Apache License 2.0
66 stars 29 forks source link

Not working this object (AWSKinesisVideoCreateSignalingChannelInput()) #82

Closed Bhoon-coding closed 1 year ago

Bhoon-coding commented 1 year ago

Thesedays app often terminate. because this object initialize value. The object is AWSKinesisVideoCreateSignalingChannelInput() in createChannel method I double checked channelName and region(ap-northeast-2)

Snipaste_2023-11-16_11-45-30 Snipaste_2023-11-16_11-45-09

Plz, let me know what do I miss

sirknightj commented 1 year ago

In your logs, I see it says faulted = YES. In the completionHandler, you can add:

if let error = task.error as? NSError {
  print("Error occurred: \(error)")
  return nil
}
Bhoon-coding commented 1 year ago

I tried your suggestion but app terminated again.

func createChannel(channelName: String) -> String? {
        print("channelName: \(channelName)")
        var channelARN : String?
        /*
            equivalent AWS CLI command:
            aws kinesisvideo create-signaling-channel --channel-name channelName --region cognitoIdentityUserPoolRegion
        */
        let kvsClient = AWSKinesisVideo(forKey: awsKinesisVideoKey)
        let createSigalingChannelInput = AWSKinesisVideoCreateSignalingChannelInput.init()
        createSigalingChannelInput?.channelName = channelName
        kvsClient.createSignalingChannel(createSigalingChannelInput!).continueWith(block: { (task) -> Void in
            if let error = task.error as? NSError {
                print("Error occurred: \(error)")
                print("Error occurred message: \(error.localizedDescription)")
                return
            }
            print("task: \(task)")
            sleep(3)
            print("3second later task status: \(task)")
            sleep(5)
            print("ChannelARN: \(task.result?.channelARN)")
            channelARN = task.result?.channelARN
        }).waitUntilFinished()
        print("ARN out?: \(channelARN)")
        return channelARN
    }

here is error log

Snipaste_2023-11-16_14-36-26

Error occurred: Error Domain=com.amazonaws.AWSKinesisVideoErrorDomain Code=11 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=ResourceInUseException:https://kinesisvideo.amazonaws.com/doc/2017-09-30/}
2023-11-16 14:34:32.702535+0900 AWSKinesisVideoWebRTCDemoApp[1738:408284] -[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x222040250
2023-11-16 14:34:32.707969+0900 AWSKinesisVideoWebRTCDemoApp[1738:408284] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x222040250'
*** First throw call stack:
(0x1c9cc948c 0x1c2fb5050 0x1c9e2a424 0x1c9cde938 0x1c9d4097c 0x1c3d35c34 0x1c3d35e60 0x1c428b16c 0x100e0b624 0x100e0ba88 0x100e0bb20 0x10199ac44 0x1019464dc 0x101946e5c 0x10199b038 0x10199a67c 0x10199a19c 0x10199c064 0x1019b520c 0x10199b4e8 0x10199ac44 0x1019464dc 0x101946e5c 0x10199ab10 0x10199b3b4 0x10199b59c 0x1019b35dc 0x1cacaa0cc 0x101d47f08 0x101d497a0 0x101d508e4 0x101d515b8 0x101d5d0ac 0x213b8fbd0 0x213b8f720)
libc++abi: terminating due to uncaught exception of type NSException
Bhoon-coding commented 1 year ago

And this closed issue is same issue (link)

sirknightj commented 1 year ago

ResourceInUseException (code=11) is thrown when the signaling channel already exists within your AWS account in that region. Signaling channel name must be unique. If one already exists, you should use that instead of creating a new one. Depending on the way you want your application to run, it may be better to create/provision the signaling channels outside of this application to minimize the amount of permissions you need to grant to the IAM user.

Here is a brief explanation of how the sample currently works: https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios/blob/5d1a1d6b759397d4e1f179ad74247779b36c4fb6/Swift/KVSiOSApp/ChannelConfigurationViewController.swift#L115-L116

Bhoon-coding commented 1 year ago

I tried change channelName, but same issue again.. retrieveChannelARN is annotation. when I build first, and then try connect as a Master only called createchannel method. but app is terminated.

sirknightj commented 1 year ago

To retrieve an existing channel ARN, provided the channel name, you can use describeSignalingChannel REST API.

For more information, refer to the AWS SDK for iOS documentation or the Kinesis Video Streams with WebRTC documentation.

The sample code can be found here: https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios/blob/5d1a1d6b759397d4e1f179ad74247779b36c4fb6/Swift/KVSiOSApp/ChannelConfigurationViewController.swift#L231-L252

Bhoon-coding commented 1 year ago

Yes, but If I can't retrieve channelARN, call createChannel() and then app terminated here is my error log

023-11-17 15:40:30.445614+0900 AWSKinesisVideoWebRTCDemoApp[24963:1156914] Warning: A long-running operation is being executed on the main thread. 
 Break on awsbf_warnBlockingOperationOnMainThread() to debug.
Error occurred: Error Domain=com.amazonaws.AWSKinesisVideoErrorDomain Code=11 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=ResourceInUseException:https://kinesisvideo.amazonaws.com/doc/2017-09-30/}
2023-11-17 15:40:31.662143+0900 AWSKinesisVideoWebRTCDemoApp[24963:1157238] -[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x1faeafa88
2023-11-17 15:40:31.668931+0900 AWSKinesisVideoWebRTCDemoApp[24963:1157238] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x1faeafa88'
*** First throw call stack:
(0x1807dfc80 0x198005ee4 0x1808b0708 0x18077956c 0x18077877c 0x1850abfa4 0x1850ac154 0x1850ac334 0x184bf6e18 0x100403624 0x100403a88 0x100403b20 0x100f56c44 0x100f024dc 0x100f02e5c 0x100f57038 0x100f5667c 0x100f5619c 0x100f58064 0x100f7120c 0x100f574e8 0x100f56c44 0x100f024dc 0x100f02e5c 0x100f56b10 0x100f573b4 0x100f5759c 0x100f6f5dc 0x180f42984 0x1009b0700 0x1009b1fc8 0x1009b9150 0x1009b9e10 0x1009c563c 0x1dbb44e00 0x1dbb4492c)
libc++abi: terminating with uncaught exception of type NSException

what do I miss.. I just wondering what is the problem below method

kvsClient.createSignalingChannel(createSigalingChannelInput!).continueWith(block: { (task) -> Void in

}
sirknightj commented 1 year ago

Seems fine, make sure to include waitUntilFinished(): https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios/blob/5d1a1d6b759397d4e1f179ad74247779b36c4fb6/Swift/KVSiOSApp/ChannelConfigurationViewController.swift#L211-L229

Can you try using the aws cli to make the same createSignalingChannel API call with the same arguments you are passing into your iOS app and see what it prints out?

For me:

aws kinesisvideo create-signaling-channel --channel-name "testing" --region us-west-2
{
    "ChannelARN": "arn:aws:kinesisvideo:us-west-2:x:channel/testing/1700205141855"
}

aws kinesisvideo create-signaling-channel --channel-name "testing" --region us-west-2

An error occurred (ResourceInUseException) when calling the CreateSignalingChannel operation: The channel testing already exists.
Bhoon-coding commented 1 year ago

When I typing this cli aws kinesisvideo create-signaling-channel --channel-name "testing" --region ap-northeast-2

I got this Unable to locate credentials. You can configure credentials by running "aws configure".

And how can I use this below? 스크린샷 2023-11-17 오후 4 31 51

sirknightj commented 1 year ago

You can follow the aws cli instructions to configure credentials to use the aws cli. AWS CLI is an alternate method to invoke the same API, making it easier to see if the issue is with your iOS code or an issue with the parameters passed into the API command. Once the channel is created, you can use the describe-signaling-channel command to obtain the ARN.

aws kinesisvideo describe-signaling-channel --channel-name "testing" --region us-west-2
{
    "ChannelARN": "arn:aws:kinesisvideo:us-west-2:x:channel/testing/1700205141855"
}

Signaling channel names must be unique within your AWS account and region. For example, I can have a channel named "testing" in us-west-2 and another channel named "testing" in ap-northeast-2. You can also have one channel named "testing" in ap-northeast-2 in your AWS account. But, I cannot create another channel "testing" in my account in us-west-2 unless I delete the previous one. Depending on your use case, you can either re-use the same channel, or delete/create a new one.

Once you obtain the signaling channel ARN, you can use it as an input to other kinesis video API requests, like UpdateMediaStorageConfiguration or getSignalingChannelEndpoint.

sirknightj commented 1 year ago

I ran the sample app in this repo without any code changes, using the create new channel functionality. Signaling channel with name "testing3" does not exist in my AWS account, meaning that the application should create one.

https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios/assets/14988194/2c8c55ee-9847-485b-a4fc-592fbb893a48

Some logs from my run:

Generated clientID is 019c549f-db19-4c6d-8710-cfc395e38da7
2023-11-20 10:53:14.856271-0800 AWSKinesisVideoWebRTCDemoApp[463:14671] Warning: A long-running operation is being executed on the main thread. 
 Break on awsbf_warnBlockingOperationOnMainThread() to debug.
Error describing channel: Error Domain=com.amazonaws.AWSKinesisVideoErrorDomain Code=12 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=ResourceNotFoundException:https://kinesisvideo.amazonaws.com/doc/2017-09-30/}
2023-11-20 10:53:15.004661-0800 AWSKinesisVideoWebRTCDemoApp[463:14671] Warning: A long-running operation is being executed on the main thread. 
 Break on awsbf_warnBlockingOperationOnMainThread() to debug.
Channel ARN :  Optional("arn:aws:kinesisvideo:us-west-2:x:channel/testing3/1700506395046")
2023-11-20 10:53:15.144163-0800 AWSKinesisVideoWebRTCDemoApp[463:14671] Warning: A long-running operation is being executed on the main thread. 
 Break on awsbf_warnBlockingOperationOnMainThread() to debug.
2023-11-20 10:53:15.193729-0800 AWSKinesisVideoWebRTCDemoApp[463:14671] Warning: A long-running operation is being executed on the main thread. 
 Break on awsbf_warnBlockingOperationOnMainThread() to debug.

As you can see, since describeSignalingChannel failed with ResourceNotFoundException, createSignalingChannel was called (Channel ARN : log line): https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-ios/blob/5d1a1d6b759397d4e1f179ad74247779b36c4fb6/Swift/KVSiOSApp/ChannelConfigurationViewController.swift#L224

Bhoon-coding commented 1 year ago

thank you for testing and show your log. I think the error cause only called createChannel() without calling retrieveChannelARN() It works for me, when I call retrieveChannelARN() and then createChannel()