WPhone is SIP user agent you can use to create web-based softphones. It uses SIP.js as the foundation but aims to be much easier for simple use-cases.
Create an HTMLAudioElement, in your HTML code, give it an id and use it to create your WPhone object. See src/examples.ts for an implementation example.
Thanks to the folks at onsip.com for such a fantastic job with SIP.js. 🔥
Kind: global class
Constructs a new WPhone object.
Param | Type | Description |
---|---|---|
config | WPhoneConfig |
Configuration object for WPhone |
config.displayName | string |
Optional friendly name to send to the receiver endpoint |
config.domain | string |
Domain or host for the user agent account |
config.username | string |
Username for authentication |
config.secret | string |
Password for authentication |
config.server | string |
Signaling server |
config.audioElementId | string |
HTML element to connect the audio to |
config.extraHeaders | Array.<string> |
Optional headers |
config.expires | string |
Expiration for register requests |
Example
const WPhone = require("wphone");
const config = {
displayName: "John Doe",
domain: "sip.acme.com",
username: "1001",
secret: "changeit",
audioElementId: "remoteAudio",
server: "ws://yoursignalingserver:5062",
extraHeaders: ["X-Extra-Header: 'extra header'"]
}
wPhone = new WPhone(config);
await wPhone.connect();
await wPhone.call({
targetAOR: "sip:1002@sip.acme.com",
extraHeaders: ["X-Extra-Header: 'more extra headers'"]
});
Calls another SIP endpoint.
Kind: instance method of WPhone
Param | Type | Description |
---|---|---|
request | CallRequest |
Request for SIP invite |
request.targetAOR | string |
Address of Record of receiving endpoint |
request.extraHeaders | Array.<string> |
Optional headers |
Example
await wPhone.connect();
await wPhone.call({
targetAOR: "sip:1002@sip.acme.com"
});
Closes the session.
Kind: instance method of WPhone
Connects to signaling server and optionally register too.
Kind: instance method of WPhone
Param | Type | Default | Description |
---|---|---|---|
register | boolean |
false |
If set to true it will also register the endpoint |
Reconnects to signaling server.
Kind: instance method of WPhone
Closes connection to signaling server.
Kind: instance method of WPhone
Returns true
if the wphone is connected to WS or WSS server.
Kind: instance method of WPhone
Sends a DTMF tones to another SIP endpoint.
Kind: instance method of WPhone
Param | Type | Description |
---|---|---|
tones | string |
Tones to send |
Sends a SIP message to another SIP endpoint.
Kind: instance method of WPhone
Param | Type | Description |
---|---|---|
request | MessageRequest |
Request to send SIP message |
Fires user agent's events.
Kind: instance method of WPhone
Param | Type | Description |
---|---|---|
eventName | string |
Name of the event fired |
callback | function |
Callback with the event's payload Events: - invite - message - hangup - error - disconnect |