Class JsSIP.RTCSession
The class JsSIP.RTCSession represents a WebRTC media (audio/video) session. It can be initiated by the local user or by a remote peer.
Instance Attributes
direction
String indicating who started the session. Possible values are ‘incoming’ when the session is started by the remote peer or ‘outgoing’ when the session is started by the local user.
local_identity
JsSIP.NameAddrHeader instance indicating the local identity. It corresponds with the INVITE From header value when the direction is ‘outgoing’, and with the To header value when the direction is ‘incoming’
remote_identity
JsSIP.NameAddrHeader instance indicating the remote identity. It corresponds with the INVITE To header value when the direction is ‘outgoing’, and with the From header value when the direction is ‘incoming’
start_time
Date object indicating the time when the session started. Takes its value at the moment when accepted event was fired.
end_time
Date object indicating the time when the session ended. Takes its value at the moment when ended event was fired.
data
Custom session empty Object for application usage. The developer can add here custom attribute/value pairs.
Instance Methods
answer(options)
Answer the incoming session. This method is available for incoming sessions only.
Parameters
options- Optional
Objectwith extra parameters (see below).
Fields in options Object
extraHeadersArrayofStringswith extra SIP headers for the MESSAGE request.mediaConstraintsObjectwith two valid fields (audioandvideo) indicating whether the session is intended to use audio and/or video and the constraints to be used. Default value is bothaudioandvideoset totrue.RTCAnswerConstraintsObjectrepresenting constraints forRTCPeerconnection createAnswer.mediaStreamMediaStreamto transmit to the other end.
Throws
terminate(options)
Terminate the current session regardless its direction or state.
Depending on the state of the session, this function may send a CANCEL request, a non-2xx final response, a BYE request, or even no request.
For incoming sessions, if the user has not answered the incoming INVITE, this function sends the non-2xx final response with the optionally specified status code and reason phrase. 480 Unavailvable is responded by default.
For outgoing sessions, if the original INVITE has not been already sent, it will never be sent. If the original INVITE has not been answered with a final response, the behavior depends on whether provisional response has been received. If provisional response has been received, a CANCEL request will be sent. If no provisional response has been received, the function will not send a CANCEL as per RFC 3261. If then a provisional response is received, the CANCEL request will be automatically sent.
For both incoming and outgoing, if the INVITE session has been answered with final response, a BYE request will be sent.
Parameters
options- Optional
Objectwith extra parameters (see below).
Fields in options Object
extraHeadersArrayofStringswith extra SIP headers for the MESSAGE request.status_codeNumberbetween 300 and 699 representing the SIP response code.reason_phraseStringrepresenting the SIP reason phrase.body- String representing the SIP message body (in case this parameter is set, a corresponding Content-Type header field must be set in
extraHeaderfield).
NOTE: When generating a CANCEL, status_code can take values from 200 to 699. The status_code and reason_phrase will form a Reason header field as specified in RFC3326. A CANCEL will not take the extraHeaders parameter nor the body paramter.
Throws
getLocalStreams()
Returns a sequence of MediaStream objects representing the streams that are currently sent in this RTCSession.
getRemoteStreams()
Returns a sequence of MediaStream objects representing the streams that are currently received in this RTCSession.
sendDTMF(tone, options=null)
Send one or multiple DTMF tones making use of SIP INFO method.
toneStringorNumbercomposed by one or multiple valid DTMF symbols.options- Optional
Objectwith extra parameters. See below.
Fields in options Object
duration- Positive decimal
Numberindicating the duration of the tone expressed in milliseconds. Default value is100. interToneGap- Positive decimal
Numberindicating the interval between two tones expressed in milliseconds. Default value is500. extraHeaders- Optional
ArrayofStringswith extra SIP headers for each INFO request. eventHandlers- Optional
Objectof event handlers to be registered to eachJsSIP.RTCSession.DTMFevent. Define an event handler for each event you want to be notified about.
Throws
Example 1
call.sendDTMF(1);
call.sendDTMF(4);
Example 2
var tones = '1234#';
var extraHeaders = [ 'X-Foo: foo', 'X-Bar: bar' ];
var options = {
'duration': 160,
'interToneGap': 1200,
'extraHeaders': extraHeaders
};
call.sendDTMF(tones, options);
hold()
Puts the call on hold by sending a Re-INVITE SIP request.
Throws
unhold()
Resumes the call from hold by sending a Re-INVITE SIP request.
Throws
isOnHold()
Returns an Object with the properties “local” and “remote” and a Boolean value asociated with each one. It represents whether the “local” and/or “remote” peer are on hold.
Example
rtcsession.isOnHold();
{
'local': true, // User has put the other peer on hold
'remote': false // Peer hasn't put user on hold
}
mute(options=null)
Mutes the local audio and/or video.
audioBooleanDetermines whether local audio must be mutedvideoBooleanDetermines whether local video must be muted
unmute(options=null)
Unmutes the local audio and/or video.
audioBooleanDetermines whether local audio must be unmutedvideoBooleanDetermines whether local video must be unmuted
isMuted()
Returns an Object with the properties “audio” and “video” and a Boolean value asociated with each one. It represents whether the local “audio” and/or “video” are on muted.
Example
rtcsession.isMuted();
{
'audio': true, // Local audio is muted
'video': false // Local audio is not muted
}
Events
JsSIP.RTCSession class defines a series of events. Each of them allow callback functions registration in order to let the user execute a function for each given stimulus.
Every event handler is executed with a JsSIP.Event instance as the only argument.
connecting
Fired after the local media stream is added into RTCSession and before the ICE gathering starts for initial INVITE request or “200 OK” response transmission.
Event data fields in incoming sessions
requestJsSIP.IncomingRequestinstance representing the incoming INVITE SIP message.
Event data fields in outgoing sessions
requestJsSIP.OutgoingRequestinstance representing the outgoing INVITE SIP message.
progress
Fired when receiving or generating a 1XX SIP class response (>100) to the INVITE request.
Event data fields in incoming sessions
originator- ‘local’
String.
Event data fields in outgoing sessions
originator- ‘remote’
String. responseJsSIP.IncomingResponseinstance of the received SIP 1XX response.
accepted
Fired when the call is accepted (2XX received/sent).
Event data fields in incoming sessions
originator- ‘local’
String.
Event data fields in outgoing sessions
originator- ‘remote’
String. responseJsSIP.IncomingResponseinstance of the received SIP 2XX response.
confirmed
Fired when the call is confirmed (ACK received/sent).
Event data fields in incoming sessions
originator- ‘local’
String.
Event data fields in outgoing sessions
originator- ‘remote’
String. responseJsSIP.IncomingResponseinstance of the received SIP 2XX response.
ended
Fired when an established call ends.
Event data fields
originator- ‘local’/‘remote’/‘system’
String. Where does the call termination come from. messageJsSIP.IncomingRequestorJsSIP.IncomingResponseinstance generating the call termination whenoriginatorvalue is ‘remote’,nullotherwise.cause- One value of Failure and End Causes.
failed
Fired when the session was unable to establish.
Event data fields
originator- ‘local’/‘remote’/‘system’
String. Where does the call failure come from. messageJsSIP.IncomingRequestorJsSIP.IncomingResponseinstance generating the call failure whenoriginatorvalue is ‘remote’,nullotherwise.cause- One value of Failure and End Causes.
newDTMF
Fired for an incoming or outgoing DTMF.
Event data fields for an incoming DTMF
originator- ‘remote’
String. The new DTMF is generated by the remote peer. dtmfJsSIP.RTCSession.DTMFinstance.requestJsSIP.IncomingRequestinstance of the received INFO request.
Event data fields for an outgoing DTMF
originator- ‘local’
String. The new DTMF is generated by the local user. dtmfJsSIP.RTCSession.DTMFinstance.requestJsSIP.OutgoingRequestinstance of the outgoing INFO request.
hold
Fired when the user or the peer puts the other side on hold.
Event data fields
originator- ‘remote’
Stringif the other peer has put the user on hold. ‘local’Stringif the user has put the other peer on hold.
unhold
Fired when the user or the peer resumes the other end from hold.
Event data fields
originator- ‘remote’
Stringif the other peer has resumed the user from hold. ‘local’Stringif the user has resumend the other peer from hold.
mute
Fired when the local media is muted.
Event data fields
audioBooleanDetermines whether the local audio is muted.videoBooleanDetermines whether the local video is muted.