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.
String
representing a destination username or a complete SIP URI. body
- Message content.
String
representing the body of the message. options
- Optional
Object
with extra parameters (see below).
Fields in options
Object
contentType
- Optional
String
representing the content-type of the body. Defaulttext/plain
. eventHandlers
- Optional
Object
of event handlers to be registered to each message event. Define an event handler for each event you want to be notified about. extraHeaders
Array
ofStrings
with 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
Object
with extra parameters (see below).
Fields in options
Object
extraHeaders
Array
ofStrings
with 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
Object
with extra parameters (see below).
Fields in options
Object
extraHeaders
Array
ofStrings
with extra SIP headers for the MESSAGE request.status_code
Number
between 300 and 699 representing the SIP response code.reason_phrase
String
representing 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. response
JsSIP.IncomingResponse
instance 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. response
JsSIP.IncomingResponse
instance generating the failure for originator value ofremote
, null otherwise.cause
- One value of Failure and End Causes.