How to use the rpc-websockets.Client function in rpc-websockets

To help you get started, we’ve selected a few rpc-websockets 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 radixdlt / radixdlt-js / src / modules / universe / RadixNodeConnection.ts View on Github external
return new Promise((resolve, reject) => {
            this.address = this.node.wsAddress

            // For testing atom queueing during connection issues
            // if (Math.random() > 0.1) {
            //    this.address += 'garbage'
            // }

            logger.info(`Connecting to ${this.address}`)

            this._socket = new Client(this.address, { reconnect: false })

            this._socket.on('close', this._onClosed)

            this._socket.on('error', error => {
                logger.error(error)
                reject(error)
            })

            setTimeout(() => {
                if (!this._socket.ready) {
                    logger.debug('Socket timeout')
                    this._socket.close()
                    this.emit('closed')
                    reject('Timeout')
                }
            }, 5000)
github loomnetwork / loom-js / src / loom-provider-2.ts View on Github external
constructor(public host: string, private ecdsaPrivateKey?: string) {
    // Simply create socket
    this._wsRPC = new WSClient(host)

    // If no privakey passed generate a random wallet
    this._wallet = ecdsaPrivateKey ? new Wallet(ecdsaPrivateKey) : Wallet.createRandom()

    // Emits new messages to the provider handler above (Web3)
    this._wsRPC.once('open', () => {
      ;((this._wsRPC as any).socket as EventEmitter).on(
        'message',
        this._onWebSocketMessage.bind(this)
      )
      ;((this._wsRPC as any).socket as WebSocket).onclose = () => {
        this.reset()
      }
    })

    // Prepare LoomProvider2 default methods
github truongsinh / appium-flutter-driver / driver / lib / sessions / observatory.ts View on Github external
const connectedPromise = new Promise((resolve) => {
      log.info(
        `Connecting to Dart Observatory: ${dartObservatoryURL}`,
      );

      const socket = new Client(dartObservatoryURL);

      const removeListenerAndResolve = (r: NullableWebSocketDummy) => {
        socket.removeListener(`error`, onErrorListener);
        socket.removeListener(`timeout`, onTimeoutListener);
        socket.removeListener(`open`, onOpenListener);
        resolve(r);
      };

      // Add an 'error' event handler for the client socket
      const onErrorListener = (ex) => {
        log.error(ex);
        log.error(
          `Check Dart Observatory URI ${dartObservatoryURL}`,
        );
        removeListenerAndResolve(null);
      };
github radixdlt / radixdlt-js / src / modules / identity / RadixRemoteIdentity.ts View on Github external
return new Promise((resolve, reject) => {
            // This is an independant websocket because 'getRemotePublicKey' is a static method
            const socket = new Client(`ws://${host}:${port}`)
            
            socket.on('open', () => {
                socket.call('get_public_key', { 
                    token,
                }).then((response) => {
                    resolve(response.data)
                }).catch((error) => {
                    reject(error)
                }).finally(() => {
                    socket.close()
                })
            })
        })
    }
github AraiEzzra / DDKCORE / api / rpc / client.js View on Github external
const WebSocket = require('rpc-websockets').Client;
const URL = 'ws://0.0.0.0:8080/v1';
const ws = new WebSocket(URL);



ws.on('open', function () {

  ws.call('getblocks', {limit: 10, offset: '0'})
    .then(function(result) {
      console.log('getblocks:', result);
    });

  ws.close();

});
github radixdlt / radixdlt-js / src / modules / identity / RadixRemoteIdentity.ts View on Github external
private getSocketConnection(): Client {
        this.socket = new Client(this.remoteUrl)

        this.socket.on('error', (error) => logger.error(error))
        this.socket.on('close', () => logger.info('Socket closed'))

        return this.socket
    }
github radixdlt / radixdlt-js / src / modules / identity / RadixRemoteIdentity.ts View on Github external
return new Promise((resolve, reject) => {
            const socket = new Client(`ws://${host}:${port}`)
            
            socket.on('open', () => resolve(true))

            setTimeout(() => {
                if (socket && socket.ready) {
                    socket.close()
                    resolve(true)
                } else {
                    socket.close()
                    resolve(false)
                }
            }, 2000)
        })
    }
github filecoin-project / lotus / lotuspond / front / src / NodeIndex.js View on Github external
connTo = async (n, node) => {
        const client = new Client(`${node.addr}?token=${node.token}`)
        client.on('open', async () => {
            this.setState(p => ({conns: {...p.conns, [n]: client}}))
            setInterval(() => this.updateInfo(n), 1333)
        })
    }
github loomnetwork / loom-js / client.js View on Github external
constructor(nodeUrl, proxyUrl) {
    this.nodeUrl = nodeUrl;
    this.proxyUrl = proxyUrl;
    this.rpcId = 0;
    this.openPromise = null;
    this.rpcClient = new RPCClient(nodeUrl, {
      autoconnect: true,
      reconnect: true,
      reconnect_interval: 1000,
      max_reconnects: 5,
    }, this._nextRequestId.bind(this));
  }
github filecoin-project / lotus / lotuspond / front / src / NodeList.js View on Github external
async mountNode(node) {
    const token = await this.props.client.call('Pond.TokenFor', [node.ID])

    const client = new Client(`ws://127.0.0.1:${node.APIPort}/rpc/v0?token=${token}`)
    client.on('open', async () => {
      const id = await client.call("Filecoin.ID", [])

      this.setState(prev => ({
        nodes: {
          ...prev.nodes,
          [node.ID]: {...node, conn: client, peerid: id}
        }
      }))

      if (!node.Storage) {
        this.props.mountWindow((onClose) =>

rpc-websockets

JSON-RPC 2.0 implementation over WebSockets for Node.js

LGPL-3.0-only
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis

Popular rpc-websockets functions