MESSAGEs cannot be handled as specified on docs
Hi,
When event 'message' is received, a callback is called with object 'message' as an argument: http://sipjs.com/api/0.7.0/ua/#message
This 'message' object, however, doesn't seem to be working as specified here: http://sipjs.com/api/0.7.0/context/server/
I thought OK would be only sent as an answer if I explicitly write message.accept(), but I've observed that OK is always sent, I have accepted MESSAGE or not.
Moreover, I tried a message.reply( { statusCode: 500 } ) and no responses was sent to client at all.
My code is something like this:
// ... config SIP UA
sipUA.on('message', onMessage);
function onMessage(message) {
// At this point, OK was already sent and I didn't add a message.accept() for it
var userSipUri;
var messageBody;
// Callbacks
function onSuccess() {
// message.accept(); // I thought it was necessary
Log.debug('[onMessage] MESSAGE successfully processed for user ' +
userSipUri);
}
function onError(err) {
Log.error('[onMessage] Got errors processing user ' + userSipUri +
' MESSAGE: \n\t' + err);
var options = {
statusCode: 500,
reasonPhrase: 'We got errors processing your ' + messageBody + ' request.'
};
// This message.reply() does nothing
message.reply(options);
}
// Processing MESSAGE
userSipUri = message.remoteIdentity.uri.toString();
messageBody = message.request.body;
myService(userSipUri, messageBody, onSuccess, onError);
}
I followed this: http://sipjs.com/api/0.7.0/context/server/#replyoptions
Am I missing something? Thank you for attention in advance!
It looks like in the UA we are accepting all valid SIP messages. We are most likely doing this for the convenience of the majority of our users. Changing it at this point would be breaking behavior our customers have already developed around, so I am not sure that would happen. We should update our docs to reflect this though. You could override this on your UA to do what you want it to.
sipUA.originalReceiveRequest = sipUA.receiveRequest;
sipUA.receiveRequest = function(request) {
if (request.method === SIP.C.MESSAGE) {
// Do what you want
} else {
return sipUA.originalReceiveRequest(request);
}
}
We do this mostly because accepting and declining MESSAGE methods don't mean exactly what you'd think. They primarily indicate successful delivery of the message, rather than whether the user says "Yes" or "No" to accept the message. Note that the 200 OK must be sent immediately and cannot wait for user input.
That said, there are cases where it may be desirable to reject it (like if you are using a specific content type and it fails to parse). @egreenmachine is right, though, it would unfortunately be a breaking change at this point. His patch is likely the best option.
I updated the documentation for: http://sipjs.com/api/0.7.0/ua/#message
to be explicit about this auto-accept behavior