The JS package for opensips
npm install opensips-js---
title: Getting started
description: The Opensips JS library and its expansive ecosystem offer developers a powerful and flexible solution for integrating Opensips protocol functionalities into a multitude of applications.
navigation:
title: Getting Started
---
shell[Terminal]
$ npm i opensips-js
`
$3
You can include the OpensipsJS library directly in your HTML file using a CDN like UNPKG or jsDelivr. This is especially useful for quick prototyping or when you don't want to set up a build environment.
Add the following script tag to your HTML file:
`html [index.html]
`
This will load the library and attach the OpensipsJS class to the global window object as OpensipsJS.
Usage
$3
Firstly lets import the library and create the OpenSIPS instance:
`javascript [file.js]
import OpenSIPSJS from 'opensips-js'
const openSIPSJS = new OpenSIPSJS({
configuration: {
session_timers: false,
uri: 'sip:extension_user@domain',
// --- Use password or authorization_jwt to authorize
password: 'password',
// or
authorization_jwt: 'token',
},
socketInterfaces: [ 'wss://domain' ],
pnExtraHeaders: {
'pn-provider': 'acme',
'pn-param': 'acme-param',
'pn-prid': 'ZH11Y4ZDJlMNzODE1NgKi0K>'
},
sipDomain: 'domain',
sipOptions: {
session_timers: false,
extraHeaders: [ 'X-Bar: bar' ],
pcConfig: {},
},
modules: [ 'audio', 'video', 'msrp' ]
})
// Then you can work with the appropriate modules
opensipsJS.audio
opensipsJS.video
opensipsJS.msrp
`
$3
After including the script via CDN, you can access the OpensipsJS class directly from the global scope.
`html [index.html]
OpensipsJS CDN Usage
`
Note: When using the library via CDN, ensure that you replace 'sip:extension_user@domain', 'password', 'token', and other placeholders with your actual configuration values.
$3
If you prefer using ES modules in the browser and your environment supports them, you can import the ES module build directly from the CDN.
`html [index.html]
OpensipsJS ES Module CDN Usage
`
Important: When using ES modules via CDN:
* Ensure your browser supports ES modules.
* The type="module" attribute is necessary in the