Posts

Showing posts with the label websocket

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...

Rails ActionCable and React Native

I'm working on a companion React Native app to accompany my RoR webapp, and want to build a chat feature using ActionCable (websockets). I cannot get my React Native app to talk to ActionCable. I have tried a number of libraries including react-native-actioncable with no luck. The initial connection seems to be working (I know this because I was having errors before and they've since gone away when I passed the proper params). This is an abbreviated version of my React Native code: import ActionCable from 'react-native-actioncable' class Secured extends Component { componentWillMount () { var url = 'https://x.herokuapp.com/cable/?authToken=' + this.props.token + '&client=' + this.props.client + '&uid=' + this.props.uid + '&expiry=' + this.props.expiry const cable = ActionCable.createConsumer(url) cable.subscriptions.create('inbox_channel_1', { received: function (data) { console....

React Native with Socket.io

I'm trying to use socket.io client from react native. I found several answers in stack overflow including this one: Is it possible to combine React Native with socket.io which suggests using socket-io client and setting the navigator.userAgent to react-native. I tried it and it doesn't work on my android, I also found a video about this in youtube but the guy got it to work on an emulator, for me once I used remote debugging it worked as well because it was on the browser I guess. And I found a project on https://www.npmjs.com/package/react-native-socketio but it is still a work in progress. Can someone who had to deal with this issue and managed to find a solution give out some pointers? In the end I resorted to using react native websockets on the client side and the npm ws library on the server side which works just fine but I don't have any of the fallbacks. I don't know if you solved your problem, but for anyone facing the same issue: you don't...

Websocket.send(blob) in React Native

I am trying to send blob data with Websocket in React Native. My React native and web code are equal as following: var websocket = new WebSocket(this.state.wsURI); websocket.onopen = function(evt) { onOpen(evt) }; websocket.onclose = function(evt) { onClose(evt) }; websocket.onmessage = function(evt) { onMessage(evt) }; websocket.onerror = function(evt) { onError(evt) }; function onClose(evt){ console.log('disconnected'); } function onOpen(evt) { var message = { action: 'start', 'content-type': 'audio/wav', }; websocket.send(JSON.stringify(message)); websocket.send(blob); websocket.send(JSON.stringify({action: 'stop'})); } In the web application, blob data is well sent. However in the React Native App, the error message ( Unsupported dataType for Websocket.send ) occurs. The console log of blob in react native is, Blob {listeners: Object, isRNFetchBlobPolyfill: true, multipartBoundary: null, _ref: "/Users...

flutter websocket connection issue

I am trying to develop a flutter app which connects to the server and exchanges data using websocket. The server is in .Net Core and using Asp.Net Core Websockets to implement this functionality. The problem I am facing is, my flutter app is not able to connect to the server and throws following error. E/flutter (31498): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception: E/flutter (31498): WebSocketChannelException: WebSocketChannelException: WebSocketException: Connection to 'http://127.0.0.1/client#' was not upgraded to websocket E/flutter (31498): #0 new IOWebSocketChannel._withoutSocket.<anonymous closure> (package:web_socket_channel/io.dart:83:24) E/flutter (31498): #1 _invokeErrorHandler (dart:async/async_error.dart:13:29) E/flutter (31498): #2 _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9) E/flutter (31498): #3 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13) E/flutter (3149...