Package Exports
- @rfkit/json-rpc-websocket
- @rfkit/json-rpc-websocket/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rfkit/json-rpc-websocket) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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),
});