我正在尝试使用npm包react-native-autobahnjs在React-Native应用程序中建立与WebSocket服务器的连接。
这是我的代码:
import autobahn from 'react-native-autobahnjs';
class websocket extends Component {
componentWillMount () {
console.warn("MOUNTING MAIN COMPONENT");
const connection = new autobahn.Connection({
url: 'wss://myserver/ws',
realm: 'realm1'
});
connection.onopen = () => {
console.warn("onopen");
};
connection.onclose = (reason, details) => {
console.warn("onclose : reason = " + reason + ", details = " + details);
};
console.warn("connection.open()");
connection.open();
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
autobahn.js test page
</Text>
</View>
);
}
}
我收到以下警告:onclose : reason = unsupported, details = [object Object]
出了什么问题? 谢谢。