GetStreamSession Swift3 Example
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()!
var success: Bool
let authAws = CkoAuthAws()!
authAws.accessKey = "AWS_ACCESS_KEY"
authAws.secretKey = "AWS_SECRET_KEY"
// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
authAws.region = "us-west-2"
authAws.serviceName = "ivs"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://ivs.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("ivs.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.connectFailReason.intValue)")
print("\(rest.lastErrorText!)")
return
}
// The following code creates the JSON request body.
// The JSON created by this code is shown below.
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
let json = CkoJsonObject()!
json.update("channelArn", value: "string")
json.update("streamId", value: "string")
// The JSON request body created by the above code:
// {
// "channelArn": "string",
// "streamId": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "GetStreamSession")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/GetStreamSession", requestBody: sbRequestBody, responseBody: sbResponseBody)
if success != true {
print("\(rest.lastErrorText!)")
return
}
var respStatusCode: Int = rest.responseStatusCode.intValue
print("response status code = \(respStatusCode)")
if respStatusCode != 200 {
print("Response Header:")
print("\(rest.responseHeader!)")
print("Response Body:")
print("\(sbResponseBody.getAsString()!)")
return
}
let jResp = CkoJsonObject()!
jResp.loadSb(sbResponseBody)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
var eventTime: Int
var name: String?
var v_type: String?
var Arn: String? = jResp.string(of: "streamSession.channel.arn")
var Authorized: Int = jResp.int(of: "streamSession.channel.authorized").intValue
var IngestEndpoint: String? = jResp.string(of: "streamSession.channel.ingestEndpoint")
var LatencyMode: String? = jResp.string(of: "streamSession.channel.latencyMode")
var Name: String? = jResp.string(of: "streamSession.channel.name")
var PlaybackUrl: String? = jResp.string(of: "streamSession.channel.playbackUrl")
var RecordingConfigurationArn: String? = jResp.string(of: "streamSession.channel.recordingConfigurationArn")
var v_String: String? = jResp.string(of: "streamSession.channel.tags.string")
var v_Type: String? = jResp.string(of: "streamSession.channel.type")
var EndTime: Int = jResp.int(of: "streamSession.endTime").intValue
var Channels: Int = jResp.int(of: "streamSession.ingestConfiguration.audio.channels").intValue
var Codec: String? = jResp.string(of: "streamSession.ingestConfiguration.audio.codec")
var SampleRate: Int = jResp.int(of: "streamSession.ingestConfiguration.audio.sampleRate").intValue
var TargetBitrate: Int = jResp.int(of: "streamSession.ingestConfiguration.audio.targetBitrate").intValue
var AvcLevel: String? = jResp.string(of: "streamSession.ingestConfiguration.video.avcLevel")
var AvcProfile: String? = jResp.string(of: "streamSession.ingestConfiguration.video.avcProfile")
var VideoCodec: String? = jResp.string(of: "streamSession.ingestConfiguration.video.codec")
var Encoder: String? = jResp.string(of: "streamSession.ingestConfiguration.video.encoder")
var VideoTargetBitrate: Int = jResp.int(of: "streamSession.ingestConfiguration.video.targetBitrate").intValue
var TargetFramerate: Int = jResp.int(of: "streamSession.ingestConfiguration.video.targetFramerate").intValue
var VideoHeight: Int = jResp.int(of: "streamSession.ingestConfiguration.video.videoHeight").intValue
var VideoWidth: Int = jResp.int(of: "streamSession.ingestConfiguration.video.videoWidth").intValue
RecordingConfigurationArn = jResp.string(of: "streamSession.recordingConfiguration.arn")
var BucketName: String? = jResp.string(of: "streamSession.recordingConfiguration.destinationConfiguration.s3.bucketName")
var RecordingConfigurationName: String? = jResp.string(of: "streamSession.recordingConfiguration.name")
var State: String? = jResp.string(of: "streamSession.recordingConfiguration.state")
var TagsString: String? = jResp.string(of: "streamSession.recordingConfiguration.tags.string")
var RecordingMode: String? = jResp.string(of: "streamSession.recordingConfiguration.thumbnailConfiguration.recordingMode")
var TargetIntervalSeconds: Int = jResp.int(of: "streamSession.recordingConfiguration.thumbnailConfiguration.targetIntervalSeconds").intValue
var StartTime: Int = jResp.int(of: "streamSession.startTime").intValue
var StreamId: String? = jResp.string(of: "streamSession.streamId")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "streamSession.truncatedEvents").intValue
while i < count_i {
jResp.i = i
eventTime = jResp.int(of: "streamSession.truncatedEvents[i].eventTime").intValue
name = jResp.string(of: "streamSession.truncatedEvents[i].name")
v_type = jResp.string(of: "streamSession.truncatedEvents[i].type")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "streamSession": {
// "channel": {
// "arn": "string",
// "authorized": boolean,
// "ingestEndpoint": "string",
// "latencyMode": "string",
// "name": "string",
// "playbackUrl": "string",
// "recordingConfigurationArn": "string",
// "tags": {
// "string": "string"
// },
// "type": "string"
// },
// "endTime": number,
// "ingestConfiguration": {
// "audio": {
// "channels": number,
// "codec": "string",
// "sampleRate": number,
// "targetBitrate": number
// },
// "video": {
// "avcLevel": "string",
// "avcProfile": "string",
// "codec": "string",
// "encoder": "string",
// "targetBitrate": number,
// "targetFramerate": number,
// "videoHeight": number,
// "videoWidth": number
// }
// },
// "recordingConfiguration": {
// "arn": "string",
// "destinationConfiguration": {
// "s3": {
// "bucketName": "string"
// }
// },
// "name": "string",
// "state": "string",
// "tags": {
// "string": "string"
// },
// "thumbnailConfiguration": {
// "recordingMode": "string",
// "targetIntervalSeconds": number
// }
// },
// "startTime": number,
// "streamId": "string",
// "truncatedEvents": [
// {
// "eventTime": number,
// "name": "string",
// "type": "string"
// }
// ]
// }
// }
}