in Swift/KVSiOSApp/ChannelConfigurationViewController.swift [97:165]
func connectAsRole(role: String, connectAsUser: String) {
guard let channelNameValue = self.channelName.text?.trim(), !channelNameValue.isEmpty else {
let alertController = UIAlertController(title: "Missing Required Fields",
message: "Channel name is required for WebRTC connection",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
return
}
guard let awsRegionValue = self.regionName.text?.trim(), !awsRegionValue.isEmpty else {
let alertController = UIAlertController(title: "Missing Required Fields",
message: "Region name is required for WebRTC connection",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
return
}
self.awsRegionType = awsRegionValue.aws_regionTypeValue()
if (self.awsRegionType == .Unknown) {
let alertController = UIAlertController(title: "Invalid Region Field",
message: "Enter a valid AWS region name",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
return
}
if (self.clientID.text!.isEmpty) {
self.localSenderId = NSUUID().uuidString.lowercased()
print("Generated clientID is \(self.localSenderId)")
}
// Kinesis Video Client Configuration
let configuration = AWSServiceConfiguration(region: self.awsRegionType, credentialsProvider: AWSMobileClient.default())
AWSKinesisVideo.register(with: configuration!, forKey: awsKinesisVideoKey)
retrieveChannelARN(channelName: channelNameValue)
if self.channelARN == nil {
createChannel(channelName: channelNameValue)
}
getSignedWSSUrl(channelARN: self.channelARN!, role: role, connectAs: connectAsUser, region: awsRegionValue)
print("WSS URL :", wssURL?.absoluteString as Any)
var RTCIceServersList = [RTCIceServer]()
for iceServers in self.iceServerList! {
RTCIceServersList.append(RTCIceServer.init(urlStrings: iceServers.uris!, username: iceServers.username, credential: iceServers.password))
}
RTCIceServersList.append(RTCIceServer.init(urlStrings: ["stun:stun.kinesisvideo." + self.regionName.text! + ".amazonaws.com:443"]))
webRTCClient = WebRTCClient(iceServers: RTCIceServersList, isAudioOn: sendAudioEnabled)
webRTCClient!.delegate = self
print("Connecting to web socket from channel config")
signalingClient = SignalingClient(serverUrl: wssURL!)
signalingClient!.delegate = self
signalingClient!.connect()
let seconds = 2.0
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
self.updateConnectionLabel()
self.vc = VideoViewController(webRTCClient: self.webRTCClient!, signalingClient: self.signalingClient!, localSenderClientID: self.localSenderId, isMaster: self.isMaster!)
self.present(self.vc!, animated: true, completion: nil)
}
}