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

Issues with ArrayBuffer in Flutter Web #51

Closed
beevelop opened this issue Jan 10, 2020 · 1 comment
Closed

Issues with ArrayBuffer in Flutter Web #51

beevelop opened this issue Jan 10, 2020 · 1 comment

Comments

@beevelop
Copy link

When using Socket.io with Flutter Web and sending ArrayBuffers over the pipe, the browser throws the following exception:

Uncaught Error: NoSuchMethodError: '[]'
Dynamic call of null.
Receiver: Instance of 'NativeByteBuffer'
Arguments: [0]
    at Object.throw_ [as throw] (errors.dart:196)
    at Object.defaultNoSuchMethod (operations.dart:667)
    at ArrayBuffer.noSuchMethod (core_patch.dart:63)
    at Object.noSuchMethod (operations.dart:662)
    at callNSM (operations.dart:255)
    at Object._checkAndCall (operations.dart:268)
    at Object.callMethod (operations.dart:390)
    at Object.dsend (operations.dart:394)
    at Function.decodePacket (parser.dart:170)
    at websocket_transport.WebSocketTransport.new.onData (transport.dart:121)
    at websocket_transport.dart:59
    at Object._checkAndCall (operations.dart:326)
    at Object.dcall (operations.dart:331)
    at WebSocket.<anonymous> (html_dart2js.dart:35657)

I saw, that the required code portion is in place, but unfortunately commented out.

if (data instanceof ArrayBuffer) {
  data = arrayBufferToBuffer(data);
}

https://github.com/rikulo/socket_io_common/blob/master/lib/src/engine/parser/parser.dart#L167

I tried adapting the implementation to automatically detect the ArrayBuffer, and it seems to (at least) stop throwing exceptions:

    if (binaryType == 'arraybuffer' || runtimeType == 'ByteBuffer') { //  || data.runtimeType == 'NativeByteBuffer'
      // wrap Buffer/ArrayBuffer data into an Uint8Array
      var intArray = (data as ByteBuffer).asUint8List();
      type = intArray[0];
      return {'type': PacketTypeList[type], 'data': intArray.sublist(0)};
    }

Would this be a suitable approach?

@jumperchen
Copy link
Member

@beevelop please upgrade the socket_io_common to 0.9.1 to see if the fix works, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants