How to use the isomorphic-ws function in isomorphic-ws

To help you get started, we’ve selected a few isomorphic-ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitshares / bitsharesjs-ws / src / ChainWebSocket.js View on Github external
new Promise((resolve, reject) => {
      this.current_reject = reject;
      this.current_resolve = resolve;

      try {
        this.ws = new WebSocket(server);
      } catch (error) {
        this.ws = { readyState: 3, close: () => {} }; // DISCONNECTED
        reject(new Error("Invalid url", server, " closed"));
        // return this.close().then(() => {
        //     console.log("Invalid url", ws_server, " closed");
        //     // throw new Error("Invalid url", ws_server, " closed")
        //     // return this.current_reject(Error("Invalid websocket url: " + ws_server));
        // })
      }

      this.ws.onopen = this.onOpen;
      this.ws.onerror = this.onError;
      this.ws.onmessage = this.onMessage;
      this.ws.onclose = this.onClose;

      this.connectionTimeout = setTimeout(() => {
github collective-soundworks / soundworks / src / client / Socket.js View on Github external
const { hostname, port } = window.location;
      url = `${protocol}//${hostname}:${port}/${path}`;
    } else {
      const protocol = config.useHttps ? 'wss:' : 'ws:';
      const { ip, port } = config;
      url = `${protocol}//${ip}:${port}/${path}`;
    }

    const queryParams = `clientType=${clientType}&key=${key}`;

    // ----------------------------------------------------------
    // init string socket
    // ----------------------------------------------------------
    const stringSocketUrl = `${url}?binary=0&${queryParams}`;

    this.ws = new WebSocket(stringSocketUrl);
    log(`string socket initialized - url: ${stringSocketUrl}`);

    const stringSocketPromise = new Promise((resolve, reject) => {
      this.ws.addEventListener('open', resolve);
    });

    // parse incoming messages for pubsub
    this.ws.addEventListener('message', e => {
      const [channel, args] = unpackStringMessage(e.data);
      this._emit(false, channel, ...args);
    });

    // broadcast all `WebSocket` native events
    [ 'open',
      'close',
      'error',
github iotexproject / iotex-antenna / src / plugin / ws.ts View on Github external
private init(): void {
    this.ws = new WebSocket(this.provider);
    this.ws.onopen = (): void => {
      window.console.log("[antenna-ws] connected");
    };
    this.ws.onclose = (): void => {
      window.console.log("[antenna-ws] disconnected");
    };
  }
github filips123 / ZeroFrameJS / src / index.js View on Github external
async _getWebsocket () {
    const wsUrl = 'ws' + (this.instance.secure ? 's' : '') + '://' + this.instance.host + ':' + this.instance.port + '/Websocket?wrapper_key=' + this.wrapperKey
    let wsClient

    if (!this.multiuser.masterAddress) {
      wsClient = new WebSocket(wsUrl)
    } else {
      wsClient = new WebSocket(wsUrl, [], { headers: { Cookie: 'master_address=' + this.multiuser.masterAddress } })
    }

    wsClient.onmessage = this._onRequest.bind(this)
    wsClient.onopen = this._onOpenWebsocket.bind(this)
    wsClient.onerror = this._onErrorWebsocket.bind(this)
    wsClient.onclose = this._onCloseWebsocket.bind(this)

    return wsClient
  }
github GetScatter / scatter-js / packages / core / src / services / SocketService.js View on Github external
const trySocket = port => new Promise(socketResolver => {
		        const ssl = !(port % 2);
		        const hostname = getHostname(port, ssl);
		        const protocol = ssl ? 'wss://' : 'ws://';
		        const s = new WebSocket(`${protocol}${hostname}${suffix}`);

		        s.onerror = () => socketResolver(false);
		        s.onopen = () => socketResolver(s);
	        });
github filips123 / ZeroFrameJS / src / index.js View on Github external
async _getWebsocket () {
    const wsUrl = 'ws' + (this.instance.secure ? 's' : '') + '://' + this.instance.host + ':' + this.instance.port + '/Websocket?wrapper_key=' + this.wrapperKey
    let wsClient

    if (!this.multiuser.masterAddress) {
      wsClient = new WebSocket(wsUrl)
    } else {
      wsClient = new WebSocket(wsUrl, [], { headers: { Cookie: 'master_address=' + this.multiuser.masterAddress } })
    }

    wsClient.onmessage = this._onRequest.bind(this)
    wsClient.onopen = this._onOpenWebsocket.bind(this)
    wsClient.onerror = this._onErrorWebsocket.bind(this)
    wsClient.onclose = this._onCloseWebsocket.bind(this)

    return wsClient
  }
github cube-js / cube.js / packages / cubejs-client-ws-transport / src / index.js View on Github external
initSocket() {
    if (this.ws) {
      return this.ws.initPromise;
    }

    const ws = new WebSocket(this.apiUrl);

    ws.messageIdSent = {};

    ws.sendMessage = (message) => {
      if (!message.messageId || message.messageId && !ws.messageIdSent[message.messageId]) {
        ws.send(JSON.stringify(message));
        ws.messageIdSent[message.messageId] = true;
      }
    };

    ws.sendQueue = () => {
      this.messageQueue.forEach(message => ws.sendMessage(message));
      this.messageQueue = [];
    };

    ws.reconcile = () => {
github Cocos-BCX / cocosjs-core / packages / core / src / services / SocketService.js View on Github external
const trySocket = (resolver = null) => {
                    let promise;
                    if (!resolver) promise = new Promise(r => resolver = r);
                    const hostname = '127.0.0.1:50005';
                    const protocol = 'ws://';
                    const host = `${protocol}${hostname}${suffix}`;
                    const s = new WebSocket(host);
                    s.onerror = err => {
                        resolve(false);
                        resolver(false);
                    };
                    s.onopen = () => {
                        socket = s;
                        send();
                        clearTimeout(reconnectionTimeout);
                        connected = true;
                        pair(true).then(() => {
                            resolve(true);
                            resolver(true);
                        });
                        setupSocket();
                    };
                    return promise;

isomorphic-ws

Isomorphic implementation of WebSocket

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis