Skip to content

CloudCommunik/wphone

Repository files navigation

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.

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",
 secret: "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

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"
});

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

Param Type Default Description
register boolean false If 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

Param Type Description
tones string Tones to send

wPhone.sendMessage(request)

Sends a SIP message to another SIP endpoint.

Kind: instance method of WPhone

Param Type Description
request MessageRequest Request to send SIP message

wPhone.on(eventName, callback)

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

About

WebRTC phone based on SIP.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages