eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.15k stars 467 forks source link

messages mixed up when multiple retained messages are received at once #41

Closed jpwsutton closed 8 years ago

jpwsutton commented 8 years ago

migrated from Bugzilla #424753 status RESOLVED severity normal in component MQTT-JS for --- Reported in version future on platform PC Assigned to: Andrew Banks

On 2013-12-30 12:15:34 -0500, Kris K wrote:

Using the developer branch, which I believe, is supposed to handle multiple messages in one websocket frame, messages appear to get mixed up. I am using mosquitto with the mod_websocket from https://launchpad.net/~roger.light/+archive/ppa

Steps to reproduce: 1) create 2 retained msgs: mosquitto_pub -t "/test/topic1" -m "blaba" -r mosquitto_pub -t "/test/topic2" -m "blubu" -r

2) run javascript: var clientid = "clientid_"+ Math.random().toString(36).substring(7); client = new Messaging.Client("wss://172.22.197.77:443/mqtt", clientid); // your mqtt-websocket broker here client.onConnectionLost = onConnectionLost; client.onMessageArrived = onMessageArrived; client.connect({onSuccess:onConnect});

function onConnect() { console.log("onConnect"); client.subscribe("/test/#"); };

function onConnectionLost(responseObject) { if (responseObject.errorCode !== 0) console.log("onConnectionLost:"+responseObject.errorMessage); };

function onMessageArrived(message) { console.log("onMessageArrived: Topic: "+message.destinationName+' msg='+message.payloadString); }

3) on my system, it comes out like this: onConnect retained_msg_test.html:18 onMessageArrived: Topic: /test/topic1 msg=blaba1/test/topic2blubu retained_msg_test.html:29 onMessageArrived: Topic: /test/topic2 msg=blubu

On 2014-01-09 09:48:23 -0500, Kris K wrote:

following patch will fix this problem:

diff --git a/src/main/javascript-templates/mqttws31s.js b/src/main/javascript-templates/mqttws31s.js index a234c49..36f2e63 100644 @@ -459,7 +459,7 @@ Messaging = (function (global) { pos += 2; }

  • var message = new Messaging.Message(input.subarray(pos));
  • var message = new Messaging.Message(input.subarray(pos, endPos)); if ((messageInfo & 0x01) == 0x01) message.retained = true; if ((messageInfo & 0x08) == 0x08)