Skip to content

InfobipRTC

Ajša Terko edited this page Feb 20, 2023 · 2 revisions

enablePushNotification(_ token, pushCredentials, debug)

Description

Enable push notifications on a physical device for receiving incoming call events.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • pushCredentials: PKPushCredentials - PushKit Push credentials received upon successful PushKit Push Registry init.
  • debug: Bool - Optional flag used to distinguish Push Notifications environments(sandbox, production). false by default.

Returns

  • none

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    if type == .voIP {
        do {
            let token = obtainToken()
            #if DEBUG
                try InfobipRTC.enablePushNotification(token, pushCredentials: pushCredentials, debug: true)
            #else
                try InfobipRTC.enablePushNotification(token, pushCredentials: pushCredentials)
            #endif
        } catch {
            os_log("Failed to enable push notifications: %@", error.localizedDescription)
        }
    }
}

enablePushNotification(_ token, pushCredentials, debug, _ completionHandler)

Description

Enable push notifications on a physical device for incoming call events. Completion handler passed as the last parameter is used to observe whether the registration for push notifications was successful or not.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • pushCredentials: PKPushCredentials - PushKit Push credentials received upon successful PushKit Push Registry init.
  • debug: Bool -Optional flag used to distinguish Push Notifications environments(sandbox, production). false by default.
  • completionHandler: (EnablePushNotificationResult) -> Void - Completion handler receiving EnablePushNotificationResult.

Returns

  • none

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    if type == .voIP {
        let token = obtainToken()
        let debug = isDebug()
        InfobipRTC.enablePushNotification(token, pushCredentials: pushCredentials, debug: debug) { result in
            if result.status == .SUCCESS {
                os_log("Successfully registered for push notifications.")
            } else {
                os_log("Failed to register for push notifications: %@", result.message)
            }
        }
    }
}

enablePushNotification(_ token, deviceToken, debug)

Description

Enable push notifications on a physical device for receiving incoming call events.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • deviceToken: String - Device token obtained from PushKit Push credentials you received upon successful PushKit Push Registry init.
  • debug: Bool - Optional flag used to distinguish Push Notifications environments(sandbox, production). false by default.

Returns

  • none

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    if type == .voIP {
        do {
            let token = obtainToken()
            let deviceToken = pushCredentials.token.reduce("", {$0 - String(format: "%02X", $1)})
            #if DEBUG
                try InfobipRTC.enablePushNotification(token, deviceToken: deviceToken, debug: true)
            #else
                try InfobipRTC.enablePushNotification(token, deviceToken: deviceToken)
            #endif
        } catch {
            os_log("Failed to enable push notifications: %@", error.localizedDescription)
        }
    }
}

disablePushNotification(_ token)

Description

Disable push notifications for the device. After this, the device will no longer be able to receive push notifications.

Arguments

Returns

  • none

Example

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
    if type == .voIP {
        do {
            let token = obtainToken()
            try InfobipRTC.disablePushNotification(token)
        } catch {
            os_log("Failed to disable push notifications.")
        }
    }    
}

call(_ callRequest, _ callOptions)

Description

Makes an outgoing call to another user of Infobip's WebRTC platform.

Arguments

  • callRequest: CallRequest - Object containing all information needed to make an outgoing call.
  • callOptions: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating audio call
let token = obtainToken()
let callRequest = CallRequest(token, destination: "Alice", callDelegate: self)
let callOptions = CallOptions(video: false)
let call = InfobipRTC.call(callRequest, callOptions)
  • Example of initiating video call with recording turned on
let token = obtainToken()
let callRequest = CallRequest(token, destination: "Alice", callDelegate: self)
let recordingOptions = RecordingOptions(true, true)
let callOptions = CallOptions(video: true, recordingOptions: recordingOptions)
let call = InfobipRTC.call(callRequest, callOptions)

callPhoneNumber(_ callRequest, _ callPhoneNumberOptions)

Description

Makes an outgoing call to a given phone number (physical device, connected to Public Switched Telephone Network, mobile or landline).

Arguments

  • callRequest: CallRequest - Object containing all information needed to make an outgoing call.
  • callPhoneNumberOptions: CallPhoneNumberOptions - Optional additional options used to configure an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating call to a phone number
