JsSIP.Socket interface

The Socket interface presented in this section abstracts JsSIP from the mechanism used to send and receive SIP traffic. JsSIP internal transport deals now with this interface and hence, it is not attached to the built-in WebSocket as a transport socket.

Implementations must follow the interface specificied here in order to get JsSIP working with the underlaying transport mechanism.

JsSIP exposes a built-in JsSIP.WebSocketInterface class implementing this interface for browser environments. An implementation for Node.js is also available via: jssip-node-websocket.

Instance Attributes

via_transport

String indicating the Via transport used in the Via Header field for outgoing Requests.

url

String identifying the socket URL. It is used for debugging purposes.

sip_uri

String indicating the connection endpoint SIP URI. Used in SIP Route header field.

Instance Methods

connect()

Called by JsSIP when the socket availability for sending and receiving data is required.
The event handler onconnect must be called as soon as the socket is ready or ondisconnect if the socket fails to connect or is not usable.

disconnect()

Called by JsSIP when the socket is no longer needed for now.
Event handlers called after this call will be ignored.

send(data)

Called by JsSIP when the given data needs to be sent.

Returns true if the data was successfully sent. false otherwise.

Parameters

data
String representation of the data to be sent.

Event Handlers

onconnect()

Must be called when the socket becomes usable for sending and receiving data after connect was called or an unsolicited disconnection occured.

ondisconnect(error, code, reason)

Must be called when the socket becomes unusable for sending or receiving data.

Parameters

error
Boolean indicating whether the socket disconnected due to an error
code
Optional Number indicating the socket disconnection code.
reason
Optional String indicating the socket disconnection reason.

ondata(data)

Must be called when there is a full SIP message to be processed by JsSIP.

Parameters

data
String or Binary representation of the data.