Skip to content

Latest commit

 

History

History
215 lines (154 loc) · 8.96 KB

TelnyxDevice.md

File metadata and controls

215 lines (154 loc) · 8.96 KB

TelnyxDevice

Represents the software phone running in a web browser or other context.

Kind: global class

new TelnyxDevice(config)

Create a new TelnyxDevice.

Param Type Description
config Object Configuration Object
config.host String The host name or IP address of the SIP server
config.port String The port of the SIP server
config.wsServers String URI(s) of the WebSocket Servers. Format wss://123.0.0.0:5066. An array of strings is also accepted.
config.username String The username for the SIP server
config.password String The passweord for the SIP server
config.displayName String The human readable name passed in the from field. Will be used for Caller ID
config.stunServers String URI(s) for how to connect to the STUN servers. Format stun:stun.telnyx.com:8000. An array of strings is also accepted.
config.turnServers Object Details for how to connect to the TURN servers. An array of objects is also accepted.
config.turnServers.urls String URI(s) for the TURN server(s). Format turn:turn.telnyx.com:8000?transport=tcp. An array of strings is also accepted.
config.turnServers.username String Username to authenticate on TURN server(s)
config.turnServers.password String Password to authenticate on TURN server(s)
config.registrarServer String URI for the registrar Server. Format sip:123.0.0.0:5066
config.traceSip Boolean If true, SIP traces will be logged to the dev console.
config.logLevel String One of "debug", "log", "warn", "error", "off". default is "log"

telnyxDevice.startWS()

Start the connection to the WebSocket server, and restore the previous state if stopped. You need to start the WebSocket connection before you can send or recieve calls. If you try to initiateCall without first starting the connection, it will be started for you, but it will not be stopped when the call is terminated.

Kind: instance method of TelnyxDevice

telnyxDevice.stopWS()

Stop the connection to the WebSocket server, saving the state so it can be restored later (by start).

Kind: instance method of TelnyxDevice

telnyxDevice.isWSConnected() ⇒ Boolean

Status of the WebSocket connection

Kind: instance method of TelnyxDevice
Returns: Boolean - isConnected true if the device is connected to the WebSocket server, false otherwise

telnyxDevice.register(options)

Register the device with the SIP server so that it can receive incoming calls.

Kind: instance method of TelnyxDevice
Emits: registered

Param Type Description
options Object
options.extraHeaders Array.<String> SIP headers that will be added to each REGISTER request. Each header is string in the format "X-Header-Name: Header-value".

telnyxDevice.unregister(options)

Unregister the device from the SIP server; it will no longer recieve incoming calls.

Kind: instance method of TelnyxDevice
Emits: unregistered

Param Type Description
options Object
options.all Boolean [Optional] - if set & true it will unregister all bindings for the SIP user.
options.extraHeaders Array.<String> SIP headers that will be added to each REGISTER request. Each header is string in the format "X-Header-Name: Header-value".

telnyxDevice.isRegistered() ⇒ Boolean

Status of SIP registration

Kind: instance method of TelnyxDevice
Returns: Boolean - isRegistered true if the device is registered with the SIP Server, false otherwise

telnyxDevice.initiateCall(phoneNumber) ⇒ TelnyxCall

Make a phone call

Kind: instance method of TelnyxDevice
Returns: TelnyxCall - activeCall Keep an eye on the call's state by listening to events emitted by activeCall

Param Type Description
phoneNumber String The desination phone number to connect to. Just digits, no punctuation. Example "12065551111".

telnyxDevice.activeCall() ⇒ TelnyxCall

Get a reference to the call currently in progress

Kind: instance method of TelnyxDevice
Returns: TelnyxCall - activeCall Keep an eye on the call's state by listening to events emitted by activeCall

"wsConnecting"

wsConnecting event

Fired when the device attempts to connect to the WebSocket server. If the connection drops, the device will try to reconnect and this event will fire again.

Kind: event emitted by TelnyxDevice
Properties

Name Type Description
attempts number the number of connection attempts that have been made

"wsConnected"

wsConnected event

Fired when the WebSocket connection has been established.

Kind: event emitted by TelnyxDevice

"wsDisconnected"

wsDisconnected event

Fried when the WebSocket connection attempt fails.

Kind: event emitted by TelnyxDevice

"registered"

registered event

Fired when a the device has been successfully registered to recieve calls.

Kind: event emitted by TelnyxDevice

"unregistered"

unregistered event

Fired as the result of a call to unregister() or if a periodic re-registration fails.

Kind: event emitted by TelnyxDevice
Properties

Name Type Description
cause object null if unregister() was called, otherwise see SIPjs causes
response object The SIP message which caused the failure, if it exists.

"registrationFailed"

registrationFailed event

Fired when a registration attepmt fails.

Kind: event emitted by TelnyxDevice
Properties

Name Type Description
cause object see SIPjs causes
response object The SIP message which caused the failure, if it exists.

"invite"

incomingInvite event

Fired when the device recieves an INVITE request

Kind: event emitted by TelnyxDevice

"message"

message event

Kind: event emitted by TelnyxDevice
Properties

Name Type Description
message object Contains the SIP message sent and server context necessary to receive and send replies.