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.
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.
- 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
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.
Privacy - Microphone Usage Descriptionand
Privacy - Camera Usage Descriptionto the
Info.plistof your Xcode project.
- Request microphone and camera permissions. You can use
AVCaptureDevice.authorizationStatusby handling the response synchronously and falling back to requesting permissions. You can also use
requestAccesswith 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
DefaultMeetingSession takes in both
- Create a ConsoleLogger for logging.
- Make a POST request to
server_urlto create a meeting and an attendee. The
server_urlis 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 a
- Now create an instance of
AudioVideoFacade is used to control audio and video experience. Inside the
audioVideo is an instance variable of type
- To start audio, you can call
- Your application now should be able to exchange audio streams. The Amazon Chime SDK also provides an API called
chooseAudioDeviceto change the audio input and output devices.
listAudioDevicescan 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.
stopLocalVideoare for turning on and off the camera on the user’s device.
stopRemoteVideoare 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
switchCameraand have different logic based on the camera type returned by calling
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
ActiveSpeakerObserver. These can be implemented in your application to handle those events. Let’s look at the following samples based on different interfaces.
AudioVideoObserveris used to monitor the status of audio or video sessions. To subscribe to this observer, you call
RealtimeObserveris 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’s
AttendeeInfois supplied in an array to
onAttendeesMute. That same attendee will no longer appear in future
externalUserId. If the attendee is sharing the screen, the associated attendeeId will have a trailing
MetricsObserveris used to monitor the changes in media metrics.
DeviceChangeObserverdetects 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 corresponding
onAudioDeviceChangecallback will be invoked. The new device is then listed in
VideoTileObserverhas two callback functions,
onRemoveVideoTile. They are triggered when a video tile is added or removed by calling
ActiveSpeakerObserveridentifies which attendee in the meeting is actively speaking. In the protocol of
ActiveSpeakerObserver, you add the stubs of
observerId. This can uniquely identify this observer and
DefaultActiveSpeakerPolicyextends the protocol of
ActiveSpeakerPolicy. You can implement your own policy by extending
ActiveSpeakerPolicyand use it for
activeSpeakerSubscribein 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
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
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
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
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.
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.