Learn how to add peer-to-peer video calls to your app.
createNewSession()
method. Pass opponent ID/IDs and a call type (video or audio) to it.
The session object can be received either as a result of the createNewSession()
method or in each event listener callback. Learn more about the event listener in this section.
Argument | Required | Description |
---|---|---|
calleesIds | yes | IDs of opponents. |
sessionType | yes | Call type: AUDIO or VIDEO. |
Parameters | Required | Description |
---|---|---|
mediaParams | yes | Media stream constrains. |
function() | yes | Specifies the callback function which receives a local media stream once it is ready. |
mediaParams
object has the following fields:
Fields | Required | Description |
---|---|---|
audio | yes | Enable audio. Boolean parameter. true is enabled, false is disabled. |
video | yes | Enable video. Boolean parameter. true is enabled, false is disabled. |
options | no | Specifies two media options:- mute. Mute audio. true is muted, false is unmuted.- mirror. Enable the mirror. true is enabled, false is disabled. |
elemId | no | ID attribute of the video element to attach a local video stream to. |
getUserMedia
callback function.
For more information about possible audio/video constraints, here is a good code sample from WebRTC team on how to work with getUserMedia constraints.
call()
method.
Argument | Required | Description |
---|---|---|
extension | yes | Custom user data. Specify any key-value pairs. In each pair, the key and value are both string values. |
fuction() | yes | Specifies the callback function. The error is received in case of unsuccessful callback. |
onCallListener()
callback specifying that a new call session has been received.
accept()
method.
reject()
method.
stop()
method and pass sessionId
parameter to tell SDK which call session to end.
update()
method to send instructions to the opponents on how to update the UI.
onAcceptCallListener
callback is received when your call has been accepted by the user. This callback receives information about the call session, user ID who accepted the call, and additional key-value data about the user.
QuickBlox JavaScript SDK persistently interacts with the server via XMPP connection that works as a signaling transport for establishing a call between two or more peers. It receives the callbacks of the asynchronous events which happen with the call and peer connection. This allows you to track these events and build your own video calling features around them.
To track call session and peer connection events, you should use the event listener. The supported event callbacks for a call session and peer connection are listed in the table below.
Method | Invoked when |
---|---|
onCallListener | A new call session has been received. |
onAcceptCallListener | A call has been accepted. |
onRejectCallListener | A call has been rejected. |
onStopCallListener | An accepted call has been ended by the peer by pressing the hang-up button. |
onUserNotAnswerListener | A user did not respond to your call within the dedicated time interval. |
onSessionCloseListener | A call session has been closed. |
onCallStatsReport | An updated stats report, which is called by timeout, has been received for the user ID. |
onSessionConnectionStateChangedListener | A peer connection state has been changed. View Peer connection states section for more details. |
onUpdateCallListener | Called when updates to the active call are made. |
onInvalidEventsListener | Called when some operation cannot be performed (for example, accept() method is called on the closed call session). |
onRemoteStreamListener | A user received a stream from the opponent. |
State | Description |
---|---|
NEW | A new call session has such a state. |
ACTIVE | A call session gets this state when you initiated or accepted the incoming call. |
HUNGUP | A call session gets this state when you hang up, before closing the call session. |
REJECTED | A call session gets this state when you reject an incoming call before closing the call session. |
CLOSED | A call session is closed. |
State | Description |
---|---|
ReconnectionState.RECONNECTING | A connection with opponent in reconnection progress after ICE connection failed. |
ReconnectionState.RECONNECTED | A connection with opponent was successfully established. |
ReconnectionState.FAILED | A connection with opponent isn’t restored by disconnect time interval. |
CONFIG
object and then call the init()
method.
State | Description |
---|---|
QB.webrtc.SessionConnectionState.CONNECTING | The ICE agent has been given one or more remote candidates and is checking pairs of local and remote candidates against one another to try to find a compatible match, but has not yet found a pair which will allow the peer connection to be made. |
QB.webrtc.SessionConnectionState.CONNECTED | A usable pairing of local and remote candidates has been found for all components of the connection, and the connection has been established. |
QB.webrtc.SessionConnectionState.CLOSED | A peer connection was closed. But the call session can still be open because there can several peer connections in a single call session.The ICE agent for this RTCPeerConnection has shut down and is no longer handling requests. |
QB.webrtc.SessionConnectionState.FAILED | One or more of the ICE transports on the connection is in the failed state. This can occur in different circumstances, for example, bad network, etc. |
QB.webrtc.SessionConnectionState.COMPLETED | The ICE agent has finished gathering candidates, has checked all pairs against one another, and has found a connection for all components. |