@lavapi/ngsip.js
v0.7.0
Published
Next Generation SIP/WebRTC library with full NG911 compliance
Downloads
38
Maintainers
Readme
NGSIP.js
A lightweight SIP/WebRTC client library for browsers. Connects over WebSocket (RFC 7118), handles SIP registration and INVITE dialogs, and delegates media to the browser's native RTCPeerConnection.
Features
- SIP REGISTER with digest authentication (RFC 2617)
- Outbound and inbound audio calls via INVITE/ACK/BYE
- WebSocket transport with keep-alive and auto-reconnect
- Multi-server connection pool — redundancy (all active) or single (failover) modes
- TypeScript-first, zero runtime dependencies
Quick Start
Install
npm install ngsip.jsOr load the UMD bundle directly:
<script src="dist/ngsip.umd.js"></script>Connect and Register
import { UA } from 'ngsip.js';
const ua = new UA({
uri: 'sip:[email protected]',
password: 'secret',
wsServers: [
{ uri: 'wss://sip.example.com:8443', priority: 1 },
{ uri: 'wss://sip-backup.example.com:8443', priority: 2 },
],
connectionMode: 'redundancy',
});
ua.on('registered', server => console.log('Registered via', server.uri));
ua.on('primaryChanged', server => console.log('Primary is now', server?.uri));
ua.start();Make a Call
const session = ua.call('sip:[email protected]');
session.on('confirmed', () => {
// Attach remote audio
const audio = document.createElement('audio');
audio.autoplay = true;
audio.srcObject = session.remoteAudioStream;
document.body.appendChild(audio);
});
session.on('terminated', cause => console.log('Call ended:', cause));Answer an Incoming Call
ua.on('newRTCSession', (session, request) => {
console.log('Incoming call from', request.headers.from.uri.user);
session.ring(); // sends 180 Ringing
// Accept:
session.answer();
// Or reject:
// session.terminate();
});Hang Up
session.terminate();Disconnect
ua.stop();Configuration
See docs/api.md for full UAConfig reference.
Multi-Server / Redundancy
const ua = new UA({
uri: 'sip:[email protected]',
password: 'secret',
wsServers: [
{ uri: 'wss://server1.example.com:8443', priority: 1 },
{ uri: 'wss://server2.example.com:8443', priority: 2 },
{ uri: 'wss://server3.example.com:8443', priority: 3 },
],
connectionMode: 'redundancy', // all servers connected simultaneously
});In redundancy mode all servers are connected and registered at the same time. The lowest-priority-number server with a live registration is used as the primary for outbound calls. If it drops, the next registered server takes over instantly.
In single mode only the highest-priority server is active. When it drops, a 5-second failover timer fires before the next server is activated.
RFC Coverage
API Reference
See docs/api.md.
