Skip to content

Conversation

@dewe
Copy link

@dewe dewe commented Feb 27, 2016

Adding WebSocket support for sending ArrayBuffer. This was previously not implemented, just printing a warning to console.

Support for receiving ArrayBuffers was implemented in #4483.

Test plan
Code was tested with Paho MQTT Client that requires support for sending ArrayBuffers.

This test code roundtrips an MQTT message over websockets and writes to console:

// Download from http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git/plain/src/mqttws31.js
import './mqttws31'; 

window.localStorage = {
    _data       : {},
    setItem     : function(id, val) { return this._data[id] = String(val); },
    getItem     : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
    removeItem  : function(id) { return delete this._data[id]; },
    clear       : function() { return this._data = {}; }
  };

var client = new Paho.MQTT.Client('broker.mqttdashboard.com', 8000, 'rn-client');

client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;

client.connect({
  onSuccess: onConnect,
  onFailure: onFail
});

function onConnect() {
  console.log("Sending message...");
  var message = new Paho.MQTT.Message('MQTT over websockets, ' + new Date().toISOString());
  message.destinationName = 'test/websockets';
  client.subscribe('test/websockets');
  client.send(message);
}

function onMessageArrived(msg) {
  console.log(`Received from '${msg.destinationName}': ${msg.payloadString}`);
}

function onConnectionLost(r) {
  console.log('Connection lost: ' + r.errorMessage);
}

function onFail(e) {
  console.log('Failed connect', e);
}

CLA has been signed.

Implements support for sending ArrayBuffers.
@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @satya164, @lindskogen and @hharnisc to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 27, 2016
@facebook-github-bot
Copy link
Contributor

@dewe updated the pull request.

@facebook-github-bot
Copy link
Contributor

@dewe updated the pull request.

@mckn
Copy link

mckn commented Feb 29, 2016

Awesome! I really need this feature as well 👍

@sreesharp
Copy link
Contributor

This is great! @dewe Are you planning to submit the Android fix as well? If not, I can submit that as another PR.

@dewe
Copy link
Author

dewe commented Mar 1, 2016

Go ahead @sreesharp. I wasn't aware this was a problem on Android as well.

@jeremyong
Copy link

Just FYI, I took the liberty to resubmit this as #6327 and fixed the conflicts and all that so it is available as a single clean commit (I also squashed your existing commits). Authorship was not changed.

@dewe
Copy link
Author

dewe commented Mar 16, 2016

Closing this in favour of #6327

@dewe dewe closed this Mar 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants