registration using sip.js and websockets in Node (wss or ws)it

2,191 views
Skip to first unread message

Gonzalo Gasca

unread,
Oct 15, 2014, 11:59:45 PM10/15/14
to sip...@googlegroups.com

I'm trying to register SIP agents using sip.js and Node to start load testing to my Kamailio

Node version v0.10.32


process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
global.WebSocket = require('ws')
// SipJS Initialization
var SIP = require('./sip-0.6.0.js');

var Uaconfig = {
        traceSip: true,
        register: true,
        userAgentString: 'sipJS Test tool',
        uri: 'ramenlabs.io',
        wsServers: ['wss://ramenlabs.io:5063'],
        authorizationUser: 'gogasca',
        password: '********'
        //hackIpInContact: true
};

var userAgent = new SIP.UA(Uaconfig);

When I run it I get an error:

Thu Oct 16 2014 03:40:53 GMT+0000 (UTC) | sip.transport | WebSocket connection error: Error: unexpected server response (400)

Because initial Websocket from Sip.js lacks Sec-WebSocket-Protocol: sip to indicate SIP Protocol. If i use sample web page it works perfectly with same parameters, but not from my node command line. How to force this?

In API js I do see the 'sip' extra header but contains the window.Websocket

try {
      this.ws = new window.WebSocket(this.server.ws_uri, 'sip');
    }
    catch(e) {
       this.logger.log('Error connecting to WebSocket ' + this.server.ws_uri + ': ' + e);
       //return false;
    }

wakam...@gmail.com

unread,
Oct 17, 2014, 1:59:08 PM10/17/14
to sip...@googlegroups.com
Hi Gonzalo,

It looks like this is a missing feature of the `ws` module. From their code (https://github.com/einaros/ws/blob/master/lib/WebSocket.js#L50)

// TODO: actually handle the `Sub-Protocols` part of the WebSocket client

So, it looks like there isn't a way to get that header in with that WebSocket package. I take it Kamailio requires it to accept the connection?

-Will
Hi

Joseph Frazier

unread,
Oct 17, 2014, 10:18:07 PM10/17/14
to sip...@googlegroups.com, wakam...@gmail.com
I looked into this as well, and it actually appears to be a bug in ws. Since the "Sec-WebSocket-Protocol: sip" header is RFC-mandated, I'll follow up on the pull request and try to get it merged. In the mean time, you could work around the bug by patching either your ws module or Transport.js as suggested in the pull request (note that the syntax of the latter suggestion is non-standard and does not work in the browser).

Thanks,
Joseph
Message has been deleted

Andrew

unread,
Nov 11, 2014, 8:46:34 AM11/11/14
to sip...@googlegroups.com, wakam...@gmail.com
Hello Joseph, I am running into this issue with 0.6.3, and I even tried building from source today with the suggested manual change in the ws bug lin your provided but the problem persists. My example works fine in 0.6.0.
Here is what I am doing to test:

global.WebSocket = require('ws');
var SIP = require('./sip-0.6.3.js');
var ua = new SIP.UA({traceSip: true});
TypeError: Cannot set property 'binaryType' of null
    at Object.Transport.connect (/home/ubuntu/onsip/SIP.js/dist/sip-0.6.3.js:7836:24)
    at Object.Transport (/home/ubuntu/onsip/SIP.js/dist/sip-0.6.3.js:7762:8)
    at Object.UA.start (/home/ubuntu/onsip/SIP.js/dist/sip-0.6.3.js:8424:12)
    at Object.UA (/home/ubuntu/onsip/SIP.js/dist/sip-0.6.3.js:8222:10)
    at repl:1:11
    at REPLServer.self.eval (repl.js:110:21)
    at repl.js:249:20
    at REPLServer.self.eval (repl.js:122:7)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)

I check line 7836 and this->ws is null after new Wesockets..

If you can suggest trying something to debug this further please let me know.
Thanks,
Andrew

Joseph Frazier

unread,
Nov 11, 2014, 3:07:05 PM11/11/14
to sip...@googlegroups.com, wakam...@gmail.com
Hi Andrew,

It sounds like your ws module might not be working correctly. Can you confirm the output of the following script?

global.WebSocket = require('ws'); 
var socket = new WebSocket('wss://echo.websocket.org');
socket.on('message', console.log.bind(console));
socket.on('open', socket.send.bind(socket, 'hello world'));