let token = obtainToken()
let callRequest = CallRequest(token, "41793026727", callDelegate: self)
let callPhoneNumberOptions = CallPhoneNumberOptions(from: "33755531044")
let call = InfobipRTC.callPhoneNumber(callRequest, callPhoneNumberOptions)
  • Example of initiating call to a phone number with recording turned on
let token = obtainToken()
let callRequest = CallRequest(token, "41793026727", callDelegate: self)
let recordingOptions = RecordingOptions(true)
let callPhoneNumberOptions = CallPhoneNumberOptions(from: "33755531044", recordingOptions: recordingOptions)
let call = InfobipRTC.call(callRequest, callPhoneNumberOptions)

callConversations(_ callConversationsRequest, _ callOptions)

Description

Makes an outgoing call to Infobip Conversations platform.

Arguments

  • callConversationsRequest: CallConversationsRequest - Object containing all information needed to make an outgoing call.
  • callOptions: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating a call to Conversations
let token = obtainToken()
let callConversationsRequest = CallConversationsRequest(token, self)
let call = infobipRTC.callConversations(callConversationsRequest)
  • Example of initiating a call to Conversations with recording turned on
let token = obtainToken()
let callConversationsRequest = CallConversationsRequest(token, self)
let recordingOptions = RecordingOptions(true, true)
let callOptions = CallOptions(video: true, recordingOptions: recordingOptions)
let call = InfobipRTC.call(callConversationsRequest, callOptions)

getActiveCall()

Description

Get currently active call if exists.

Arguments

  • none

Returns

  • Call? - Instance of the currently active call. nil if there is no active call.

Example

if let activeCall = InfobipRTC.getActiveCall() {
    activeCall.mute(true)
}

getActiveConference()

Description

Get currently active conference if exists.

Arguments

  • none

Returns

  • Conference? - Instance of the currently active conference. nil if there is no active conference.

Example

if let activeConference = InfobipRTC.getActiveConference() {
    getActiveConference.mute(true)
}

isIncomingCall(_ payload)

Description

Check if received VoIP push notification is incoming call.

Arguments

Returns

  • Bool - true if VoIP push notification contains incoming call data, otherwise false.

Example

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    if InfobipRTC.isIncomingCall(payload) {
        InfobipRTC.handleIncomingCall(payload)
    }
}

isIncomingCall(payload)

Description

Check if received VoIP push notification is incoming call.

Arguments

  • payload: [AnyHashable: Any] - PushKit Push Notification Payload represented as dictionary.

Returns

  • Bool - true if VoIP push notification contains incoming call data, otherwise false.

Example

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    let dictionaryPayload = payload.dictionaryPayload
    if InfobipRTC.isIncomingCall(payload: dictionaryPayload) {
        InfobipRTC.handleIncomingCall(payload: dictionaryPayload)
    }
}

handleIncomingCall(_ payload)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive Incoming Call.

Arguments

Returns

Example

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    if type == .voIP {
        os_log("Received VoIP Push Notification %@", payload.dictionaryPayload)
        if let incomingCall = InfobipRTC.handleIncomingCall(payload) {
            ...
        }
    }
}

handleIncomingCall(payload)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive Incoming Call.

Arguments

  • payload: [AnyHashable: Any] - PushKit Push Notification Payload represented as dictionary.

Returns

Example

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    if type == .voIP {
        let dictionaryPayload = payload.dictionaryPayload
        os_log("Received VoIP Push Notification %@", dictionaryPayload)
        if let incomingCall = InfobipRTC.handleIncomingCall(payload: dictionaryPayload) {
            ...
        }
    }
}

joinConference(_ conferenceRequest)

Description

Joins a conference call on Infobip's WebRTC platform.

Arguments

  • conferenceRequest: ConferenceRequest - Object containing all information needed to join a conference.

Returns

Throws

  • ConferenceError - Error explaining why joining the conference call failed.

Example

let token = obtainToken()
let conferenceRequest = ConferenceRequest(token, "conference-demo", self)
let conference = InfobipRTC.joinConference(conferenceRequest)
Clone this wiki locally