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.
Calls integration to Chat provides the following benefits:
Sendbird Calls and Sendbird Chat are provided from the same app to offer an advanced in-app chat experience for users.
Users can directly make a call to anyone in a channel without leaving the app.
Smooth transition between Calls and Chat within a chat channel will make the user experience more engaging.
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.
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.
The minimum requirements for Calls integration to Chat are:
iOS 9.0 or later
Sendbird Chat sample
Sendbird Chat SDK
Sendbird Calls SDK
To install the Calls SDK and the Chat SDK, do the following steps:
Sendbird Calls SDK and Chat SDK both use singleton interfaces. Since these two SDKs work independently, create appropriate functions that can handle them together.
Find your application ID from the Sendbird Dashboard to use in 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.
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.
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 > Notifications in your dashboard.
For Calls integration to Chat, both CallKit and PushKit are used to register push tokens.
AppDelegate.swift, save the remote device token and PushKit token from the following delegate methods:
Then, register them to Sendbird server as shown below:
Before logging out, unregister the push tokens as shown below:
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.
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:
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
UITableViewCellas the subclass.
- Go to File > New > File, then select the View template in User Interface. Create a new xib file and name it
- Design the
CallMessageTableViewCell.xibfile. Register the custom class to the
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
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
BaseMessageclass from Sendbird Chat SDK has a field called
pluginswhere you can store additional information to default values. The key-value plugins are delivered as
- When a call is made from the Calls SDK, the
pluginfield of a message associated with the call will contain the following information:
- Then, for the messages that have these fields, show the UI component created.
- In the
tableView()method of the
GroupChannelChatViewController.swiftfile from the Chat sample, add the following:
A model shown below demonstrates a way to extract specific information from the
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
The above model shows how to extract the information from the plugin to add them to the
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
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
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.
UIAlertController instance and add
videoCallAction as action items for initiating a new voice or video call. The view controller then will appear for the new call.
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.