Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@rfkit/json-rpc-websocket

hxgh74MIT0.1.0TypeScript support: included

A lightweight JSON-RPC 2.0 client implementation over WebSocket, supporting request-response, notifications, and batch processing

json-rpc, websocket, rpc, client, remote-procedure-call, typescript, real-time, communication, async

readme

json-rpc-websocket

基于WebSocket+JSONRPC+msgpack+TypeScript封装的实时通讯函数

安装

pnpm add json-rpc-websocket

使用

import Socket, { SocketType } from 'json-rpc-websocket';

const socket: SocketType = new Socket({ url: 'ws://url' });

// 普通模式
socket.send({
    method: 'msg',
    callback: e => {
      console.log(e);
    },
});

// 流模式
const stream = socket.stream({
    method: 'start',
    callback: e => {
      console.log(e);
    },
    onerror: e => {
      console.log('处理超时 || 处理send无法启动');
    },
});
stream.close();

// 接收所有消息
const socket = new Socket({
  url: 'ws://url',
  onmessage: (res: Object) => console.log(res),
});