It should print the following:

hello world { masked: false,
  buffer: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64> } 

Joseph
Message has been deleted
Message has been deleted
Message has been deleted

Andrew

unread,
Nov 12, 2014, 12:41:44 PM11/12/14
to sip...@googlegroups.com, wakam...@gmail.com
It prints the same result as you. I may remove and re-install node next. Do you have any other suggestions? What linux distro and node version did you use? I am using Ubuntu 12 with node version v0.13.0-pre
Thanks,
Andrew

Joseph Frazier

unread,
Nov 12, 2014, 1:29:31 PM11/12/14
to sip...@googlegroups.com, wakam...@gmail.com
Hey, sorry about the trouble with replying. I'm not quite sure what's going on, but I went and permanently allowed you to post, so hopefully the problems will go away.

I'm using OSX 10.9.5 with the following configuration:

node --version && npm --version && npm ls

v0.10.32

2.1.2

/private/tmp

├── sip...@0.6.3

└─┬ w...@0.4.32

  ├── comm...@2.1.0

  ├── n...@1.0.0

  ├── opt...@0.0.6

  └── tiny...@0.0.1

I'm guessing you'll have better luck with a stable version of Node, but I'd also try modifying Transport.js instead of the ws module, just to rule out any problems with it.

Let me know how it goes,
Joseph

Andrew Pappas

unread,
Nov 14, 2014, 2:49:10 PM11/14/14
to Joseph Frazier, sip...@googlegroups.com, wakam...@gmail.com
I tried re-installing npm and node, nodejs. Still have the issue. I also tried node 0.10.32 and node 0.10.33.
I might just fire up a new server to make sure I didn't screw up and symlinks or library references somehow.
Here is the result of my versions:

ubuntu@ip-10-0-0-212:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty


