New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@0xbeejs/requester

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xbeejs/requester

Promise based websocket client

0.0.2
latest
Version published
Weekly downloads
19
46.15%
Maintainers
1
Weekly downloads
 
Created

To communicate with a WebSocket service like an RPC call, avoiding the need to manually match requests and responses in callbacks

Install

$ npm install @0xbeejs/requester
$ yarn add @0xbeejs/requester

Usage

import Requester from "@0xbeejs/requester"

const requeter = new Requester("ws://<YOUR_ENDPOINT>")

interface ReconnectState {
  reconnectAttempts: number;
  requestQueue: number;
  responseQueue: number;
}

const pid = process.pid;
const requester = new Requester(`<endpoint>`, {
    reconnect: {
      auto: true,
      delay: 1000,
      onTimeout: true,
    },
  },
);

requester.currentProvider.on('connect', () => {
  console.log('Connection Established');
});

requester.currentProvider.on('close', () => {
  console.log('Connection Closed');
});

requester.currentProvider.on('reconnect', (data: ReconnectState) => {
  console.log(`Connection reconnect`);
});


async function start() {
    // Asynchronously send message through Websocket and asynchronously retrieve the result
    // The library internally establishes the correspondence between requests and responses
    const data = await requester.send({req: "tx.detail", arg: {txId: "<TX_ID>"}})
    return data
}

start()

FAQs

Package last updated on 17 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts