Tlantic / cdv-socket-plugin

Cordova Socket Plugin
GNU General Public License v3.0
51 stars 43 forks source link

Android - Binary data support (send only) #54

Open shblythe opened 10 years ago

shblythe commented 10 years ago

This is related to issue #53 where the same was requested for iOS.

(I don't know if the user who raised that issue also wanted receive support, but in my application I only need to send binary data).

I propose addition of a new method:

sendBinary(successCallback, errorCallback, connectionId, data)

In this case data is a JSONArray, one byte per element, so it may be called as follows:

window.tlantic.plugins.socket.sendBinary(
  function() {
    console.log('sent')
  },
  function(error) {
    console.log('failed to send: '+error)
  },
  connectionId,
  [ 0x01, 0x00, 0x01, 0xFD ]
);
vinnylinck commented 10 years ago

Thank you!

On 30/06/2014, at 17:29, shblythe notifications@github.com wrote:

This is related to issue #53 where the same was requested for iOS.

(I don't know if the user who raised that issue also wanted receive support, but in my application I only need to send binary data).

I propose addition of a new method:

sendBinary(successCallback, errorCallback, connectionId, data) In this case data is a JSONArray, one byte per element, so it may be called as follows:

window.tlantic.plugins.socket.sendBinary( function() { console.log('sent') }, function(error) { console.log('failed to send: '+error) }, connectionId, [ 0x01, 0x00, 0x01, 0xFD ] ); — Reply to this email directly or view it on GitHub.

thomasbrueggemann commented 10 years ago

Wouln't something like this work too?

var arraydata = [77, 67, 71, 80];
var stringdata = String.fromCharCode.apply(null, arraydata);

window.tlantic.plugins.socket.sendBinary(
  function() {
    console.log('sent')
  },
  function(error) {
    console.log('failed to send: '+error)
  },
  connectionId,
  stringdata
);