in Swift/KVSiOSApp/ChannelConfigurationViewController.swift [233:320]
func getSignedWSSUrl(channelARN: String, role: String, connectAs: String, region: String) {
let singleMasterChannelEndpointConfiguration = AWSKinesisVideoSingleMasterChannelEndpointConfiguration()
singleMasterChannelEndpointConfiguration?.protocols = videoProtocols
singleMasterChannelEndpointConfiguration?.role = getSingleMasterChannelEndpointRole()
var httpResourceEndpointItem = AWSKinesisVideoResourceEndpointListItem()
var wssResourceEndpointItem = AWSKinesisVideoResourceEndpointListItem()
let kvsClient = AWSKinesisVideo(forKey: awsKinesisVideoKey)
let signalingEndpointInput = AWSKinesisVideoGetSignalingChannelEndpointInput()
signalingEndpointInput?.channelARN = channelARN
signalingEndpointInput?.singleMasterChannelEndpointConfiguration = singleMasterChannelEndpointConfiguration
kvsClient.getSignalingChannelEndpoint(signalingEndpointInput!).continueWith(block: { (task) -> Void in
if let error = task.error {
print("Error to get channel endpoint: \(error)")
} else {
print("Resource Endpoint List : ", task.result!.resourceEndpointList!)
}
guard (task.result?.resourceEndpointList) != nil else {
let alertController = UIAlertController(title: "Invalid Region Field",
message: "No endpoints found",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
return
}
for endpoint in task.result!.resourceEndpointList! {
switch endpoint.protocols {
case .https:
httpResourceEndpointItem = endpoint
case .wss:
wssResourceEndpointItem = endpoint
case .unknown:
print("Error: Unknown endpoint protocol ", endpoint.protocols, "for endpoint" + endpoint.description())
}
}
AWSMobileClient.default().getAWSCredentials { credentials, _ in
self.AWSCredentials = credentials
}
var httpURlString = (wssResourceEndpointItem?.resourceEndpoint!)!
+ "?X-Amz-ChannelARN=" + self.channelARN!
if !self.isMaster! {
httpURlString += "&X-Amz-ClientId=" + self.localSenderId
}
let httpRequestURL = URL(string: httpURlString)
let wssRequestURL = URL(string: (wssResourceEndpointItem?.resourceEndpoint!)!)
usleep(5)
self.wssURL = KVSSigner
.sign(signRequest: httpRequestURL!,
secretKey: (self.AWSCredentials?.secretKey)!,
accessKey: (self.AWSCredentials?.accessKey)!,
sessionToken: (self.AWSCredentials?.sessionKey)!,
wssRequest: wssRequestURL!,
region: region)
// Get the List of Ice Server Config and store it in the self.iceServerList.
let endpoint =
AWSEndpoint(region: self.awsRegionType,
service: .KinesisVideo,
url: URL(string: httpResourceEndpointItem!.resourceEndpoint!))
let configuration =
AWSServiceConfiguration(region: self.awsRegionType,
endpoint: endpoint,
credentialsProvider: AWSMobileClient.default())
AWSKinesisVideoSignaling.register(with: configuration!, forKey: awsKinesisVideoKey)
let kvsSignalingClient = AWSKinesisVideoSignaling(forKey: awsKinesisVideoKey)
let iceServerConfigRequest = AWSKinesisVideoSignalingGetIceServerConfigRequest.init()
iceServerConfigRequest?.channelARN = channelARN
iceServerConfigRequest?.clientId = self.localSenderId
kvsSignalingClient.getIceServerConfig(iceServerConfigRequest!).continueWith(block: { (task) -> Void in
if let error = task.error {
print("Error to get ice server config: \(error)")
} else {
self.iceServerList = task.result!.iceServerList
print("ICE Server List : ", task.result!.iceServerList!)
}
}).waitUntilFinished()
}).waitUntilFinished()
}