mcollina / mows

Using MQTT.js in the browser over WebSocket -- Built with browserify!
72 stars 12 forks source link

Pre-compiled browser client #10

Closed RangerMauve closed 10 years ago

RangerMauve commented 10 years ago

Hey, it'd be nice if there was a pre-compiled browserify bundle on a CDN or something of the sort for easy integration with projects.

RangerMauve commented 10 years ago

Actually, it looks like there isn't even a browser.js to put through browserify...

mcollina commented 10 years ago

Have a look at this package.json. The whole thing is built to be able to run in the browser first.

RangerMauve commented 10 years ago

Err, does that mean that I need to compile the package itself and not browser.js? I haven't used browserify before and I think the readme might be a little out of date. When I tried to build index.js, it was giving me errors when I was trying to make a connection. Running browserify . -s mows > mows.js isn't working either. The error I'm getting is:

parser.header = function(buf, packet) {
  var zero = buf.readUInt8(0);
                        ^ Uncaught TypeError: undefined is not a function

The code I'm using after adding the script to my page is:

var socket = mows.createClient("ws://localhost:80?clientId=someid");
socket.on("connect", function () {
    console.log("Connected mqtt");
})
mcollina commented 10 years ago

Would you like to send a PR to add that? Have a look at how Mosca builds it: https://github.com/mcollina/mosca/blob/master/package.json#L17.

mcollina commented 10 years ago

What version of browserify are you running? It needs one of the latests, as there the buffer additions.

mcollina commented 10 years ago

This should be working: http://test.mosca.io/mqtt.js

RangerMauve commented 10 years ago

I'm using Browserify v4.2.0

mcollina commented 10 years ago

This was built for browserify 3, so it might need some updates/fix

RangerMauve commented 10 years ago

I'll try installing Browserify 3 and see if that helps in the meantime.

RangerMauve commented 10 years ago

Browserify 3.46.1 is working properly.

mcollina commented 10 years ago

I updated MQTT.js to be able to work with Browserify 4.2, see https://github.com/adamvr/MQTT.js/commit/cde47a7f4b44b3af2c4a31b18d3b9fc0e2f385d9.

RangerMauve commented 10 years ago

Reinstalling mows and trying the steps again seems to be having the same issue as before. npm ls says that I have mows 0.0.6 and it's got mqtt 0.3.10

mcollina commented 10 years ago

I've just released MQTT.js v0.3.11.

RangerMauve commented 10 years ago

Just tested it and it works perfectly, though the issue is really about pre-compiling the bundle, I think that just being able to compile it should be easy enough.