Posts

Showing posts with the label autobahn

React-Native and AutobahnJS

I am trying to set up a connection with a WebSocket server in a React-Native application using the npm package react-native-autobahnjs. Here is my code : 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> ); } } I get the...

WebSocket React Native

I'm new to react native moved from ReactJS I thought I can use same packages as my previous pure Reactjs app but I was wrong. What I'm trying to do is to make a websocket connection. I'm recently using autobahnJS package WAMP2 in my ReactJS app but when I moved to react native it seems autobahnJS doesn't support react-native connectToSocketFunction = () =>{ // autobahn code let connection = new autobahn.Connection({ url: 'wss://api.example.com/websocket/', realm: 'Realm1', authmethods: ['jwt'] }); connection.onopen = (session, detalis) => { session.subscribe('ChannelName', (data)=>console.log(data)); }; Anyone know how does react native make socket connection based on my code? I have tried react-native-autobahnjs doesn't work The React Native documentation mentions support for WebSocket connections: var ws = new WebSocket('ws://host.com/path'); ws.o...