You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Connect to a WebSocketServer z.B. 'wss://echo.websocket.org'
Send a ws message
Close the ws
Please read the following code comments
constws=newWebSocket('wss://echo.websocket.org');ws.onopen=()=>{// connection openedws.send('something');// send a message// close the webSocket could happen because of the wsServerws.close();try{// send again on the closed connectionws.send('test');// now you get a Java Error: cannot send to Unknown WebSocket id XYZ// the error is not catchable because it originates in the Java WebSocketModule.java// this shouldn't happen because the server can always close the connection for some reason// we should be able to catch that.}catch(err){console.log('caught error');console.log(err);}};
Expected Behavior
The Error should be caught in the catch block.
Actual Behavior
I get a red screen which I can't keep from the user.
Reproducible Demo
With a setup branch on a test reop
Clone the repo and switch to branch: UnknownWebSocketIdError
git clone https://github.com/Tonacatecuhtli/createRnIssues
cd createRnIssues
git checkout https://github.com/Tonacatecuhtli/createRnIssues
With an initial rn project and copy-paste App.js
Create an initial react-native project and copy this into your App.js
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */importReact,{Component}from'react';import{Platform,StyleSheet,Text,View,Button}from'react-native';constinstructions=Platform.select({ios: 'Press Cmd+R to reload,\n'+'Cmd+D or shake for dev menu',android: 'Double tap R on your keyboard to reload,\n'+'Shake or press menu button for dev menu',});exportdefaultclassAppextendsComponent<{}>{testWs(){constws=newWebSocket('wss://echo.websocket.org');ws.onopen=()=>{// connection openedws.send('something');// send a message// close the webSocket could happen because of the wsServerws.close();try{// send again on the closed connectionws.send('test');// now you get a Java Error: cannot send to Unknown WebSocket id XYZ error// the error is not catchable because it originates in the Java WebSocketModule.java// this shouldn't happen because the server can always close the connection for some reason// we should be able to catch that.}catch(err){console.log('caught error');console.log(err);}};ws.onmessage=(e)=>{// a message was receivedconsole.log(e.data);};ws.onerror=(e)=>{// an error occurredconsole.log(e.message);};ws.onclose=(e)=>{// connection closedconsole.log(e.code,e.reason);};}render(){return(<Viewstyle={styles.container}><Textstyle={styles.welcome}>
Welcome to React Native!
</Text><Textstyle={styles.instructions}>Togetstarted,editApp.js</Text><Textstyle={styles.instructions}>{instructions}</Text><Buttontitle="test websocket"onPress={this.testWs}/>
</View>);}}conststyles=StyleSheet.create({container: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},welcome: {fontSize: 20,textAlign: 'center',margin: 10,},instructions: {textAlign: 'center',color: '#333333',marginBottom: 5,},});
The text was updated successfully, but these errors were encountered:
Is this a bug report?
yes
Have you read the Contributing Guidelines?
yes
Environment
Environment:
OS: Windows 10
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.0.0.0 AI-171.4443003
Packages: (wanted => installed)
react: ^16.0.0 => 16.0.0
react-native: github:facebook/react-native#master => 1000.0.0
Target Platform: Android (>=6)
Steps to Reproduce
Expected Behavior
The Error should be caught in the catch block.
Actual Behavior
I get a red screen which I can't keep from the user.
Reproducible Demo
With a setup branch on a test reop
Clone the repo and switch to branch: UnknownWebSocketIdError
git clone https://github.com/Tonacatecuhtli/createRnIssues cd createRnIssues git checkout https://github.com/Tonacatecuhtli/createRnIssues
With an initial rn project and copy-paste App.js
Create an initial react-native project and copy this into your App.js
The text was updated successfully, but these errors were encountered: