0.0.9 • Published 1 year ago

wphone v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

WPhone

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

new WPhone(config)

Constructs a new WPhone object.

ParamTypeDescription
configWPhoneConfigConfiguration object for WPhone
config.displayNamestringOptional friendly name to send to the receiver endpoint
config.domainstringDomain or host for the user agent account
config.usernamestringUsername for authentication
config.secretstringPassword for authentication
config.serverstringSignaling server
config.audioElementIdstringHTML element to connect the audio to
config.extraHeadersArray.<string>Optional headers
config.expiresstringExpiration 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'"]
});

wPhone.call(request)

Calls another SIP endpoint.

Kind: instance method of WPhone

ParamTypeDescription
requestCallRequestRequest for SIP invite
request.targetAORstringAddress of Record of receiving endpoint
request.extraHeadersArray.<string>Optional headers

Example

await wPhone.connect();
await wPhone.call({
  targetAOR: "sip:1002@sip.acme.com"
});

wPhone.hangup()

Closes the session.

Kind: instance method of WPhone

wPhone.connect(register)

Connects to signaling server and optionally register too.

Kind: instance method of WPhone

ParamTypeDefaultDescription
registerbooleanfalseIf set to true it will also register the endpoint

wPhone.reconnect()

Reconnects to signaling server.

Kind: instance method of WPhone

wPhone.disconnect()

Closes connection to signaling server.

Kind: instance method of WPhone

wPhone.isConnected()

Returns true if the wphone is connected to WS or WSS server.

Kind: instance method of WPhone

wPhone.sendDtmf(tones)

Sends a DTMF tones to another SIP endpoint.

Kind: instance method of WPhone

ParamTypeDescription
tonesstringTones to send

wPhone.sendMessage(request)

Sends a SIP message to another SIP endpoint.

Kind: instance method of WPhone

ParamTypeDescription
requestMessageRequestRequest to send SIP message

wPhone.on(eventName, callback)

Fires user agent's events.

Kind: instance method of WPhone

ParamTypeDescription
eventNamestringName of the event fired
callbackfunctionCallback with the event's payload Events: - invite - message - hangup - error - disconnect