Socket support (node.js)
How much work will it be to allow sip.js to work over Sockets instead of WebSockets?
I'm looking into it now, but can't decide whether there's work only on an alternative Transport controller, or a refactor of the whole thing.
@egreenmachine and I looked into this as well (for UDP, that is), and found that it would take a bit more than just overriding Transport (as allowed by https://github.com/onsip/SIP.js/commit/63d205ceea4976f8af91a6f50608a3e71339ea00). We made a little progress on the non-Transport changes (see https://github.com/joseph-onsip/SIP.js/tree/udp), but didn't go any further. @egreenmachine, do you have any UDP Transport code or other comments on what the difficulties were?
Well today I've started something, kind of a Socket class that abstracts away UDP/TCP/TLS/WS. It's not on git yet, as it's preliminary (basically I have yet to take care of message segmentation) but I hope it will be soon
Using TCP sockets should be pretty straightforward. Websockets and TCP sockets are essentially the same thing.
Getting full SIP.js behavior with UDP is more challenging. There are some underlying assumptions that were carried over from when we forked JsSIP. We do not track the destination IP or Port per session because of these assumptions. To correctly fix the problem is a big undertaking. If I remember correctly, each session would need to track its own transport instead of just blindly using a single transport.
Feel free to correct me on any of this. It has been a few months since we last looked at this.
I've been working on this for a few weeks now. When finished, you will be able to use WS/TCP/UDP transport and be able to specify if you want to run SIP.js in UAS mode or UA mode. Quite an overhaul but necessary for the MSRP conference bridge project I'm doing.
I've got UDP working in Transport.js today (Proof of concept) in UAS mode. I haven't done much in UA mode but I'm sure it would work fine.
Also, instead of having a configuration option named wsServers this would likely change to servers.
Servers config:
servers: "udp:sip.example.com"
servers: "udp:sip.example.com:5061"
servers: [
"udp:sip-udp.example.com",
"tcp:sip-tcp.example.com",
"ws://sip-ws.example.com"
]
servers: [
{ // First connection attempt
uri: "udp:sip-udp.example.com",
weight: 10
},
{
uri: "tcp:sip-tcp.example.com",
weight: 1
}
]
Turn on UAS mode:
// fires up server based on `servers` configuration option.
// In UAS mode, servers option is limited to a single URI String instead of object and array.
// Port is assumed 5060 unless specified with a colon.
// In UAS mode, registration is turned off.
// Its best to override the MediaHandlerFactory to handle SDP for other server side applications
uasMode: true // false by default
I think you should allow specifyinf udp4/udp6/tcp4/tcp6 for IPv4 vs IPv6. And if just udp/tcp is specified - then try to autodetect.
On Fri, May 29, 2015 at 7:13 PM, cwysong85 [email protected] wrote:
I've been working on this for a few weeks now. When finished, you will be able to use WS/TCP/UDP transport and be able to specify if you want to run SIP.js in UAS mode or UA mode. Quite an overhaul but necessary for the project I'm doing.
I've got UDP working in Transport.js today (Proof of concept) in UAS mode. I haven't done much in UA mode but I'm sure it would work fine.
Also, instead of having a configuration option named wsServers this would likely change to servers.
Servers config:
servers: "udp:sip.example.com" servers: "udp:sip.example.com:5061" servers: [ "udp:sip-udp.example.com", "tcp:sip-tcp.example.com", "ws://sip-ws.example.com" ] servers: [ { // First connection attempt uri: "udp:sip-udp.example.com", weight: 10 }, { uri: "tcp:sip-tcp.example.com", weight: 1 } ]
Turn on UAS mode:
// fires up server based on
serversconfiguration option. // In UAS mode, servers option is limited to a single URI String instead of object and array. // Port is assumed 5060 unless specified with a colon. // In UAS mode, registration is turned off. // Its best to override the MediaHandlerFactory to handle SDP for other server side applications uasMode: true // false by default— Reply to this email directly or view it on GitHub https://github.com/onsip/SIP.js/issues/169#issuecomment-106860857.
Good point.
// Assume udp4 by default
servers: "udp:sip.example.com"
servers: "udp4:sip.example.com"
servers: "udp6:sip.example.com"
// assume tcp4 by default
servers: "tcp:sip.example.com"
servers: "tcp4:sip.example.com"
servers: "tcp6:sip.example.com"
Yeah :-) Especially when the world is running out of IPv4 addresses...
Btw with IPv6 we have a problem with specifying ports using the colon syntax, we'll need to specify a comma or something
Not sure why I did all domains in my example.
IPv6 example:
servers: "udp:[1fff:0:a88:85a3::ac1f]:5060"
On Sat, May 30, 2015, 1:36 PM Daniel Cohen Gindi [email protected] wrote:
Yeah :-) Especially when the world is running out of IPv4 addresses...
Btw with IPv6 we have a problem with specifying ports using the colon syntax, we'll need to specify a comma or something
— Reply to this email directly or view it on GitHub https://github.com/onsip/SIP.js/issues/169#issuecomment-107070024.
@cwysong85 Did you get the UDP transport working?
@n-samir Yes I have UDP transport working. When npm downloads and installs SIP.js, I run a postinstall script that patches SIP.js replacing the WS transport dependencies with NodeJS UDP library.
@n-samir I plan on pulling down this library and adding in my changes.. I've just been very busy with other projects. We have also forked the Crocodile MSRP library and ported it to NodeJS. We just haven't had the time to go back thru and do a complete analysis of each library.
The UDP transport support for SIP.js will be very helpful to many and save a LOT of hours of re-inventing the wheel that you have already done. I presume that SIP.js itself does not have any browser dependencies and can be installed in NodeJS as a npm module. I know Jssip, from which sip.js is derived, can be installed on NodeJS. Thanks for the update and hope you get some time soon to make the UDP support available!
On Tue, May 3, 2016 at 4:38 AM, cwysong85 [email protected] wrote:
@n-samir https://github.com/n-samir I plan on pulling down this library and adding in my changes.. I've just been very busy with other projects. We have also forked the Crocodile MSRP library and ported it to NodeJS. We just haven't had the time to go back thru and do a complete analysis of each library.
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/onsip/SIP.js/issues/169#issuecomment-216391279
@cwysong85 Thank you for your work. Was it already possible to commit your changes? UDP support would be great for SIP.js.
@iwanbolzern Sorry for the delay. Please see https://www.npmjs.com/package/sipjs-udp. Also, I'm needing contributors! This is a very young project.
The 0.11.0 release allows users to write their own custom transport, similarly to how it is done with sessionDescriptionHandlers. The transport is provided to the UA by the configuration property transportConstructor, and additional options for it are passed in as another UA configuration property transportOptions. There's no formal guide yet, but the transport documentation has more information. We tried to make it as straightforward as possible, but as always the mailing list is there if you need help.
I am looking for a similar solution, but one that would work from the browser, and not NodeJS. Would it be possible? please refer #1042
Edit: From the answer I received in the issue above, it looks like it isn't possible. But I will leave the message here for posterity. In case browsers start to support, then it would be awesome...