Video Call
555 JS SDK supports video call between its users. Make sure that the app is logged in and connected to RTC server before initiating a call. If RTC connection got disconnected due to inactivity, the user should again request for connection to make a successful call.
Different APIs are used to create and join a video session. It also supports features like mute and unmute of local stream. Session related API requests have their respective callbacks to notify the user about the status of the request. List of callbacks specific to video session, in addition to the generic callbacks for any session type (audio, video or chat).
Create Local Media Stream
The IrisRtcStream class manages the audio and video streams that can be created using Iris stream APIs. It will create stream with both audio and video with video quality as HD and make use of back camera.
var irisRtcStream = new IrisRtcStream();
var constraints = {
video : { mandatory: {}, optional: [] },
audio : { mandatory: {}, optional: [] }
}
var streamConfig = {
"streamType": "video",
"resolution": "hd",
"constraints": constraints
}
irisRtcStream.createStream(streamConfig);
// Stream can also be received with a callback
irisRtcStream.onLocalStream = (stream) => {
// Video stream is received
}
irisRtcStream.onStreamError = (errorCode, errorMessage) => {
// Throws error if failed to create stream
}
// API to stop media stream once call is ended.
irisRtcStream.stopMediaStream(mediaStream);
Initiate an Outgoing Call
Once the RTC connection is made, dial a valid user id to make an outgoing call. An 555 session is then created with the local stream and other necessary values using IrisRtcSession class.
createSession API is invoked to create a video session, which involves creating and starting a video session using the room id for the room which has been already allocated for the involved participants. This API takes three params, userConfig a json object with attributes explained below, IrisRtcConnection object from rtc connetion and IrisRtcStream object from local stream
var irisRtcSession = new IrisRtcSession();
var userConfig = {
type : "video",
domain : "<app domain>",
sessionType : "create",
useBridge : true,
useAnonymousLogin : false,
irisToken : "<555 JWT Token>",
routingId: "<Routing Id of the caller"
}
irisRtcSession.createSession(userConfig, irisRtcConn, irisRtcStream);
Parameters passed to createSession
API are :
Parameters | |
---|---|
userConfig | JSON object for setting session configuration parameters |
irisRtcConn | IrisRtcConnection object after rtc is connetion is successfully established |
irisRtcStream | IrisRtcStream object after local stream is successfully created |
userConfig
JSON contains below parameters :
Parameters | |
---|---|
type | Call type must be video |
irisToken | 555 JWT token |
routingId | Routing id of the caller |
useAnonymousLogin | false for non-anonymous Calls |
useBridge | true for PSTN Call |
traceId | Unique time based UUID to identify call uniquely |
sessionType | Session type 'create' |
publicId | Public id of the caller |
Accept Incoming Video Call
Notification for the incoming calls are received via callback onNotification of Connection, Use this info to join call.
A local stream should be created and passed along with other parameters received in the incoming call notification to joinSession API to join a video call session.
var irisRtcSession = new IrisRtcSession();
var userConfig = {
type : "video",
domain : "<app domain>",
sessionType : "join",
useBridge : true,
useAnonymousLogin : false,
irisToken : "<JWT Token>",
routingId : "<Routing Id>"
}
irisRtcSession.joinSession(userConfig, irisRtcConn, irisRtcStream, notificationPayload);
Parameters | |
---|---|
userConfig | JSON object for setting session configuration parameters |
irisRtcStream | IrisRtcStream object |
irisRtcConn | IrisRtcConnection object |
notificationPayload | Notification payload received by onNotification callback from irisRtcConn |
End an Active Call
On end call, all data and objects associated with that particular call must be cleared for efficiency and to avoid memory leak . While closing a video call session following things must be kept in mind.
- Close 555 Rtc session
By invoking endSession() API in IrisRtcSession, 555 session will get closed by releasing all objects associated with it. - Close stream
The close operation of stream class is synchronous and can take time while closing the stream. Closing the stream during a session can cause an error in video or audio sessions. Hence it is advisable to use stopMediaStream() API once the session is closed.
var irisRtcSession = new IrisRtcSession();
irisRtcSession.endSession(roomId);
var irisRtcStream = new IrisRtcStream();
irisRtcStream.stopMediaStream(stream);
On-call Features
Mute Local Audio
An user can mute his end to stop sharing audio from their end, but at the same time they can receive audio from other end. JS SDK provides audioMuteToggle() API in IrisRtcSession class for the same.
If an user is on mute he can unmute the call and resume conversation by calling the same API again audioMuteToggle(). RoomId Should be passed as a parameter
var irisRtcSession = new IrisRtcSession();
irisRtcSession.audioMuteToggle(roomId);
Mute Local Video
An user can mute his end to stop sharing audio from their end, but at the same time they can receive audio from other end. JS SDK provides videoMuteToggle() API in IrisRtcSession class for the same.
If an user is on mute he can unmute the call and resume conversation by calling the same API again videoMuteToggle(). RoomId Should be passed as a parameter
var irisRtcSession = new IrisRtcSession();
irisRtcSession.videoMuteToggle(roomId);
Video Call Related Callbacks
onRemoteStream
This callback gets invoked when the remote stream is added to peerconnection (the mechanism in WebRTC that provides all the communication capabilities of WebRTC).
var irisRtcSession = new IrisRtcSession();
irisRtcSession.onRemoteStream = (roomId, remoteStream) => {
// Remote stream is received from participant
};
Parameters | |
---|---|
roomId | Room id received from Iris backend |
remoteStream | Media stream of the participant |
onRemoveRemoteStream
This callback gets invoked when the remote stream is removed from the peerconnection.
var irisRtcSession = new IrisRtcSession();
irisRtcSession.onRemoteStreamRemove = (roomId, participantId) => {
// Other participant has removed his media stream from session
};
Parameters | |
---|---|
participantId | Routing id of the participant |
roomId | Room id received from Iris backend |