node.js-sip is a comprehensive VoIP framework for Node.js. Despite its name, this library goes beyond SIP (Session Initiation Protocol) and offers a full-fledged toolkit for building robust VoIP applications. Leverage its extensive capabilities for SIP transport, registration, messaging, call handling, and more.
- SIP Transport: Built-in transport layer supporting UDP.
- Client and Server Modes: Easily switch between User Agent Client (UAC) and User Agent Server (UAS).
- Call Handling: Initiate, accept, reject, and terminate calls.
- Message Handling: Send and receive SIP messages.
- Customizable: Built with modularity and extensibility in mind.
npm install node.js-sip
Here's a quick example to demonstrate how to set up a client and make a SIP call.
const VOIP = require('node.js-sip');
const voipClient = new VOIP({
type: 'client',
transport: {
type: 'UDP',
port: 5060,
},
username: '1000',
register_password: 'yourPassword',
register_ip: '192.168.1.2',
register_port: 5060,
}, (response) => {
if (response.type === 'REGISTERED') {
console.log('Successfully registered with the SIP server.');
v.call({
to:'14444444444',
ip:'192.168.1.12',
port:'5060',
callId:'1234567890',
username:'1001',
client_callback:(m) => {
console.log(`client_callback`)
console.log(m)
}
})
}
});
//Nik Hendricks 10/13/23
const SIP = require('../SIP')
const VOIP = require('../')
const USERS = {
'1000':{
password:'rootPassword',
name:'test testerson',
ip:undefined,
port:undefined,
registered:false,
call_id:undefined,
extension: '1000'
},
'1001':{
password:'rootPassword',
name:'Bill Billerson',
ip:undefined,
port:undefined,
registered:false,
call_id:undefined,
extension: '1001'
}
}
var server = new VOIP({
type:'server',
transport:{
type: 'UDP',
port: 5060,
},
},
(d) => {
if(d.type == 'UAS_READY'){
}else if(d.message !== undefined){
let parsed_headers = SIP.Parser.ParseHeaders(d.message.headers);
if(d.type == 'REGISTER'){
server.uas_handle_registration(d.message, USERS, (response) => {
console.log('response')
console.log(response)
})
}else if(d.type == 'INVITE'){
server.uas_handle_invite(d.message, USERS, (response) => {
console.log('response')
console.log(response)
})
}
}
})
server.TrunkManager.addTrunk({
name:'trunk1',
type:'SIP',
username:'1001',
password:'rootPassword',
ip:'192.168.1.2',
port:5060,
callId:'1234567890'
})
server.Router.addRoute({
name: 'Main Trunk Route',
type: 'trunk',
match: '^[0-9]{11}$',
endpoint: 'trunk:trunk1', //will decide if i want the prefix or to use the type property
})
setTimeout(() => {
server.TrunkManager.trunks['trunk1'].register();
}, 1000)
props
: Configuration object for the VOIP instance.type
:'client'
or'server'
.transport
: Transport configuration.type
:'UDP'
(currently supported).ip
: Local IP address for the transport.port
: Port for the transport.
username
: SIP username (for client).register_password
: SIP password (for client).register_ip
: Registrar IP (for client).register_port
: Registrar port (default:5060
).
callback(response)
: Callback invoked on significant events.
Initiates a SIP call.
props
: Call properties.to
: Destination phone number.ip
: Destination IP address.port
: Destination port.callId
: Call ID.username
: SIP username.client_callback
: Callback for client events.
Accepts an incoming SIP INVITE message.
Rejects an incoming SIP INVITE message.
Terminates an ongoing call.
Sends a SIP MESSAGE to the specified extension.
extension
: The SIP extension to message.body
: The message body.
- Further orginization of the codebase is needed.
- Finish RTP implementation.
- Finish SDPParser implementation.
- When making a call from a UAS in a b2bua configuration bye messages recived from the UAS Trunk UAC are not being associated with the originating messages.
- UAS UAC Registrations does not actually check if the password is correct.
MIT License. See the LICENSE file for more details.
For detailed usage and advanced configurations, refer to the full documentation (coming soon).