Skip to content

InfobipRTC

Lejla Solak edited this page Aug 5, 2024 · 9 revisions

enablePushNotification(token, pushCredentials, debug, pushConfigId)

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.
  • pushConfigId: String - Push configuration ID generated via Infobip's HTTP /webrtc/1/webrtc-push-config endpoint.

Returns

  • N/A

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    let infobipRTC = getInfobipRTCInstance()
    let token = obtainToken()
    let debug = isDebug()
    if type == .voIP {
        infobipRTC.enablePushNotification(token, pushCredentials: pushCredentials, debug: debug, pushConfigId: "454d142b-a1ad-239a-d231-227fa335aadc3")
    }
}



enablePushNotification(token, pushCredentials, debug, pushConfigId, 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.
  • pushConfigId: String - Push configuration ID generated via Infobip's HTTP /webrtc/1/webrtc-push-config endpoint.
  • completionHandler: (EnablePushNotificationResult) -> Void - Completion handler receiving EnablePushNotificationResult.

Returns

  • N/A

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    let infobipRTC = getInfobipRTCInstance()
    let token = obtainToken()
    let debug = isDebug()
    if type == .voIP {
        infobipRTC.enablePushNotification(token, pushCredentials: pushCredentials, debug: debug, pushConfigId: "454d142b-a1ad-239a-d231-227fa335aadc3") { 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, pushConfigId)

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.
  • pushConfigId: String - Push configuration ID generated via Infobip's HTTP /webrtc/1/webrtc-push-config endpoint.

Returns

  • N/A

Example

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    let infobipRTC = getInfobipRTCInstance()
    let token = obtainToken()
    let debug = isDebug()
    if type == .voIP {
        let deviceToken = pushCredentials.token.reduce("", {$0 - String(format: "%02X", $1)})
        infobipRTC.enablePushNotification(token, deviceToken: deviceToken, debug: debug, pushConfigId: "454d142b-a1ad-239a-d231-227fa335aadc3")
    }
}



disablePushNotification(token)

Description

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

Arguments

Returns

  • N/A

Example

func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
    let infobipRTC: InfobipRTC = getInfobipRTCInstance()
    if type == .voIP {
        let token = obtainToken()
        infobipRTC.disablePushNotification(token)
    }
}



callWebrtc(callWebrtcRequest)

Description

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

Arguments

  • callWebrtcRequest: CallWebrtcRequest - Object containing all information needed to make an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating audio call
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callWebrtcRequest = CallWebrtcRequest(token, destination: "Alice", webrtcCallEventListener: self)
let webrtcCall = infobipRTC.callWebrtc(callWebrtcRequest)



callWebrtc(callWebrtcRequest, webrtcCallOptions)

Description

Makes an outgoing call to another user of Infobip's WebRTC platform, using additional options.

Arguments

  • callWebrtcRequest: CallWebrtcRequest - Object containing all information needed to make an outgoing call.
  • webrtcCallOptions: WebrtcCallOptions - Additional options used to configure an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating video call
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callWebrtcRequest = CallWebrtcRequest(token, destination: "Alice", webrtcCallEventListener: self)
let webrtcCallOptions = WebrtcCallOptions(video: true)
let webrtcCall = infobipRTC.callWebrtc(callWebrtcRequest, webrtcCallOptions)



callPhone(callPhoneRequest)

Description

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

Arguments

  • callPhoneRequest: CallPhoneRequest - Object containing all information needed to make 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 infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callPhoneRequest = CallPhoneRequest(token, destination: "41793026727", phoneCallEventListener: self)
let call = infobipRTC.callPhone(callPhoneRequest)



callPhone(callPhoneRequest, callPhoneNumberOptions)

Description

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

Arguments

  • callPhoneRequest: CallPhoneRequest - Object containing all information needed to make an outgoing call.
  • phoneCallOptions: PhoneCallOptions - 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, with options
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callPhoneRequest = CallPhoneRequest(token, destination: "41793026727", phoneCallEventListener: self)
let phoneCallOptions = PhoneCallOptions(from: "33712345678")
let call = infobipRTC.callPhone(callPhoneRequest, phoneCallOptions)



callViber(callViberRequest)

Description

Makes an outgoing call to a given Viber phone number.

Arguments

  • callViberRequest: CallViberRequest - Object containing all information needed to make an outgoing call.

Returns

Throws

  • CallError - Error explaining why making the call failed.

Example

  • Example of initiating call to a Viber destination
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callViberRequest = CallViberRequest(token, destination: "41793026727", from: "41727620397", viberCallEventListener: self)
let call = infobipRTC.callViber(callViberRequest)



callViber(callViberRequest, viberCallOptions)

Description

Makes an outgoing call to a given Viber phone number, using additional options.

Arguments

  • callViberRequest: CallViberRequest - Object containing all information needed to make an outgoing call.
  • viberCallOptions: ViberCallOptions - 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 Viber destination, with options
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callViberRequest = CallViberRequest(token, destination: "41793026727", from: "41727620397", viberCallEventListener: self)
let viberCallOptions = ViberCallOptions(audio: true)
let call = infobipRTC.callViber(callViberRequest, viberCallOptions)



