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. String representing a destination username or a complete SIP URI.
options
Optional Object with extra parameters (see below).

Fields in options Object

mediaType
Object with two valid fields (audio and video with Boolean values) indicating whether the session is intended to use audio and/or video. Default value is both audio and video set to true.
views
Object with two keys (selfView and remoteView) pointing to the HTMLVideoElement (HTML5 <video>) in which local and remote video will be shown.
extraHeaders
Array of Strings with extra SIP headers for the INVITE request.
anonymous
Boolean field indicating whether the call should be done anonymously. Default value is false.

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

localView
HTMLVideoElement (HTML5 <video>) in which local video will be shown.
remoteView
HTMLVideoElement (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).
request
JsSIP.OutgoingRequest instance 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.
response
JsSIP.IncomingResponse instance 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.
response
JsSIP.IncomingResponse instance 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.
message
JsSIP.IncomingRequest or JsSIP.IncomingResponse instance generating the call termination when originator value is ‘remote’, null otherwise.
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.
response
JsSIP.IncomingResponse instance generating the call failure when originator value is ‘remote’, null otherwise.
cause
One value of Failure and End Causes.