Get Started
The following guide describes how to get started with WebRTC.ai and to perform stream publishing and subscription.
Last updated
Was this helpful?
The following guide describes how to get started with WebRTC.ai and to perform stream publishing and subscription.
Last updated
Was this helpful?
All the interactions with WebRTC.ai are powered by the Javascript SDK. It is the first step in enabling the video communication powered by WebRTC.ai. To begin, add the required client libraries to your app.
This would create a WebRTCai
object and associate with the global window
object.
WebRTCai.init_session
is an asynchronous method and returns a Promise. The Promise would resolve with a connector
object or reject with an error
. The SDK would maintain a robust websocket connection with WebRTC.ai. All further interactions (like publishing a new stream or subscribing to other users' stream) would make use of this connector
object. API endpoints are deployed over to optimise the routing to Media Server thus minimising packet loss, jitter and latency.
Following are the required parameters for initiating a connection with WebRTC.ai:
API_KEY
: Either a (bounded for your domain) or a (created at your backed servers)
SESSION_ID
: A unique identifier for each session (think of it as a room).
USER_ID
: A unique identifier for the user. (e.g. phone numbers)
logLevel
: use "debug" to get maximum logging in console (default : warn)
Following are the parameters supported:
args
:
username
: Human friendly name for this publisher (default : user_id
of the session)
type
: "video"/"screen" Either publish the webcam or share screen. (default : "video")
screenshareFrameRate
: How many frames to capture per second. (default : 22 )
video_device_id
: ID of video device to capture, obtain a list via WebRTCai.listDecives()
adaptive_bitrate
: Dynamically adjust media quality as per available bandwidth (default : true)
resolution
: A string representation for Webcam Stream. Possible values "sd/hd/fhd" (default : "sd")
datachannel
: Boolean for native WebRTC datachannels, default false
targetVideoEleID
: HTML video element id, it would preview the stream that client is publishing.
data
: The object received with the event.
args
:
audio
: true/false should the SDK receive the audio stream (default : true)
video
: true/false should the SDK receive the video stream (default : true)
adaptive_bitrate
: Dynamically adjust media quality as per available bandwidth (default : true)
targetVideoEleID
: HTML video element id, it would preview the stream client is publishing.
The connector
object obtained in the previous step exposes a method publish
to initiate a WebRTC connection with the cloud servers and start publishing a stream like webcam or screen sharing. The method would return a Promise that would either resolve with a publisherObj
(required to further manipulate the video feed) or reject with en .
On successful publication, the targetVideoEleID
would start playing the webcam feed with muted
attribute set to true
, to be compliant with browsers' (not letting any video play with sound enabled without a user click)
The connector
object emits certain to inform the client app about various states of the session. One of the most useful of them is WebRTCai.events.publisher
, that fires every time someone starts publishing in the session. Client apps can listen for this event and subscribe to the new publisher with method subscribe
exposed by the connector
object. Following are the parameters supported:
On successful publication, the targetVideoEleID
would start playing the webcam feed with muted
attribute set to true
, to be compliant with browsers' (not letting any video play with sound enabled without a user click)