How can I use lib 'websocket' in React Native?

Asked

Viewed 39 times

0

I have a chunk of code that I can connect to my websocket server using it:

var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();

var token = "##############";

client.connect(`ws://pusher.dominio.tech/?token=${token}`);

client.on('connect', function(connection) {
    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            console.log("Received: '" + message.utf8Data + "'");
        }
    });
    console.log("conectado");
})

I’d like to know how I can implement this connection using this lib in an React Native app (I use Expo).

Useful information:

  • Expo 40.0.0
  • React 16.13.1
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.