The pandemic has forced the big players in cloud computing to offer communication services, of which arguably the biggest is Amazon with their Amazon Web Services platform. Now AWS is offering SDK’s and API’s for their pre-existing Amazon Chime video conferencing application. This will allow customers to easily build their own real-time communication apps with Amazon’s infrastructure as the backbone.
In this post, we will go through setting up a simple videoconferencing app with the Amazon Chime SDK and explore some of the core functionality. Let’s get into it!
First and foremost, we need to clone the Chime’s SDK github repository as it contains a couple of demo applications for us to work with. The SDK can also be added as a dependency to your own project. But for now, we’ll just work with demo code.
Perfect! Now change directory into the demos/browser
folder:
Please make sure you satisfy the following prerequisites to build, test, and run these demos from source:
If you don’t already have Node and NPM installed, use this link: https://nodejs.org/en/download/.
Now, we have to initialize our AWS credentials. Make sure you set these environment variables with your credentials:
You can also initialize your credentials using the aws command line interface using the configure
command. This will store all your credentials in the root ~/.aws directory from which the Chime SDK will authenticate the user.
Now run:
This will build and run your project at http://localhost:8080. If all goes well then you should see this screen.
We will now discuss the core functionality of the sample application provided by the Chime SDK.
First, we need to initialize the SDK. If you get errors here, please check your AWS credentials and roles.
Any WebRTC-based application starts with token generation. So let’s start with that:
As you can see here, we save the response from chime.createMeeting
in a table so we can later look up the meeting title to know whether the meeting exists or not. We will later send this token to the client securely.
Now what if the meeting already exists? We then have to send a token from a different API. Specifically from this one:
Simple right? Let’s see what we can do with this token on the client side.
In this block of code, the response from await this.joinMeeting()
is the object we generated on the server.
We will now use this configuration object to initialize our meetingSession
. This will be responsible for controlling most of the call actions, like so:
Keep an eye out for the meetingSession
and audioVideo
objects. They will be used repeatedly to set up the call.
To join, we first have to configure an Audio and Video device with Chime. This is synonymous to the process of publishing in most WebRTC applications. We create a dropdown of available devices so that the user can choose which devices they want to publish with. Let’s look at how we populate and set audio devices:
Ignoring the UI code, it’s important to realize the two main calls in actions here. The first is that we populate our Audio devices using the this.audioVideo.listAudioInputDevices()
function. And then, when the user selects a device from the drop down we select it in our publisher using the this.audioVideo.chooseAudioInputDevice()
function.
Once the user has initialized their devices we are ready to start the call with one simple line of code.
As of now, we’ve connected to the session and published our stream. Now there’s one last thing left to do: Subscribe to other streams. This is done in this particular example in the setupSubscribeToAttendeeIdPresenceHandler()
function.
This is a rather lengthy function that handles UI operations such as binding a volume indicator to show the participant’s mic activity and speaker detection. But what’s important is to look at the this.audioVideo.realtimeSubscribeToVolumeIndicator()
function. Despite its confusing name that implies that it has something to do with the subscribers volume, this is the function responsible for connecting the remote participant’s stream to your session.
We’ve made some great progress! Our client is now successfully connected to the call. But you may ask, what about the stream UI? How does this connect to stuff you can actually see on the screen?
This is an area that Amazon Chime offers a lot of flexibility. Maybe even too much flexibility one would argue. Let’s keep it simple. In your App you need to make sure your react class implements AudioVideoObserver
:
If this class of yours also has code to change devices, you’ll have to implement the DeviceChangeObserver
code as well. Now you’ll have to implement one of AudioVideoObserver’s call back called videoTileDidUpdate(tileState: VideoTileState)
.
This gets called whenever a new participant joins or when the user’s stream’s state changes. You will use this to bind this to an html element in your UI using this function call:
Here, the videoElement
is the existing element in your HTML DOM where you would like to display the user’s stream and tileId
is contained in the tileState object you received in the videoTileDidUpdate
call back.
And there you have it. You’re an Amazon Chime Pro!
Ready to build audio calling, video calling, or screen sharing capabilities into your business or application? Contact the experts at WebRTC.ventures today!