A simple, intuitive, and powerful JavaScript signaling library
  • TypeScript 79.4%
  • JSON-with-Comments 18%
  • PEG.js 2.1%
  • JavaScript 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2020-07-16 10:39:10 -04:00
.github/ISSUE_TEMPLATE Add issue templates 2018-06-14 11:56:59 -04:00
.vscode Update vscode settings 2020-04-23 23:44:02 -04:00
build Fix grammar generator for node 10 compatibility 2020-05-07 16:21:41 -04:00
demo update eslint and tsloader 2020-07-09 12:17:55 -04:00
docs Update docs 2020-07-13 12:06:16 -04:00
etc Update docs 2020-07-13 12:06:16 -04:00
src Version 0.17.1 2020-07-13 12:54:47 -04:00
test Update test mock 2020-07-13 12:13:19 -04:00
.eslintignore TSLint to ESLint 2020-05-06 17:01:24 -04:00
.eslintrc.json Add eslint tree shaking plugin 2020-05-11 09:44:35 -04:00
.gitattributes Initial setup of api-extractor and api-documenter 2019-07-12 13:06:29 -04:00
.gitignore New API - Transport refactor 2019-11-24 18:59:48 -05:00
.npmignore remove dist folder from npm, as it hasn't been the default method of utilizing the library for a long time: 2020-07-06 13:33:54 -04:00
.prettierignore Move existing SDH 2020-06-10 22:10:32 -04:00
.prettierrc.json Add type module to package.json 2020-05-07 11:15:32 -04:00
.travis.yml Version 0.16 - update package.json 2020-04-29 12:59:19 -04:00
AUTHORS.md Update AUTHORS 2020-04-29 12:59:19 -04:00
karma.conf.cjs Add ChromeHeadlessFakeMediaStream for Karma 2020-06-10 22:10:32 -04:00
LICENSE.md Update LICENSE 2020-04-29 12:59:19 -04:00
package-lock.json update package-lock to satisfy dependabot PR 2020-07-16 10:39:10 -04:00
package.json update ts-loader and ts-pegjs 2020-07-16 10:31:38 -04:00
README.md update travis link to reflect new travis site post-migration 2020-05-06 15:38:22 -04:00
RELEASE.md complete removal of node: 2019-07-02 16:54:42 -04:00
SECURITY.md Create SECURITY.md 2019-07-19 09:32:21 -04:00
THANKS.md add andrew127 to THANKS.md 2018-06-07 10:49:38 -04:00
tsconfig-base.json Update tsconfig base 2020-06-10 22:54:16 -04:00

SIP.js Logo

Build Status npm version

SIP Library for JavaScript

  • Create real-time peer-to-peer audio and video sessions via WebRTC
  • Utilize SIP in your web application via SIP over WebSocket
  • Send instant messages and view presence
  • Support early media, hold and transfers
  • Send DTMF RFC 2833 or SIP INFO
  • Share your screen or desktop
  • Written in TypeScript
  • Runs in all major web browsers
  • Compatible with standards compliant servers including Asterisk and FreeSWITCH

Demo

Want see it in action? The project website, sipjs.com, has a live demo.

Looking for code to get started with? This repository includes demonstrations which run in a web browser.

Usage

To place a SIP call, either utilize the SimpleUser class...

import { Web } from "sip.js";

// Helper function to get an HTML audio element
function getAudioElement(id: string): HTMLAudioElement {
  const el = document.getElementById(id);
  if (!(el instanceof HTMLAudioElement)) {
    throw new Error(`Element "${id}" not found or not an audio element.`);
  }
  return el;
}

// Options for SimpleUser
const options: Web.SimpleUserOptions = {
  aor: "sip:alice@example.com", // caller
  media: {
    constraints: { audio: true, video: false }, // audio only call
    remote: { audio: getAudioElement("remoteAudio") } // play remote audio
  }
};

// WebSocket server to connect with
const server = "wss://sip.example.com";

// Construct a SimpleUser instance
const simpleUser = new Web.SimpleUser(server, options);

// Connect to server and place call
simpleUser.connect()
  .then(() => simpleUser.call("sip:bob@example.com"))
  .catch((error: Error) => {
    // Call failed
  });

Or, alternatively, use the full API framework...

import { Inviter, SessionState, UserAgent } from "sip.js";

// Create user agent instance (caller)
const userAgent = new UserAgent({
  uri: UserAgent.makeURI("sip:alice@example.com"),
  transportOptions: {
    server: "wss://sip.example.com"
  },
});

// Connect the user agent
userAgent.start().then(() => {

  // Set target destination (callee)
  const target = UserAgent.makeURI("sip:bob@example.com");
  if (!target) {
    throw new Error("Failed to create target URI.");
  }

  // Create a user agent client to establish a session
  const inviter = new Inviter(userAgent, target, {
    sessionDescriptionHandlerOptions: {
      constraints: { audio: true, video: false }
    }
  });

  // Handle outgoing session state changes
  inviter.stateChange.addListener((newState) => {
    switch (newState) {
      case SessionState.Establishing:
        // Session is establishing
        break;
      case SessionState.Established:
        // Session has been established
        break;
      case SessionState.Terminated:
        // Session has terminated
        break;
      default:
        break;
    }
  });

  // Send initial INVITE request
  inviter.invite()
    .then(() => {
      // INVITE sent
    })
    .catch((error: Error) => {
      // INVITE did not send
    });

});

Installation

Node module

npm install sip.js

UMD bundle

Building, Development and Testing

Clone this repository, then...

npm install
npm run build-and-test

For more info please see the Documentation.

Support

  • For migration guides and API reference please see the Documentation.
  • For bug reports and feature requests please open a GitHub Issue.
  • For questions or usage problems please use the Google Group.
  • For more information see the project website at SIPjs.com.