UNPKG

@iosio/websocket-client

Version:

Simple wrapper for native client-side WebSocket. Similar to socket.io. Easy to use with any backend

21 lines (16 loc) 339 B
class Transmitter{ constructor(){ this.socket = false; } setSocket = (socket) => { this.socket = socket; }; send = (event, data) =>{ if(!this.socket){ console.error('no socket available in transmitter'); return; } this.socket.send(JSON.stringify({event, data})); } } export const transmitter = new Transmitter();