joinRoom(roomRequest)

Description

Joins a room on Infobip's WebRTC platform.

Arguments

  • roomRequest: RoomRequest - Object containing all information needed to join a room.

Returns

Throws

  • CallError - Error explaining why joining the room failed.

Example

let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let roomRequest = RoomRequest(token, roomName: "room-demo", roomCallEventListener: self)
let roomCall = infobipRTC.joinRoom(roomRequest)



joinRoom(roomRequest, roomCallOptions)

Description

Joins a room on Infobip's WebRTC platform, using additional options.

Arguments

  • roomRequest: RoomRequest - Object containing all information needed to join a room.
  • roomCallOptions: RoomCallOptions - Additional options used to configure a call.

Returns

Throws

  • CallError - Error explaining why joining the room failed.

Example

let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let roomRequest = RoomRequest(token, roomName: "room-demo", roomCallEventListener: self)
let roomCallOptions = RoomCallOptions(video: true)
let roomCall = infobipRTC.joinRoom(roomRequest, roomCallOptions)



callApplication(callApplicationRequest)

Description

Makes an outgoing application call through Infobip's Calls platform to your application.

Arguments

  • callApplicationRequest: CallApplicationRequest - Object containing all information needed to make an application call.

Returns

Example

  • Example of initiating an application call:
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callApplicationRequest = CallApplicationRequest(token, callsConfigurationId: "45g2gql9ay4a2blu55uk1628", applicationCallEventListener: self)
let applicationCall = infobipRTC.callApplication(callApplicationRequest)
  • Example of initiating a call towards the Infobip Conversations:
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callApplicationRequest = CallApplicationRequest(token, callsConfigurationId: InfobipCallsConfiguration.conversations.rawValue, applicationCallEventListener: self)
let applicationCall = infobipRTC.callApplication(callApplicationRequest)



callApplication(callApplicationRequest, applicationCallOptions)

Description

Makes an outgoing application call through Infobip's Calls platform to your application, using additional options.

Arguments

  • callApplicationRequest: CallApplicationRequest - Object containing all information needed to make an application call.
  • applicationCallOptions: ApplicationCallOptions - Additional options used to configure an outgoing application call.

Returns

Example

  • Example of initiating a video application call:
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callApplicationRequest = CallApplicationRequest(token, callsConfigurationId: "45g2gql9ay4a2blu55uk1628", applicationCallEventListener: self)
let applicationCallOptions = ApplicationCallOptions(video: false)
let applicationCall = infobipRTC.callApplication(callApplicationRequest, applicationCallOptions)
  • Example of initiating a call towards the Infobip Conversations:
let token = obtainToken()
let infobipRTC: InfobipRTC = getInfobipRTCInstance()

let callApplicationRequest = CallApplicationRequest(token, callsConfigurationId: InfobipCallsConfiguration.conversations.rawValue, applicationCallEventListener: self)
let applicationCall = infobipRTC.callApplication(callApplicationRequest)



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

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



getActiveRoomCall()

Description

Get currently active room call if exists.

Arguments

  • none

Returns

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

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
if let activeRoomCall = infobipRTC.getActiveRoomCall() {
    activeRoomCall.mute(true)
}



getActiveApplicationCall()

Description

Get currently active application call if exists.

Arguments

  • none

Returns

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

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
if let activeApplicationCall = infobipRTC.getActiveApplicationCall() {
    activeApplicationCall.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

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



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

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



isIncomingApplicationCall(payload)

Description

Check if received VoIP push notification is incoming application call.

Arguments

Returns

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

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    if infobipRTC.isIncomingApplicationCall(payload) {
        infobipRTC.handleIncomingApplicationCall(payload, incomingApplicationCallEventListener: self)
    }
}



isIncomingApplicationCall(payload)

Description

Check if received VoIP push notification is incoming application call.

Arguments

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

Returns

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

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
    let dictionaryPayload = payload.dictionaryPayload
    if infobipRTC.isIncomingApplicationCall(payload: dictionaryPayload) {
        infobipRTC.handleIncomingApplicationCall(payload: dictionaryPayload, incomingApplicationCallEventListener: self)
    }
}



handleIncomingCall(payload, incomingCallEventListener)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive incoming call.

Arguments

Example

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



handleIncomingCall(payload, incomingCallEventListener)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive incoming call.

Arguments

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
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 infobipRTC.isIncomingCall(payload: dictionaryPayload) {
            infobipRTC.handleIncomingnCall(payload: dictionaryPayload, incomingCallEventListener: self)
        }
    }
}



handleIncomingCall(payload, incomingCallEventListener)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive incoming application call.

Arguments

Example

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



handleIncomingCall(payload, incomingCallEventListener)

Description

Handle received VoIP Push Notification with InfobipRTC in order to receive incoming application call.

Arguments

Example

let infobipRTC: InfobipRTC = getInfobipRTCInstance()
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 infobipRTC.isIncomingApplicationCall(payload: dictionaryPayload) {
            infobipRTC.handleIncomingApplicationCall(payload: dictionaryPayload, incomingApplicationCallEventListener: self)
        }
    }
}

Tutorials

Migration guides

Reference documentation

Clone this wiki locally