1.1.7 • Published 4 years ago
jsonrpc2websocket v1.1.7
jsonrpc2websocket
基于WebSocket+JSONRPC+msgpack+TypeScript封装的实时通讯函数
安装
$ npm install jsonrpc2websocket
# or
yarn add jsonrpc2websocket
使用
import Socket, { SocketType } from 'jsonrpc2websocket';
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);
},
});
stream.close();
// 接收所有消息
const socket: SocketType = new Socket({
url: 'ws://url',
onmessage: (res: Object) => console.log(res),
});