JsSIP

3.13.6 · active · verified Sun Apr 19

JsSIP is a robust and lightweight JavaScript SIP library that enables real-time communication capabilities in both browser and Node.js environments. It currently maintains version 3.13.6, with a steady release cadence indicating active development and timely updates. The library facilitates SIP over WebSocket (RFC 7118, co-authored by JsSIP's creators), supporting audio/video calls via WebRTC, and instant messaging. Its key differentiators include its dual-environment compatibility, a user-friendly yet powerful API, and demonstrated interoperability with popular SIP servers like Kamailio, Asterisk, and Mobicents. JsSIP provides a flexible foundation for integrating SIP functionality directly into web applications, abstracting the complexities of WebRTC and WebSocket signaling for developers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a JsSIP User Agent, configure a WebSocket transport, register event handlers for the call lifecycle, and initiate an audio/video SIP call. It showcases the fundamental setup required for WebRTC-based communication using JsSIP in a modern JavaScript/TypeScript environment, including proper import syntax and basic error handling.

import { UA, WebSocketInterface } from 'jssip';

const socket = new WebSocketInterface('wss://sip.myhost.com');
const configuration = {
  sockets  : [ socket ],
  uri      : 'sip:alice@example.com',
  password : process.env.SIP_PASSWORD ?? 'superpassword' // Use environment variables for sensitive data.
};

const ua = new UA(configuration);

ua.start();

// Register callbacks to desired call events
const eventHandlers = {
  'progress': (e: any) => { // Type 'any' for brevity; consider defining specific event types
    console.log('Call is in progress');
  },
  'failed': (e: any) => {
    console.error('Call failed with cause: ' + e.data.cause);
  },
  'ended': (e: any) => {
    console.log('Call ended with cause: ' + e.data.cause);
  },
  'confirmed': (e: any) => {
    console.log('Call confirmed');
  }
};

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

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

// Example: Stop UA after some time (for demonstration)
setTimeout(() => {
  console.log('Stopping User Agent...');
  ua.stop();
}, 30000);

view raw JSON →