Skip to content

[WebSocket] RCTWebSocket crashes when receiving messages in binary format #1730

@orktes

Description

@orktes

WebSocket client doesn't currently contain any handling for binary messages and just passes the message directly to bridge. This crashes the application.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_NSInlineData)'

Problematic code:

- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
{
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketMessage" body:@{
@"data": message,
@"id": webSocket.reactTag
}];
}

Few ways to fix this.

  1. Wait for [Bridge] Array Buffers / Typed Arrays for WebSockets, Ajax #1424
  2. Pass error describing the issue instead of crashing
  3. Convert NSData to string
  4. Base64 encode NSData and convert to arraybuffer & blob in JS

Personally I'd prefer 4. as it brings the polyfill api more closer to actual WebSocket behaviour. I can take a stab at the problem once we've settled with the correct approach.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions