Calls integration to Chat
You can integrate Sendbird Calls to Sendbird Chat to provide users with a seamless experience in using Calls and Chat services by allowing them to make a call within a chat channel. With the implementation of Calls integration to Chat, the call screen will appear when the call starts and when the call ends users will return to the chat view.
Note: To turn on Calls integration to Chat on the Sendbird Dashboard, go to Settings > Chat > Messages.
Benefits
Calls integration to Chat provides the following benefits:
Natively integrated service
Sendbird Calls and Sendbird Chat are provided from the same app to offer an advanced in-app chat experience for users.
Call within channel
Users can directly make a call to anyone in a channel without leaving the app.
Immersive user experience
Smooth transition between Calls and Chat within a chat channel will make the user experience more engaging.
How it works
Since Calls integration to Chat is a way to add call capabilities to Sendbird Chat, it requires an app that uses Chat. If you already have one, you are ready to move to the next step. If you don’t have an app, learn how to set up Sendbird Chat from our Send first message page.
Prerequisites
To use Calls integration to Chat, an environment setup is first needed for both Sendbird Calls and Sendbird Chat using the SDKs. To learn more about each, refer to Sendbird Calls for Quickstart and Sendbird Chat samples.
Requirements
The minimum requirements for Calls integration to Chat are:
iOS 9.0 or later
SendBirdWebRTC
Sendbird Chat sample
Sendbird Chat SDK
Sendbird Calls SDK
Install the SDKs
To install the Calls SDK and the Chat SDK, do the following steps:
Step 1 Configuration
Sendbird Calls SDK and Chat SDK both use singleton interfaces. Since these two SDKs work independently, create appropriate functions that can handle them together.
Step 2 Initialize the Calls SDK and the Chat SDK
Find your application ID from the Sendbird Dashboard to use in the Calls SDK and the Chat SDK.
Step 3 Log in to the Calls SDK and the Chat SDK
To log in to the Calls and Chat SDKs, create a function that allows you to authenticate the Calls SDK and the Chat SDK together.
As written above, the SendBirdCall.authenticate()
method and SendbirdChat.connect(userId:completionHandler:)
method are used to authenticate the current user to use Calls and Chat APIs in your app.
Step 4 Log out from the Calls SDK and the Chat SDK
To log out from the Calls SDK and the Chat SDK, create a function that handles the two SDKs together like it was to log in.
Register push tokens
Push notifications services allow users to receive notifications when the app is in the background. Before utilizing this feature, you need to register appropriate push tokens to Sendbird server. To turn on this feature, go to Settings > Chat > Push notifications in your dashboard.
For Calls integration to Chat, both CallKit and PushKit are used to register push tokens.
In AppDelegate.swift
, save the remote device token and PushKit token from the following delegate methods:
Then, register them to Sendbird server as shown below:
Unregister push tokens
Before logging out, unregister the push tokens as shown below:
Make a call
For integration between the Calls and Chat services, the Calls SDK provides a specific option when dialing. You can provide the group channel URL to a DialParams
object of Sendbird Calls as shown below:
When a group channel URL is provided to the DialParams
object, messages containing call information such as calling statuses and duration will be automatically sent to the channel when the call starts and ends.
The messages will contain call information in the plugins
field of the BaseMessage
instance which can be used to properly show information about the calls.
Create custom UI components
The sample app for Calls integration to Chat is built based on Sendbird Chat. In the Chat sample app, every chat message is associated with a specific type of instance from the UITableViewCell
class. With different types of messages such as user message, file message, and admin message, different types of instances of the UITableViewCell
class are shown to the user, offering a more intuitive user experience.
For UI components for Calls integration to Chat, create an instance of the UITableViewCell
class, like the following, that will be shown to users when they make or receive a call:
An example of UI components you can create is demonstrated in these view controller files in the sample app:
GroupChannelOutgoingCallMessageTableViewCell.swift
GroupChannelOutgoingCallMessageTableViewCell.xib
To create similar UI components for Calls integration to Chat, follow the steps below.
- In Xcode, go to File > New > File > Cocoa Touch Class.
- Create a new class and name it
CallMessageTableViewCell.swift
. SelectUITableViewCell
as the subclass. - Go to File > New > File, then select the View template in User Interface. Create a new xib file and name it
CallMessageTableViewCell.xib
. - Design the
UITableViewCell
class inCallMessageTableViewCell.xib
file. Register the custom class to theCallMessageTableViewCell
class.
Register UI components
Use the UI components created to integrate Sendbird Calls to the group channel view controller in Chat. Register the UITableViewCell
class to the UITableView
instance of the chat view controller.
Then, add the following to the viewDidLoad()
method of GroupChannelChatViewController.swift
file from the Chat sample app, which will create new table view cells with the identifier CallMessageTableViewCell
.
Show UI components
To show the registered UI components, you have to identify which messages are associated with the Calls SDK and show the messages by using the CallMessageTableViewCell
class.
- The
BaseMessage
class from Sendbird Chat SDK has a field calledplugins
where you can store additional information to default values. The key-value plugins are delivered as[String: Any]
dictionary. - When a call is made from the Calls SDK, the
plugin
field of a message associated with the call will contain the following information:vendor
: sendbird,type
: call. - Then, for the messages that have these fields, show the UI component created.
- In the
tableView()
method of theGroupChannelChatViewController.swift
file from the Chat sample, add the following:
Extract call data from plugins
A model shown below demonstrates a way to extract specific information from the plugin
about Sendbird Calls.
Use the model to retrieve information about the call as shown below:
Using the detailed information from the message plugin, fill the CallMessageTableViewCell
.
The above model shows how to extract the information from the plugin to add them to the callTableViewCell
.
Create view controller
The call view controller provides interfaces for actions such as ending a call, muting or unmuting , or offers local and remote video views on a user's screen.
To implement a voice call interface to your app, refer to VoiceCallViewController.swift
and to implement a video call interface, refer to VideoCallViewController.swift
on our Sendbird Calls for Quickstart. Once both interfaces are implemented, the two will be referred to as CallingViewController
.
Use message bubble to call
Calls integration to Chat can provide a seamless user experience by allowing users to initiate a new call directly from a channel by tapping the messages that contain call information.
First, add an UITapGestureRecognizer
instance to the CallMessageCell
instance:
If the view controller is hidden during a call, tap the message which corresponds to the call to show the view controller on the screen.
If you would like to make a call again, tap any one of the status messages and a pop-up will appear for voice or video call options.
Create an UIAlertController
instance and add audioCallAction
and videoCallAction
as action items for initiating a new voice or video call. The view controller then will appear for the new call.
Other requirements
To enhance the user experience for Calls integration to Chat, features such as receiving calls using CallKit and push notifications should be added. Refer to Calls integration to Chat for Quickstart and learn more about these essential features.