Sha256: a8e645ff7d13a5a1246d9a2ae0c483dcd77d0b4cec7adc89108c60df408d4bef
Contents?: true
Size: 734 Bytes
Versions: 35
Compression:
Stored size: 734 Bytes
Contents
const EventEmitter = require('events'); // wrapper around the Node.js ws module // for use in browsers class WebSocketWrapper extends EventEmitter { constructor(url) { super(); this._ws = new WebSocket(url); this._ws.onopen = () => { this.emit('open'); }; this._ws.onclose = () => { this.emit('close'); }; this._ws.onmessage = (event) => { this.emit('message', event.data); }; this._ws.onerror = () => { this.emit('error', new Error('WebSocket error')); }; } close() { this._ws.close(); } send(data) { this._ws.send(data); } } module.exports = WebSocketWrapper;
Version data entries
35 entries across 35 versions & 2 rubygems