vscode-ws-jsonrpc
VSCode JSON RPC over WebSocket
Last updated 4 months ago by typefox-team .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vscode-ws-jsonrpc 
SYNC missed versions from official npm registry.

VSCode WebSocket JSON RPC

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

Client side connection handling

import * as rpc from 'vscode-ws-jsonrpc';

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

Server side connection handling

import * as rpc from 'vscode-ws-jsonrpc';

const socket: rpc.IWebSocket; // open the web socket
const reader = new rpc.WebSocketMessageReader(socket);
const writer = new rpc.WebSocketMessageWriter(socket);
const logger = new rpc.ConsoleLogger();
const connection = rpc.createMessageConnection(reader, writer, logger);
const notification = new rpc.NotificationType<string, void>('testNotification');
connection.onNotification(notification, (param: string) => {
	console.log(param); // This prints Hello World
});

connection.listen();

Server side connection forwarding

import * as rpc from 'vscode-ws-jsonrpc';
import * as server from 'vscode-ws-jsonrpc/lib/server';

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

License

MIT

Current Tags

  • 0.1.1                                ...           es6 (4 months ago)
  • 0.1.1                                ...           latest (4 months ago)
  • 0.0.2-2                                ...           next (2 years ago)

12 Versions

  • 0.1.1                                ...           4 months ago
  • 0.1.0                                ...           4 months ago
  • 0.0.3                                ...           a year ago
  • 0.0.2-2                                ...           2 years ago
  • 0.0.2-1                                ...           2 years ago
  • 0.0.2-0                                ...           2 years ago
  • 0.0.1-alpha.5                                ...           2 years ago
  • 0.0.1-alpha.4                                ...           3 years ago
  • 0.0.1-alpha.3                                ...           3 years ago
  • 0.0.1-alpha.2                                ...           3 years ago
  • 0.0.1-alpha.1                                ...           3 years ago
  • 0.0.1-alpha.0                                ...           3 years ago

Copyright 2014 - 2016 © taobao.org |