# @sourcegraph/vscode-ws-jsonrpc

> VSCode JSON RPC over WebSocket

Latest version **0.0.3-fork** (published 2018-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sourcegraph/vscode-ws-jsonrpc
pnpm add @sourcegraph/vscode-ws-jsonrpc
yarn add @sourcegraph/vscode-ws-jsonrpc
bun add @sourcegraph/vscode-ws-jsonrpc
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3-fork |
| Published | 2018-11-06 |
| First published | 2018-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 44.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | TypeFox GmbH |
| Maintainers | attfarhan, beyang, chrismwendt, dadlerj, felixfbecker, francisschmaltz, ggilmore, ijsnow, keegancsmith, kevinburke, kingthematt, nicksnyder, ryan.blunden, slimsag, sourcegraph-bot, sqs, vanesa- |

## Links

- npm: https://www.npmjs.com/package/@sourcegraph/vscode-ws-jsonrpc
- Repository: https://github.com/TypeFox/vscode-ws-jsonrpc
- Homepage: https://github.com/TypeFox/vscode-ws-jsonrpc#readme
- Issues: https://github.com/TypeFox/vscode-ws-jsonrpc/issues
- npm.io page: https://npm.io/package/@sourcegraph/vscode-ws-jsonrpc

## Dependencies (1)

- [vscode-jsonrpc](https://npm.io/package/vscode-jsonrpc.md) ^4.0.0

## Recent versions

- 0.0.3-fork (latest) — 2018-11-06

## README

# ⚠️ vscode-ws-jsonrpc is deprecated.

## Use [vscode-ws-jsonrpc](https://github.com/TypeFox/monaco-languageclient/tree/main/packages/vscode-ws-jsonrpc) instead

-----

## VSCode WebSocket JSON RPC

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

### Client side connection handling

```ts
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

```ts
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

```ts
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](https://github.com/TypeFox/vscode-ws-jsonrpc/blob/master/License.txt)

---
_Source: https://npm.io/package/@sourcegraph/vscode-ws-jsonrpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
