Socket
Socket
Sign inDemoInstall

@codingame/monaco-jsonrpc

Package Overview
Dependencies
1
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @codingame/monaco-jsonrpc

VSCode JSON RPC over WebSocket


Version published
Weekly downloads
2.6K
decreased by-26.82%
Maintainers
6
Created
Weekly downloads
 

Readme

Source

:warning: @CodinGame/monaco-jsonrpc is deprecated.

Use 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

import * as rpc from 'monaco-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 'monaco-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 'monaco-jsonrpc';
import * as server from 'monaco-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

FAQs

Last updated on 21 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc