0.1.0 • Published 8 months ago

@rfkit/json-rpc-websocket v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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),
});