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

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

Closed
orktes opened this issue Jun 24, 2015 · 3 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@orktes
Copy link

orktes commented Jun 24, 2015

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!

@orktes
Copy link
Author

orktes commented Jun 24, 2015

It seems that FileReader and atob (and probably Blob) are not implemented in JSCore by default. One option could be to decode base64 in pure JS directly into a TypedArray and then only support binaryType="text" and binaryType="arraybuffer".

master...Applifier:feature/ws_binaryType

@phoboslab
Copy link

We could also just push Apple to provide a native API for Typed Arrays in JSCore:
https://bugs.webkit.org/show_bug.cgi?id=120112

@brentvatne
Copy link
Collaborator

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out it's new home: https://productpains.com/post/react-native/websocket-rctwebsocket-crashes-when-receiving-messages-in-binary-format

@facebook facebook locked as resolved and limited conversation to collaborators Jul 22, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants