Business Productivity
Building a Meeting Application on iOS using the Amazon Chime SDK
The Amazon Chime SDKs for iOS and Android provide application developers native choices to add audio calling, video calling, and screen share viewing capabilities to their mobile applications. Developers can use the same communication infrastructure that powers Amazon Chime, an online meetings service from AWS, to deliver engaging experiences in their applications. This post demonstrates how to use the Amazon Chime SDK for iOS to add real-time audio and video conferencing to your iOS application.
Solution Overview
The Amazon Chime SDK for iOS provides methods to access the Amazon Chime SDK media services and access local audio and video devices. It supports realtime signaling for audio quality, active speaker events, enhanced echo cancellation, hardware accelerated encoding, decoding and rendering, adaptive bandwidth. It is composed of a native media binary shared with Amazon Chime SDK for Android and a Swift wrapper for easy integration.
Using the Amazon Chime SDK, you can add a unified communication experience to your mobile application on any supported iOS devices. For example, you can add video calling to a healthcare application so patients can consult remotely with doctors on health issues. You can also add audio calling to a company website so customers can quickly connect with sales.
In this post, we first walk through configuring an iOS project. We then guide you through specific usage of the Amazon Chime SDK with sample code. Similarly, if you’re building a meeting application for Android, you can follow Building a Meeting Application on Android using the Amazon Chime SDK.
Prerequisites
- You have read Building a Meeting Application using the Amazon Chime SDK. You understand the basic architecture of Amazon Chime SDK and deployed a serverless/browser demo meeting application.
- You have a basic to intermediate understanding of iOS development and tools.
- You have installed Xcode version 11.0 or later.
Note: Deploying the serverless/browser demo and receiving traffic from the demo created in this post can incur AWS charges.
Key steps outline
Here is an outline of the key steps involved in integrating the Amazon Chime SDK into your iOS application
- Configure your application
- Create a meeting session
- Access AudioVideoFacade
- Handle real-time events
- Render a video tile
- Test
- Cleanup
- Conclusion
Configure your application
To declare the Amazon Chime SDK as a dependency, you must complete the following steps.
- Follow the steps in the Setup section in the README file to download and import the Amazon Chime SDK.
- Add
Privacy - Microphone Usage Description
andPrivacy - Camera Usage Description
to theInfo.plist
of your Xcode project. - Request microphone and camera permissions. You can use
AVAudioSession.recordPermission
andAVCaptureDevice.authorizationStatus
by handling the response synchronously and falling back to requesting permissions. You can also userequestRecordPermission
andrequestAccess
with an asynchronous completion handler.
Create a meeting session
To start a meeting, you need to create a meeting session. We provide DefaultMeetingSession
as an actual implementation of the protocol MeetingSession
. DefaultMeetingSession
takes in both MeetingSessionConfiguration
and ConsoleLogger
.
- Create a ConsoleLogger for logging.
- Make a POST request to
server_url
to create a meeting and an attendee. Theserver_url
is the URL of the serverless demo meeting application you deployed (see Prerequisites section). - Create a
MeetingSessionConfiguration
. JSON response of the POST request contains data required for constructing aCreateMeetingResponse
and aCreateAttendeeResponse
. - Now create an instance of
DefaultMeetingSession
.
Access AudioVideoFacade
AudioVideoFacade
is used to control audio and video experience. Inside the DefaultMeetingSession
object, audioVideo
is an instance variable of type AudioVideoFacade
.
- To start audio, you can call
start
onAudioVideoFacade
. - Your application now should be able to exchange audio streams. The Amazon Chime SDK also provides an API called
chooseAudioDevice
to change the audio input and output devices.listAudioDevices
can be used to list all the available audio devices. - You can turn local audio on and off by calling the mute and unmute APIs.
- There are two sets of APIs for starting and stopping video.
startLocalVideo
andstopLocalVideo
are for turning on and off the camera on the user’s device.startRemoteVideo
andstopRemoteVideo
are for receiving videos from other participants on the same meeting. - You can switch the camera for local video between front-facing and rear-facing. Call
switchCamera
and have different logic based on the camera type returned by callinggetActiveCamera
.
Handle real-time events
We want to handle various real-time events during the meeting to update the UI accordingly. Events are triggered when attendees join or leave the meeting, metrics become available, audio is muted or unmuted, audio or video device is changed, video is enabled or disabled, or active talker changes. The Amazon Chime SDK provides several observer interfaces including AudioVideoObserver
, MetricsObserver
, RealtimeObserver
, DeviceChangeObserver
, VideoTileObserver
and ActiveSpeakerObserver
. These can be implemented in your application to handle those events. Let’s look at the following samples based on different interfaces.
- AudioVideoObserver
AudioVideoObserver
is used to monitor the status of audio or video sessions. To subscribe to this observer, you calladdAudioVideoObserver
onAudioVideoFacade
: - RealtimeObserver
RealtimeObserver
is used to maintain a list of attendees and their audio volume and signal strength status. This observer only notifies the change since the last notification. For example, if one attendee becomes muted, only that attendee’sAttendeeInfo
is supplied in an array toonAttendeesMute
. That same attendee will no longer appear in futureonVolumeChange
callbacks.AttendeeInfo
contains bothattendeeId
andexternalUserId
. If the attendee is sharing the screen, the associated attendeeId will have a trailing#content
. - MetricsObserver
MetricsObserver
is used to monitor the changes in media metrics. - DeviceChangeObserver
DeviceChangeObserver
detects changes in available MediaDevices, including both audio and video devices. When a new audio device, such as a Bluetooth headset, is connected or disconnected, a correspondingonAudioDeviceChange
callback will be invoked. The new device is then listed infreshAudioDeviceList
. - VideoTileObserver
VideoTileObserver
has two callback functions,onAddVideoTile
andonRemoveVideoTile
. They are triggered when a video tile is added or removed by callingbindVideoView
andunbindVideoView
methods ofAudioVideoFacade
. - ActiveSpeakerObserver
ActiveSpeakerObserver
identifies which attendee in the meeting is actively speaking. In the protocol ofActiveSpeakerObserver
, you add the stubs ofobserverId
. This can uniquely identify this observer andactiveSpeakerDidDetect
function.DefaultActiveSpeakerPolicy
extends the protocol ofActiveSpeakerPolicy
. You can implement your own policy by extendingActiveSpeakerPolicy
and use it foractiveSpeakerSubscribe
in your application.
Render a video tile
You bind the local and remote video streams to the UI elements to visualize the video tiles. Each DefaultVideoTile
has an associated VideoTileState
, which includes the unique tileId
and attendeeId
. It also has other attributes for the video tile such as isLocalTile
to indicate whether the tile represents a local or remote video stream. You can also show whether the video stream is for content sharing with isContent
. A tile can be paused
.
DefaultVideoRenderView
is used to render the frames of videos on UIImageView
. Once you have both VideoTileState
and a DefaultVideoRenderView
, you can bind them by calling bindVideoView
.
Test
After building and running your iOS application, you can verify the end-to-end behavior. Test it by joining the same meeting from your iOS device and a browser (using the demo application you set up in the prerequisites).
Amazon Chime SDK iOS Demo Application
Cleanup
If you no longer want to keep the demo active in your AWS account and want to avoid incurring AWS charges, the demo resources can be removed. Delete the two AWS CloudFormation stacks created in the prerequisites that can be found in the AWS CloudFormation console.
Conclusion
This post has covered the basic APIs in the Amazon Chime SDK for iOS including meeting session, audio and video facade, and observers. You can download the complete demo application in our Amazon Chime SDK for iOS Github repository. The demo application uses the Amazon Chime SDK to start a meeting with real-time audio and video. You can input the meeting ID and name to join the meeting. Once in a meeting, you can share your audio and video with other participants using Android, iOS, and web clients.