A link to the repo can be found here:
iOS SDKIf you prefer to jump right in
Have a look at our demo app: Telnyx Meet.An overview of the Video API
These are important concepts to understand.-
A
Roomrepresents a real time audio/video/screen share session with other people or participants. It is fundamental to building a video application. -
A
Participantrepresents a person inside aRoom. EachRoomhas oneLocal Participantand one or moreRemote Participants. -
Room Statetracks the state of the room as it changes making it extremely easy to understand what’s happened to aRoom.Room Statecould change due to aLocal Participanthas started publishing a stream or because aRemote Participantleft.
-
A
Streamrepresents the audio/video media streams that are shared byParticipantsin aRoom- A
Streamis indentified by it’sparticipantIdandstreamKey
- A
-
A
Participantcan have one or moreStream’s associated with it. -
A
Subscriptionis used to subscribe to aStreambelonging to aRemote Participant
API of a Room
This should give you high level overview of the Room API and it’s functionality.After pasting the above content, Kindly check and remove any new line added
Events that are triggered in a Room
Here’s a list of events that will fire as you make API calls.After pasting the above content, Kindly check and remove any new line added
Understanding the state of the Room
Everything in the SDK centers around theRoom object. When the state of the Room changes (e.g. a new participant joins or a remote participant starts publishing a stream) the onStateChanged event is triggered.
The event is invoked with a state parameter which contains the current of the state of the Room.
After pasting the above content, Kindly check and remove any new line added
Before getting started
Install the SDK
Currently, the Telnyx iOS Video SDK can be installed using CocoaPods. For instructions on that check out our releases repo for iOSGet an API Key
You’ll need an API key which is associated with your Mission Control Portal account under API Keys. You can learn how to do that here. An API key is your credential to access our API. It allows you to:- to authenicate to the Rest API
- to manage your access tokens
Create a Room to join (if it doesn’t exist)
In order to join a room you must create it, if it doesn’t already exist. See our Room Rest API to create one. There’s also additional resources on other endpoints available to perform basic operations on aRoom.
Generate an a client token to join a room
In order to join a room you must have a client token for thatRoom. The client token is short lived and you will be able to refresh it using the refresh token provided with it when you request a client token.
Please see the docs here to learn how to create a client token.
Code Examples
Enough already let’s get to the code. Here are some code examples to get your wet feet on how to start building something with the iOS video SDK.Participating in a Room
Connect to a room
First, you’ll need to create aRoom instance and then connect to it. Once you’re connected to a room, you can start sharing audio/video streams with other participant in the rooms.
Important Note:
This simply creates an instance of a Room in code it does not use the Rooms Rest API to create a room, mentioned above in “Create a Room to join”*
After pasting the above content, Kindly check and remove any new line added
Room only has one Local Participant but can have multiple Remote Participants.
After pasting the above content, Kindly check and remove any new line added
What is Room context?
Context is any details you want to include about theLocalParticipant of the Room.
For instance, let’s say you want to use context to identify a Participant with fields from an external system. You could pass a userId and username as context, like the code snippet above.
These details will be available to all RemoteParticipants in the Room, when they are notified about your presence in the Room.
Working with local media
Publishing audio and/or video from your camera or microphone works by usingMediaDevices. MediaDevices is a helper class that we provide for you to make it easy to grab local media from your device.
After pasting the above content, Kindly check and remove any new line added
Setting the quality of the local video
You can set the camera resolution and fps usingMediaDevices.
After pasting the above content, Kindly check and remove any new line added
Publishing a stream
Once you have tracks from say, a local media device like video from a camera and/our audio from your micrphone you can use those to create aStream and publish it in the Room.
After pasting the above content, Kindly check and remove any new line added
Unpublishing a stream
If you can longer want to continue publishing a stream you canunpublish it.
Naturally the stream you want to unpublish must be added already.
After pasting the above content, Kindly check and remove any new line added
Working with Remote Participants and Streams
A remote participant who joins or leaves the room
When a remote participant joins a a room you will be notified with theRoom.onParticipantJoined event. And similiarly with Room.onParticipantLeaving when a remote participant leaves.
You can use these events to keep track of participants in the room.
After pasting the above content, Kindly check and remove any new line added
Remote participants already in the room
When you connect to aRoom there may already be remote participants in the Room. To understand who is in the Room after you connect use the onParticipantJoined event.
After pasting the above content, Kindly check and remove any new line added
Display a remote participant’s media
In order to understand how to display a remote participants’ media let’s review on subscriptions work in the API. It might be helpful to review the Video API overview to get a better understanding of how aRoom is modeled, especially Stream and Subscription.
Major 🔑 about Subscriptions
In order to display media from a remote stream you need to subscribe to it.
It’s important to understand that your Room doesn’t automatically subscribe to a remote stream being published. It’s your choice to decide whether to subscribe to a given stream.
Subscribing to a stream
So let’s say the app your building has two users - let’s them call them Alice and Bob. First, Alice joins theRoom and starts publishing a stream with audio from her microhone and video from her camera like this:
NOTE: The app on Alice’s device runs the following code…
After pasting the above content, Kindly check and remove any new line added
After pasting the above content, Kindly check and remove any new line added
Handling remote streams that are already publishing in the Room
After you connect to a Room there may be remote participants already in theRoom who are publishing streams in the Room.
To deal with that use the onStreamPublished event:
After pasting the above content, Kindly check and remove any new line added
Disconnecting from a Room
To disconect from a room do:After pasting the above content, Kindly check and remove any new line added
Room all Remote Participant’s will be notified that you’ve left the Room because the Room.onParticipantLeft event will fire on their Room instance.