vscode-ws-jsonrpc
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.2 • Public • Published

    VSCode WebSocket JSON RPC

    NPM module to implement communication between a jsonrpc client and server over WebSocket.

    See the following example code how to use this library or take a look of the monaco-languageclient and vscode-ws-jsonrpc examples here:

    Client side connection handling

    import { MessageConnection, NotificationType } from 'vscode-jsonrpc';
    import { listen } from 'vscode-ws-jsonrpc';
    
    const webSocket = new WebSocket('ws://www.example.com/socketserver');
    listen({
        webSocket,
        onConnection: (connection: MessageConnection) => {
            const notification = new rpc.NotificationType<string, void>('testNotification');
            connection.listen();
            connection.sendNotification(notification, 'Hello World');
        }
    });

    Server side connection handling

    import { createWebSocketConnection, ConsoleLogger, IWebSocket } from 'vscode-ws-jsonrpc';
    import { NotificationType } from 'vscode-languageserver';
    
    const socket: IWebSocket; // open the web socket
    const logger = new ConsoleLogger();
    const connection = createWebSocketConnection(socket, logger);
    const notification = new NotificationType<string, void>('testNotification');
    connection.onNotification(notification, (param: string) => {
      console.log(param); // This prints Hello World
    });
    
    connection.listen();

    Server side connection forwarding

    import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';
    import { createConnection, createServerProcess, forward } from 'vscode-ws-jsonrpc/server';
    import { Message } from 'vscode-languageserver';
    
    const socket: IWebSocket; // open the web socket
    const reader = new WebSocketMessageReader(socket);
    const writer = new WebSocketMessageWriter(socket);
    const socketConnection = createConnection(reader, writer, () => socket.dispose())
    const serverConnection = createServerProcess('Example', 'node', ['example.js']);
    forward(socketConnection, serverConnection, message => {
        if (Message.isNotification(message)) {
            if (message.method === 'testNotification') {
                // handle the test notification
            }
        }
        return message;
    });

    License

    MIT

    Keywords

    none

    Install

    npm i vscode-ws-jsonrpc

    DownloadsWeekly Downloads

    19,146

    Version

    2.0.2

    License

    MIT

    Unpacked Size

    57.9 kB

    Total Files

    64

    Last publish

    Collaborators

    • spoenemann
    • kaisalmen
    • typefox-team