Class JsSIP.Session
The class JsSIP.Session represents a 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
String indicating the SIP URI of the local user.
remote_identity
String indicating the SIP URI of the remote peer.
start_time
Date object indicating the time when the session started. Takes its value at the moment when started 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
connect(target, options)
Generates the INVITE request and sends it through the WebSocket connection. This method is available for outgoing sessions only.
Parameters
target- Destination of the call.
Stringrepresenting a destination username or a complete SIP URI. options- Optional
Objectwith extra parameters (see below).
Fields in options Object
mediaTypeObjectwith two valid fields (audioandvideowithBooleanvalues) indicating whether the session is intended to use audio and/or video. Default value is bothaudioandvideoset totrue.viewsObjectwith two keys (selfViewandremoteView) pointing to theHTMLVideoElement(HTML5<video>) in which local and remote video will be shown.extraHeadersArrayofStringswith extra SIP headers for the INVITE request.anonymousBooleanfield indicating whether the call should be done anonymously. Default value isfalse.
Throws
Example
var target = 'sip:bob@example.net';
var options = {
mediaType: { audio: true, video: true },
views: {
'selfView': document.getElementById('my-video'),
'remoteView': document.getElementById('peer-video')
},
extraHeaders: [ 'X-Foo: foo', 'X-Bar: bar' ]
};
var session = new JsSIP.Session(coolPhone);
session.on('connecting', function(e){ // Your code here});
session.on('progress', function(e){ // Your code here});
session.on('failed', function(e){ // Your code here});
session.on('started', function(e){ // Your code here});
session.on('ended', function(e){ // Your code here});
session.connect(target, options);
answer(localView, remoteView)
Answer the incoming session. This method is available for incoming sessions only.
Parameters
localViewHTMLVideoElement(HTML5<video>) in which local video will be shown.remoteViewHTMLVideoElement(HTML5<video>) in which remote video will be shown.
Throws
terminate()
Terminate the current session.
Throws
Events
JsSIP.Session 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 when the INVITE request is created. Before sending though the WebSocket connection and after firing UA.newSession event. This event only fires for outgoing sessions.
Event data fields
originator- ‘local’
String(local user generated the INVITE). requestJsSIP.OutgoingRequestinstance of the generated INVITE request.
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.
started
Fired when the call is answered.
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. responseJsSIP.IncomingResponseinstance generating the call failure whenoriginatorvalue is ‘remote’,nullotherwise.cause- One value of Failure and End Causes.