Reference code snippet - How to initiate or join Anonymous Video Call
Sample Anonymous Video call implementation.
//AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//SDK Initialization
Rtc555Sdk.initializeLibrary()
return true
}
}
//DashboardViewController.swift
class DashboardViewController {
//After successful login
func configureSDK {
//SDK Config should be called before accessing other SDK APIs
let config:Rtc555Config = Rtc555Sdk.sharedInstance.getConfig()
config.routingId = "a2685b26-5ef0-11ea-83a9-fa163e547f24@uciris12.comcast.net" // Random uuid @ appdomain
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 anonymous login response.
config.domain = "uciris12.comcast.net" // Unique domain name
config.notificationManagerUrl = "https://ntm.iris.comcast.net/" //(Optional) For mobile notifications from 555 Platform
config.isAnonymous = true // Set it to true for anonymous video call.
Rtc555Sdk.setConfig(config: config)
}
}
//VideoCallViewController.swift
class AnonymousVideoCallViewController {
private var localStreamId: String!
private var remoteStreamIds = [String:String]()
private var localRenderer : RtcRenderer!
private var remoteRenderer : RtcRenderer?
override func viewDidLoad() {
super.viewDidLoad()
setupRenderers()
}
private func setupRenderers(){
self.localRenderer = createRenderer(self.localView.bounds)
self.remoteRenderer = createRenderer(self.remoteView.bounds)
}
private func createRenderer(_ size: CGRect) -> RtcRenderer {
return RtcRenderer(frameSize: size)!
}
func createLocalPreview() {
//Create local preview
Rtc555Video.createStream(callType: "anonymous", rtcVideoDelegate: self) //Wait for "onLocalStream" callback
}
func initiateVideoCall {
//SDK Video Call
Rtc555Video.anonymousCall(targetRoomName: "roomName", streamId: self.localStreamId, rtcVideoDelegate: self) { result in
switch(result){
case .success(let callId):
Log.d("Call Success and callid is = \(callId)")
case .failure(let error):
print(error)
}
}
}
}
extension AnonymouysVideoCallViewController: Rtc555VideoDelegate {
func onLocalStream(streamId mediastreamId: String) {
self.localStreamId = mediastreamId
self.localRenderer.addStream(streamId: mediastreamId)
//Initiate actual video call
self.initiateVideoCall()
}
func onParticipantJoined(streamId mediastreamId: String, participantId id: String) {
remoteStreamIds[id] = mediastreamId //Maintain the array of participants
self.remoteRenderer?.addStream(streamId: mediastreamId)
}
func onParticipantLeft(participantId id: String) {
remoteStreamIds.removeValue(forKey: id)
}
func onDominantSpeakerChanged(participantId id: String) {
//Update UI using actively speaking particiapnt ID
}
}
extension AnonymouysVideoCallViewController: Rtc555VoiceDelegate {
//SDK voice callbacks
func onStatus(status callStatus: CallStatus, id callId: String) {
switch (callStatus){
case .initializing:
//Initializing
case .connecting:
//Connecting
case .connected:
//Call connected
case .reconnecting:
//Reconnecting
case .disconnected:
//Call ended
case .hold:
//Call is on hold
}
}
func onError(error errorInfo: Error, id callId: String) {
print("Error: \(String(describing: errorInfo)) for callId \(callId)")
}
}
//AnonymouysVideoCallViewController.swift
class AnonymouysVideoCallViewController {
// User tapped on mute audio button
@IBAction func buttonMuteAudio(_ sender: Any) {
//SDK mute audio only
Rtc555Video.audioMuteToggle(callId: currentCallId)
}
}
//AnonymouysVideoCallViewController.swift
class AnonymouysVideoCallViewController {
// User tapped on unmute call button
@IBAction func buttonMuteVideo(_ sender: Any) {
//SDK mute video only
Rtc555Video.videoMuteToggle(callId: currentCallId)
}
}
//AnonymouysVideoCallViewController.swift
class AnonymouysVideoCallViewController {
// User tapped flip camera button
@IBAction func buttonFlipCamera(_ sender: Any) {
//SDK flip camera
Rtc555Video.flipCamera()
}
}
//VideoCallViewController.swift
class VideoCallViewController {
// User tapped on end call button
@IBAction func buttonEndCall(_ sender: Any) {
//SDK end call
Rtc555Video.hangup(callId: currentCallId)
}
}
//AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidEnterBackground(_ application: UIApplication) {
//If no active calls
if !hasActiveCall {
//SDK cleanup
Rtc555Sdk.cleanup()
}
}
}