Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. #9

Open
valichek opened this issue Nov 8, 2017 · 9 comments
Assignees

Comments

@valichek
Copy link

valichek commented Nov 8, 2017

Checked in FF and Chrome. Getting TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.

this.sock.addEventListener('message', function(e) {
	self.emit('data', new Buffer(e.data));
});

Here is a line that throws error. https://github.com/isobit/websocket-nats/blob/master/lib/net.js#L14

The cause is that e.data is of Blob type.

valichek added a commit to valichek/websocket-nats that referenced this issue Nov 8, 2017
@isobit
Copy link
Owner

isobit commented Nov 8, 2017

It may be sufficient to just set this.sock.binaryType = 'arraybuffer', I'll try to get a fix in later today.

https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Attributes

@valichek
Copy link
Author

valichek commented Nov 9, 2017

@isobit yes, this does the job

valichek added a commit to valichek/websocket-nats that referenced this issue Nov 9, 2017
@valichek
Copy link
Author

valichek commented Nov 9, 2017

@isobit also I have updated it to the latest lib from node-nats with some minor changes to get it working. so please check this master...valichek:update-to-0.7.24 and if everything is ok, merge it.

@antonioaguilar
Copy link

antonioaguilar commented Jan 28, 2018

@isobit @valichek I have tried the update to 0.7.24 but I'm getting the following exception:

Uncaught TypeError: url.format is not a function
    at Object.exports.createConnection (websocket-nats.dev.js:3967)
    at Client.createConnection (websocket-nats.dev.js:645)
    at new Client (websocket-nats.dev.js:211)
    at Object.exports.connect (websocket-nats.dev.js:224)
    at (index):6

using this code to test:

<html>
<head>
  <script src="../dist/websocket-nats.dev.js"></script>

  <script>
    var nats = NATS.connect('ws://localhost:8080/');

    setInterval(function () {
      nats.publish('topic.123', JSON.stringify({ date: new Date().toDateString() }));
    }, 1000);

    nats.subscribe('topic.*', function (data) {
      console.log(JSON.parse(data));
    });

  </script>
</head>
<body></body>
</html>

NATS is deployed using Docker and Websockets TCP relay:

docker run -it -d --rm --name="nats" -p 4222:4222 nats

./ws-tcp-relay -p 8080 localhost:4222

@valichek
Copy link
Author

@antonioaguilar hi, note that if you use https://github.com/valichek/websocket-nats/tree/update-to-0.7.24 you will get this error, because I didn't update dist scripts, only sources

@antonioaguilar
Copy link

@valichek I built using NODE_ENV=dev webpack ... if you guys could duplicate the issue and I can help with testing ...

@valichek
Copy link
Author

@antonioaguilar do you mean that creating dist from my fork doesn't help?

@antonioaguilar
Copy link

@valichek me bad, I had built the wrong repo. I can confirm that creating the dist from your fork does work. @isobit just wondering when this fork could be merged to the main branch?

@isobit
Copy link
Owner

isobit commented Jan 29, 2018

My apologies, I haven't updated this repo in a while; I will merge in the latest from upstream (node-nats) ASAP. I believe I actually have a branch lying around with some changes to use a newer webpack version as well...

@valichek I didn't want to merge your fork directly because your indentation whitespace changes created a massive diff for lib/nats.js.

@isobit isobit self-assigned this Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants