Class JsSIP.Message
SIP MESSAGE based IM.
Instance Attributes
direction
String indicating who sent the MESSAGE. Possible values are ‘incoming’ when the MESSAGE is sent by the remote peer or ‘outgoing’ when the MESSAGE is sent by the local user.
local_identity
JsSIP.NameAddrHeader instance indicating the local identity. It corresponds with the MESSAGE From header value when the direction is ‘outgoing’, and with the To header value when the direction is ‘incoming’
remote_identity
JsSIP.NameAddrHeader instance indicating the remote identity. It corresponds with the MESSAGE To header value when the direction is ‘outgoing’, and with the From header value when the direction is ‘incoming’
Instance Methods
send(target, body, options=null)
Sends the message through the WebSocket connection. This method is available for outgoing messages only.
Parameters
target- Destination of the message.
Stringrepresenting a destination username or a complete SIP URI. body- Message content.
Stringrepresenting the body of the message. options- Optional
Objectwith extra parameters (see below).
Fields in options Object
contentType- Optional
Stringrepresenting the content-type of the body. Defaulttext/plain. eventHandlers- Optional
Objectof event handlers to be registered to each message event. Define an event handler for each event you want to be notified about. extraHeadersArrayofStringswith extra SIP headers for the MESSAGE request.
Example
var text = 'Hello Bob!';
var eventHandlers = {
'succeeded': function(e){ /* Your code here */ },
'failed': function(e){ /* Your code here */ };
};
var options = {
'eventHandlers': eventHandlers
};
coolPhone.sendMessage('sip:bob@example.com', text, options);
accept(options)
Responds positively to the incoming MESSAGE. Indicates the sender that it has been delivered to the destination. This method is available for incoming messages only.
Parameters
options- Optional
Objectwith extra parameters (see below).
Fields in options Object
extraHeadersArrayofStringswith extra SIP headers for the MESSAGE request.body- String representing the SIP message body.
Note: In case this parameter is set, a corresponding ‘Content-Type’ header field must be set in ‘extraHeader’ field.
reject(options)
Responds negatively to the incoming MESSAGE. Indicates the sender that it has not been delivered to the destination. The response code and reason determinte the rejection cause. This method is available for incoming messages only.
Parameters
options- Optional
Objectwith extra parameters (see below).
Fields in options Object
extraHeadersArrayofStringswith extra SIP headers for the MESSAGE request.status_codeNumberbetween 300 and 699 representing the SIP response code.reason_phraseStringrepresenting the SIP reason phrase.body- String representing the SIP message body.
Note: In case this parameter is set, a corresponding ‘Content-Type’ header field must be set in ‘extraHeader’ field.
Events
JsSIP.Message class defines a series of events. Each of them allows callback functions registration in order to let the user execute a handler for each given stimulus.
succeeded
Fired when receiving a final positive response to MESSAGE request.
Event data fields
originator- ‘remote’
String. Remote peer responded positively to the SIP MESSAGE. responseJsSIP.IncomingResponseinstance of the received 2XX response.
failed
Fired if no final positive response for the sent MESSAGE is received.
Event data fields
originator- ‘remote’/‘system’
String. Where does the MESSAGE failure come from. responseJsSIP.IncomingResponseinstance generating the failure for originator value ofremote, null otherwise.cause- One value of Failure and End Causes.