Sha256: 230ec502475500164e079e90a98f43173df96940f13fdd296dd2d24ac0633261

Contents?: true

Size: 894 Bytes

Versions: 12

Compression:

Stored size: 894 Bytes

Contents

'use strict';

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); // eslint-disable-line no-undef
        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, callback) {
        try {
            this._ws.send(data);
            callback();
        } catch (err) {
            callback(err);
        }
    }
}

module.exports = WebSocketWrapper;

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.8.2 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.8.1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.8.0 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.8.0.beta1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.4 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.8.0.alpha1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.3 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.2 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.0 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js
opal-1.7.0.rc1 lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js