JSPM

@rfkit/json-rpc-websocket

0.1.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 70
    • Score
      100M100P100Q83023F
    • License MIT

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

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