Getting Started

JsSIP User Agent is the core element in JsSIP. It represents the SIP client associated to a SIP account. JsSIP User Agent is defined in JsSIP.UA class.

Multiple JsSIP User Agents can be created (this is useful for having different SIP accounts running in the same web application).

Creating a JsSIP User Agent

User Agent Configuration

JsSIP User Agent requires a configuration object for its initialization. There are some mandatory configuration parameters and many optional ones. Check the full configuration parameters list.

var socket = new JsSIP.WebSocketInterface('wss://sip.myhost.com');
var configuration = {
  sockets  : [ socket ],
  uri      : 'sip:alice@example.com',
  password : 'superpassword'
};

User Agent instance

var coolPhone = new JsSIP.UA(configuration);

User Agent events definition

Full list of User Agent events.

WebSocket connection events

coolPhone.on('connected', function(e){ /* Your code here */ });

coolPhone.on('disconnected', function(e){ /* Your code here */ });

New incoming or outgoing call event

coolPhone.on('newRTCSession', function(e){ /* Your code here */ });

New incoming or outgoing IM message event

coolPhone.on('newMessage', function(e){ /* Your code here */ });

SIP registration events

coolPhone.on('registered', function(e){ /* Your code here */ });
coolPhone.on('unregistered', function(e){ /* Your code here */ });
coolPhone.on('registrationFailed', function(e){ /* Your code here */ });

Starting the User Agent

See JsSIP.UA.start() method definition.

coolPhone.start();

Making outbound calls

See JsSIP.UA.call() method definition.

Example

// Create our JsSIP instance and run it:

var socket = new JsSIP.WebSocketInterface('wss://sip.myhost.com');
var configuration = {
  sockets  : [ socket ],
  uri      : 'sip:alice@example.com',
  password : 'superpassword'
};

var ua = new JsSIP.UA(configuration);

ua.start();

// Register callbacks to desired call events
var eventHandlers = {
  'progress': function(e) {
    console.log('call is in progress');
  },
  'failed': function(e) {
    console.log('call failed with cause: '+ e.data.cause);
  },
  'ended': function(e) {
    console.log('call ended with cause: '+ e.data.cause);
  },
  'confirmed': function(e) {
    console.log('call confirmed');
  }
};

var options = {
  'eventHandlers'    : eventHandlers,
  'mediaConstraints' : { 'audio': true, 'video': true }
};

var session = ua.call('sip:bob@example.com', options);

Instant messaging

See JsSIP.UA.sendMessage() method definition.

Example 1

var text = 'Hello Bob!';

coolPhone.sendMessage('sip:bob@example.com', text);

Example 2

var text = 'Hello Bob!';

// Register callbacks to desired message events
var eventHandlers = {
  'succeeded': function(e){ /* Your code here */ },
  'failed':    function(e){ /* Your code here */ }
};

var options = {
  'eventHandlers': eventHandlers
};

coolPhone.sendMessage('sip:bob@example.com', text, options);