ubuntu@ip-10-0-0-212:~$ node --version && npm --version && npm ls
v0.10.33
2.1.7
/home/ubuntu
├─┬ n...@2.1.2
│ ├── abb...@1.0.5
│ ├── an...@0.3.0
│ ├── ansic...@0.3.2
│ ├── ansis...@0.1.3
│ ├── ar...@0.0.2
│ ├── async...@1.0.1
│ ├── block-...@0.0.7
│ ├── char-s...@1.0.1
│ ├── child-pro...@0.1.1
│ ├── chm...@0.1.0
│ ├── cho...@0.0.1
│ ├── cmd-...@2.0.1
│ ├─┬ colu...@1.2.1
│ │ ├─┬ strip...@1.0.0
│ │ │ └── ansi-...@0.2.1
│ │ └─┬ wcw...@1.0.0
│ │   └─┬ defa...@1.0.0
│ │     └── cl...@0.1.18
│ ├─┬ dez...@1.0.0
│ │ └── as...@1.0.0
│ ├── edi...@0.1.0
│ ├── fs-v...@1.2.1
│ ├── fs-write-st...@1.0.2
│ ├── fst...@1.0.2
│ ├─┬ fstre...@1.0.0
│ │ └── fstream...@1.0.1
│ ├── github-ur...@1.4.0
│ ├── github-url-fro...@1.0.2
│ ├── gl...@4.0.5
│ ├── grace...@3.0.2
│ ├── infl...@1.0.1
│ ├── inhe...@2.0.1
│ ├── i...@1.2.1
│ ├─┬ init-pac...@1.1.0
│ │ └── prom...@0.2.2
│ ├── lock...@1.0.0
│ ├── lru-...@2.5.0
│ ├─┬ mini...@1.0.0
│ │ └── sig...@1.0.0
│ ├─┬ mkd...@0.5.0
│ │ └── mini...@0.0.8
│ ├── node...@1.0.2
│ ├── no...@3.0.1
│ ├── normalize-p...@1.0.3
│ ├── npm-cache...@1.0.1
│ ├── npm-insta...@1.0.4
│ ├── npm-pac...@2.1.2
│ ├── npm-regis...@3.2.2
│ ├── npm-user...@0.1.0
│ ├─┬ npm...@2.1.0
│ │ └─┬ config...@1.1.8
│ │   └── proto...@1.2.3
│ ├── npm...@0.1.1
│ ├── on...@1.3.0
│ ├── ope...@1.3.0
│ ├── os...@0.1.0
│ ├── path-is...@1.0.1
│ ├─┬ re...@1.0.5
│ │ └── mute-...@0.0.4
│ ├─┬ read-in...@3.1.3
│ │ ├── debu...@1.0.1
│ │ ├── readdir-sco...@1.0.0
│ │ └── util-...@1.0.1
│ ├── read-pac...@1.2.7
│ ├─┬ req...@2.44.0
│ │ ├── aws-...@0.5.0
│ │ ├─┬ b...@0.9.3
│ │ │ └─┬ readabl...@1.0.31
│ │ │   ├── core-u...@1.0.1
│ │ │   ├── isa...@0.0.1
│ │ │   └── string_...@0.10.31
│ │ ├── case...@0.6.0
│ │ ├── foreve...@0.5.2
│ │ ├─┬ form...@0.1.4
│ │ │ ├── as...@0.9.0
│ │ │ ├─┬ combine...@0.0.5
│ │ │ │ └── delayed...@0.0.5
│ │ │ └── mi...@1.2.11
│ │ ├─┬ ha...@1.1.1
│ │ │ ├── bo...@0.4.2
│ │ │ ├── cryp...@0.2.2
│ │ │ ├── ho...@0.9.1
│ │ │ └── sn...@0.2.4
│ │ ├─┬ http-si...@0.10.0
│ │ │ ├── as...@0.1.11
│ │ │ ├── asser...@0.1.2
│ │ │ └── ct...@0.5.2
│ │ ├── json-stri...@5.0.0
│ │ ├── mime-...@1.0.2
│ │ ├── node...@1.4.1
│ │ ├── oauth...@0.4.0
│ │ ├── q...@1.2.2
│ │ ├── string...@0.0.4
│ │ ├─┬ tough-...@0.12.1
│ │ │ └── puny...@1.3.1
│ │ └── tunnel...@0.4.0
│ ├── re...@0.6.0
│ ├── rim...@2.2.8
│ ├── sem...@4.0.0
│ ├─┬ s...@1.2.4
│ │ └─┬ readabl...@1.0.31
│ │   ├── core-u...@1.0.1
│ │   ├── isa...@0.0.1
│ │   └── string_...@0.10.31
│ ├── sl...@1.1.6
│ ├── sorted...@1.0.0
│ ├── t...@1.0.1
│ ├── text-...@0.2.0
│ ├── uid-n...@0.0.5
│ ├── wh...@1.0.5
│ └── write-fi...@1.1.0
├── sip...@0.6.3
└─┬ w...@0.4.32
  ├── comm...@2.1.0
  ├── n...@1.0.0
  ├── opt...@0.0.6
  └── tiny...@0.0.1

--
You received this message because you are subscribed to a topic in the Google Groups "SIP.js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sip_js/5GyRZHvyUTI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sip_js+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Pappas

unread,
Nov 18, 2014, 11:19:31 AM11/18/14
to Joseph Frazier, sip...@googlegroups.com, William Mitchell
After installing node, npm, and sipjs with the version above on a new system I no longer have the issue. I must have corrupted my server with multiple versions of the packages somehow.
Thanks for seeing this through with me.
Andrew 

On Wed, Nov 12, 2014 at 1:29 PM, Joseph Frazier <jos...@onsip.com> wrote:

--

Joseph Frazier

unread,
Nov 18, 2014, 11:21:59 AM11/18/14
to sip...@googlegroups.com, jos...@onsip.com, wakam...@gmail.com
Glad to hear you got it working! Let us know if you encounter any further problems.

Joseph
To unsubscribe from this group and all its topics, send an email to sip_js+unsubscribe@googlegroups.com.

Joseph Frazier

unread,
Dec 29, 2014, 1:06:33 PM12/29/14
to sip...@googlegroups.com, jos...@onsip.com, wakam...@gmail.com
Resurrecting the thread to mention that this has been fixed on the master branch: https://github.com/onsip/SIP.js/commit/e746a9d84bf024bae1a21cef8ad08e24c922fcb6

bbbu...@usc.edu

unread,
Feb 14, 2019, 9:12:19 PM2/14/19
to SIP.js
Hi!

I'm trying to use SIP.js in Node.js.

In order to add WebSocket capabilities in Node.js, do I need to just include the line: global.WebSocket = require('ws')?
Reply all
Reply to author
Forward
0 new messages