WebSocket missing when running on Node
mkdir sipjstest
cd sipjstest
npm init
npm i sip.js --save
echo "new (require('sip.js')).UA();" > index.js
node index.js
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.ua | configuration parameters after validation:
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.ua | · viaHost: "mbqm5mfb8olj.invalid"
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.ua | · uri: sip:[email protected]
...
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.ua | · authorizationUser: "anonymous.nif1vp"
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.ua | user requested startup...
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.transport | connecting to WebSocket wss://edge.sip.onsip.com
Thu Nov 02 2017 17:24:30 GMT+0100 (CET) | sip.transport | error connecting to WebSocket wss://edge.sip.onsip.com: TypeError: t is not a constructor
~/code/sipjstest/node_modules/sip.js/dist/sip.min.js:38
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t()...
TypeError: Cannot set property 'binaryType' of null
If I go into sip.min.js and use ws package from npm there instead of e.WebSocket (environment.WebSocket), it'll actually try to connect:
// with e.WebSocket --> require('ws')
...
Thu Nov 02 2017 17:58:41 GMT+0100 (CET) | sip.ua | user requested startup...
Thu Nov 02 2017 17:58:41 GMT+0100 (CET) | sip.transport | connecting to WebSocket wss://edge.sip.onsip.com
Thu Nov 02 2017 17:58:43 GMT+0100 (CET) | sip.transport | WebSocket connection error:
{ Error: unexpected server response (400)
Tested on Node version 8.9.0
I think I see the issue. I will try and get a patch into our next release to resolve this.
Can this library run on a server (no audio)?
This problem is actually a bit trickier than I originally anticipated. Refactoring the transport is on my list of things to improve in SIP.js.
The issue you are seeing is that there is no WebSocket defined for SIP.js to connect to and therefore the connection code fails. However, when the connection code fails there is nothing really indicating that it has failed so it continues down the same code block. If I change the behavior of this code, it could adversely affect other portions of the code and it still may not solve the problem as the UA may just continually call connect without any regard as to its response. So, as I said a bit trickier than originally anticipated, but I hope to put some major work in here in the near future.
As of 0.11.0 the transport code got a massive refactor- can you double check and see if this is still broken? I realize it's been a while and may not be an issue anymore.
Since its been a while I'm going to close this- feel free to open up a new issue if the problem still persists
Now that you have refactored the transport, can you give an example of using it? I am trying to connect via Websocket in Node.js. Thanks.
The default Websocket interface provided works in web browsers. You will need to create your own Transport to use with Node.js. We would take it back into the library as a pull request.