VIDEO Call
RTC 555 iOS SDK supports VIDEO calls between its users. It also supports on-call features such as mute/unmute audio/video, and flip camera.
Before initiating or accepting a VIDEO call, make sure to have logged in.
SDK initialization
Below API initializes and sets the context for the SDK. It is advisable to call this API at the launch of the application.
Rtc555Sdk.initializeLibrary()
Adding SDK configuration.
To make video related API call, SDK should have below mentioned mandatory configuration data to establish a connection with the 555 platform backend.
let config:Rtc555Config = Rtc555Sdk.sharedInstance.getConfig()
config.routingId = "a2685b26-5ef0-11ea-83a9-fa163e547f24@uc-prod.comcast.com" // Unique id for the user logged in 555 platform. (Identity manager response)
config.url = "https://evm.iris.comcast.net" // Event manager URL
config.token = "<555 JWT token>" // JWT token for accessing the 555 SDK/backend APIs. Token can be accessed from the 555 login response.
config.domain = "uciris12.comcast.net" // *Optional
config.notificationManagerUrl = "https://ntm.iris.comcast.net/" //(Optional) For mobile notifications from 555 Platform
config.isAnonymous = false // Set it to true for anonymous video call.
Rtc555Sdk.setConfig(config: config)
Create Stream
To make a video related API call, you need to create a stream that will provide you with the local stream id required for video call APIs. To create stream, pass callType & Rtc555VideoDelegate to createStream API.
Rtc555Video.createStream(callType: callType, rtcVideoDelegate: self)
Parameters | Type | Description |
---|---|---|
callType | string | "outgoing" or "incoming" |
rtcVideoDelegate | Rtc555VideoDelegate | Delegate object for getting local stream Id |
Initiating an Outgoing Video Call
To make outgoing video calls, pass destination email ID , notification payload, local stream ID, & Rtc555VideoDelegate to call API. Notification payload contains two fields called data and notification. The client can make use of data to send any custom key/value pair to the remote (callee) end as part of the push notification payload. The below code shows some examples to send caller Id (cid) & caller name (cname). The notification key contains the notification type and federation type as mentioned in the below code snippet.
call API returns enum Result. Success case of result will return call id and failure case return error code and reason for the error.
Rtc555Video.call(targetEmailID: "<Destination EmailID>", notificationPayload: buildNotificationPayload(), streamId: localStreamId, rtcVideoDelegate: self) { result in
switch(result){
case .success(let callId):
print("Video call was success and callid is = \(callId)")
case .failure(let error):
print("Video call failed with error \(error)")
}
}
//build notification payload
private func buildVideoNotificationPayload() -> [AnyHashable : Any] {
let data:[String: Any] = ["cname" : "Caller Name",
"cid" : "Caller Username",
"isVideoOnly" : true]
let notification = ["type" : "video",
"topic": "federation/video"]
let userData = ["data": data, "notification" : notification]
return userData
}
Parameters | Type | Description |
---|---|---|
targetEmailID | string | Target(callee) email ID |
notificationPayload | dictionary | notification & custom user data |
streamId | string | local stream ID received from onLocalStream delegate |
rtcVideoDelegate | Rtc555VideoDelegate | Delegate object for getting remote stream Id, call status and error callback |
Below is the Notification payload need to be build for outgoing VIDEO call:
Parameters | Type | Description |
---|---|---|
data (Optional) | dictionary | e.g.
|
notification | dictionary |
|
Note:Please make sure to add a mandatory microphone and camera permission in your info.plist file before accessing call/Accept call APIs to allow SDK to create local audio and video streams.
Accept Incoming Video Call
If the user wants to accept the incoming video call request, use accept API and pass the notification payload received from the incoming APNS push notification & Rtc555VideoDelegate. accept API returns enum result. Success case of result will return call id and failure case return error code and reason for the error.
Rtc555Video.accept(notificationData: buildNotificationData(), streamId: localStreamId, rtcVideoDelegate: self) { result in
switch(result){
case .success(let callId):
print("Join video call Success. \(callId)")
case .failure(let error):
print("Join video call Failed with error \(error)")
}
}
//Note : Here userInfo is the dictionary payload received in didReceiveIncomingPushWith callback for push notification or notificationData received from onNotification for XMPP notification.
private func buildNotificationData() -> Dictionary{
let notificationdata = ["trace_id" : (userInfo["trace_id""] as? String) ?? "",
"room_id" : (userInfo["room_id"] as? String) ?? ""y,
"rtc_server" : n(userInfo["rtc_server"] as? String) ?? "",
"to_routing_id" : (userInfo["routing_id"] as? String) ?? "",
"room_token" : (userInfo["room_token"] as? String) ?? "",
"room_token_expiry_time" : (userInfo["room_token_expiry_time"] as? Int64) ?? 0
] as [String : Any]
return notificationdata
}
Pass notification payload received at incoming notification.
Parameters | Type | Description |
---|---|---|
notificationdata | dictionary | Contains key/value pair for the data received from incoming APNs/XMPP payload |
rtcVideoDelegate | Rtc555VideoDelegate | Delegate object for getting remote stream Id, call status and error callback |
Notification data is constructed from the values received from the incoming notification payload :
Parameters | Description |
---|---|
trace_id | trace id |
room_id | Room name that needs to be joined which is received in notification payload. |
room_token | Room token which is received in notification payload. |
room_token_expiry_time | Room token expiry time retrieved from notification payload. |
to_routing_id | Caller's routing Id |
rtc_server | RTC server URL extracted from notification payload. |
End an Active Video Call
Users need to call hangup API to end the active call.
Rtc555Video.hangup(callId: callId)
Parameters | Description |
---|---|
callId | callId is a unique id for the call which was returned from call/accept API |
Clean up the session.
Call the below API in Rtc555Sdk to release all the resources used by SDK. This call also allows the client to disconnect from the 555 platform backend. The app developer should call this API if the app goes to the background or kill state to release the SDK resource. Client need to call setConfig API again before attempting to initiate/accept the call.
Rtc555Sdk.cleanup()
Callkit Support
Callkit in client requires below API calls from SDK
Initialize Audio Unit
This API call allows users to manually initialize Audio Unit while using CallKit. The user needs to call this before starting/joining the call.
Rtc555Voice.initilizeManualAudio(audioManual: Bool)
Parameters | Type | Description |
---|---|---|
audioManual | Bool | Pass Yes to initilize Audio unit Manually |
Activate/Deactive Audio Unit
This API is only effective if initilizeManualAudio is YES. This API call allows users to activate/deactivate audio while using callkit. Need to call this API in provider(:didActivate:) delegate and provider(:didDeactivate:) delegate.
Rtc555Voice.enableAudio(enableAudio: Bool)
//Usage :: Callkit delegates
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
Rtc555Voice.enableAudio(enableAudio: false)
}
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
Rtc555Voice.enableAudio(enableAudio: true)
}
Parameters | Type | Description |
---|---|---|
enableAudio | Bool | Pass Yes or No to start /stop the Audio unit |
Video On-call Features
Features offered by iOS SDK for Video call are:
Toggle Audio Mute
This API call allows the users to mute and unmute its audio in the call.
Rtc555Video.audioMuteToggle(callId: callId)
Parameters | |
---|---|
callId | callId is a unique id for this call which was returned from call/accept API |
Toggle Video Mute
This API call allows the user to mute and unmute its video in the call.
Rtc555Video.videoMuteToggle(callId: callId)
Parameters | Description |
---|---|
callId | callId is a unique id for this call which was returned from call/accept API |
Flip Camera
This API call allows users to flip between the front and rear camera of the device.
Rtc555Video.flipCamera()
Video Call Delegates
To get local stream Id, remote stream Id, and call status or error report during the call, Rtc555VideoDelegate is passed to the call/accept API call. This delegate provides the below callbacks.
onLocalStream
This callback gets invoked when we receive the local stream id which is required to make/accept the call. This local stream can be used to render local video on the device screen using RtcRenderer.
func onLocalStream(streamId mediastreamId: String) {
}
Parameters | Description |
---|---|
streamId | Local Stream Id |
onRemoteStream
This callback gets invoked when we receive the stream Id of the remote participant that can be used to render remote video on the device screen using RtcRenderer.
func onRemoteStream(streamId mediastreamId: String) {
}
Parameters | Description |
---|---|
streamId | Remote Stream Id |
onStatus
This callback gets invoked when we receive the status of the ongoing call.
func onStatus(status callStatus: CallStatus,id callId:String) {
}
Parameters | Description |
---|---|
callStatus | status of ongoing call |
callId | Call id for the ongoing call |
Call Status:
- initializing - When the call is initializing
- connecting - When the call is connecting i.e. when remote party is ringing.
- connected - When the call is connected and media(video) started transferring.
- disconnected - When the call is disconnected i.e. when remote side hang up the call.
onError
This callback gets invoked when we receive an error from an ongoing video call.
func onError(error errorInfo: Error,id callId:String) {
}
Parameters | Description |
---|---|
errorInfo | error object consists of error code and error message |
callId | callId received from backend |
onNotification
Use this delegate to receive notify
and cancel
XMPP notifications or the cancel
notification when subscribed to APNs. The client needs to be connected to 555 backend to avail of this notification callback.
@objc func onNotification(notification notificationData: [AnyHashable : Any]) {
}
Parameters | Description |
---|---|
notificationData | notification payload for incoming notification |
Video Call Renderer
The video call renderer referred to as RtcRenderer provided by the Rtc555Sdk is used to render the video on the UI using stream id from Local Stream and Remote Stream.
Initilize RtcRenderer
To initialize, you need to pass the size of the View which needs to render the video stream. After that, you need to add the videoView variable of RtcRenderer to the UIView.
//Local
var localRenderer = RtcRenderer(frameSize: self.localView.bounds)
self.localView.insertSubview(localRenderer.videoView)
//Remote
var remoteRenderer = RtcRenderer(frameSize: self.remoteView.bounds)
self.remoteView.insertSubview(remoteRenderer.videoView)
Parameters | Description |
---|---|
frameSize | size of the rendering UIView |
Add Stream
This API adds the Stream id received from Local Stream and Remote Stream to local/remote RtcRenderer.
self.localRenderer.addStream(streamId: localStreamId)
self.remoteRenderer.addStream(streamId: remoteStreamId)
Parameters | Description |
---|---|
streamId | Stream Id received from onLocalStream/onRemoteStream |