3.3.1 • Published 23 days ago

vscode-ws-jsonrpc v3.3.1

Weekly downloads
15,452
License
MIT
Repository
github
Last release
23 days ago

VSCode WebSocket JSON RPC

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

CHANGELOG

All changes are noted in the CHANGELOG.

Getting Started

This is npm package is part of the https://github.com/TypeFox/monaco-languageclient mono repo. Please follow the main repositories instructions](https://github.com/TypeFox/monaco-languageclient#getting-started) to get started with local development.

Usage

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

Examples

For a detailed list of examples please look at this section in the main repository.

License

MIT

3.3.1

23 days ago

3.3.0

2 months ago

3.3.0-next.6

2 months ago

3.3.0-next.5

2 months ago

3.3.0-next.2

2 months ago

3.3.0-next.3

2 months ago

3.3.0-next.4

2 months ago

3.3.0-next.0

2 months ago

3.2.0

2 months ago

3.1.0-next.1

6 months ago

3.1.0-next.0

6 months ago

3.1.0

6 months ago

3.0.0-next.1

1 year ago

3.0.0-next.0

1 year ago

2.0.2

1 year ago

3.0.0

1 year ago

2.0.1

1 year ago

1.1.0-next.1

2 years ago

1.1.0-next.0

2 years ago

2.0.0-next.0

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.5.0-dev.0

2 years ago

1.0.1-dev.0

2 years ago

0.2.0

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.3

6 years ago

0.0.2-2

6 years ago

0.0.2-1

6 years ago

0.0.2-0

6 years ago

0.0.1-alpha.5

7 years ago

0.0.1-alpha.4

7 years ago

0.0.1-alpha.3

7 years ago

0.0.1-alpha.2

7 years ago

0.0.1-alpha.1

7 years ago

0.0.1-alpha.0

7 years ago