Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vscode-ws-jsonrpc

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vscode-ws-jsonrpc - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

lib/server/connection.d.ts

3

lib/connection.d.ts
import { MessageConnection, Logger } from 'vscode-jsonrpc';
export { MessageConnection, Logger };
import { IWebSocket } from './socket';
export declare function listen(options: {

@@ -8,1 +8,2 @@ webSocket: WebSocket;

}): void;
export declare function toSocket(webSocket: WebSocket): IWebSocket;

@@ -9,13 +9,4 @@ "use strict";

webSocket.onopen = function () {
var connection = socket_1.createSocketConnection({
send: function (content) { return webSocket.send(content); },
onMessage: function (cb) { return webSocket.onmessage = function (event) { return cb(event.data); }; },
onError: function (cb) { return webSocket.onerror = function (event) {
if (event instanceof ErrorEvent) {
cb(event.message);
}
}; },
onClose: function (cb) { return webSocket.onclose = function (event) { return cb(event.code, event.reason); }; },
dispose: function () { return webSocket.close(); }
}, logger);
var socket = toSocket(webSocket);
var connection = socket_1.createWebSocketConnection(socket, logger);
onConnection(connection);

@@ -25,1 +16,15 @@ };

exports.listen = listen;
function toSocket(webSocket) {
return {
send: function (content) { return webSocket.send(content); },
onMessage: function (cb) { return webSocket.onmessage = function (event) { return cb(event.data); }; },
onError: function (cb) { return webSocket.onerror = function (event) {
if (event instanceof ErrorEvent) {
cb(event.message);
}
}; },
onClose: function (cb) { return webSocket.onclose = function (event) { return cb(event.code, event.reason); }; },
dispose: function () { return webSocket.close(); }
};
}
exports.toSocket = toSocket;

@@ -0,1 +1,3 @@

export * from 'vscode-jsonrpc';
export * from 'vscode-jsonrpc/lib/messages';
export * from './disposable';

@@ -2,0 +4,0 @@ export * from './stream';

@@ -10,2 +10,4 @@ "use strict";

* ------------------------------------------------------------------------------------------ */
__export(require("vscode-jsonrpc"));
__export(require("vscode-jsonrpc/lib/messages"));
__export(require("./disposable"));

@@ -12,0 +14,0 @@ __export(require("./stream"));

import { MessageConnection, Logger } from "vscode-jsonrpc";
import { Socket } from "./socket";
export declare function createSocketConnection(socket: Socket, logger: Logger): MessageConnection;
import { IWebSocket } from "./socket";
export declare function createWebSocketConnection(socket: IWebSocket, logger: Logger): MessageConnection;

@@ -10,5 +10,5 @@ "use strict";

var writer_1 = require("./writer");
function createSocketConnection(socket, logger) {
var messageReader = new reader_1.SocketMessageReader(socket);
var messageWriter = new writer_1.SocketMessageWriter(socket);
function createWebSocketConnection(socket, logger) {
var messageReader = new reader_1.WebSocketMessageReader(socket);
var messageWriter = new writer_1.WebSocketMessageWriter(socket);
var connection = vscode_jsonrpc_1.createMessageConnection(messageReader, messageWriter, logger);

@@ -18,2 +18,2 @@ connection.onClose(function () { return connection.dispose(); });

}
exports.createSocketConnection = createSocketConnection;
exports.createWebSocketConnection = createWebSocketConnection;
import { DataCallback } from "vscode-jsonrpc/lib/messageReader";
import { AbstractStreamMessageReader } from "../stream";
import { Socket } from "./socket";
export declare class SocketMessageReader extends AbstractStreamMessageReader {
protected readonly socket: Socket;
constructor(socket: Socket);
import { IWebSocket } from "./socket";
export declare class WebSocketMessageReader extends AbstractStreamMessageReader {
protected readonly socket: IWebSocket;
constructor(socket: IWebSocket);
listen(callback: DataCallback): void;
}

@@ -14,5 +14,5 @@ "use strict";

var stream_1 = require("../stream");
var SocketMessageReader = (function (_super) {
__extends(SocketMessageReader, _super);
function SocketMessageReader(socket) {
var WebSocketMessageReader = (function (_super) {
__extends(WebSocketMessageReader, _super);
function WebSocketMessageReader(socket) {
var _this = _super.call(this) || this;

@@ -22,3 +22,3 @@ _this.socket = socket;

}
SocketMessageReader.prototype.listen = function (callback) {
WebSocketMessageReader.prototype.listen = function (callback) {
var _this = this;

@@ -38,4 +38,4 @@ this.socket.onMessage(function (data) { return _this.readMessage(data, callback); });

};
return SocketMessageReader;
return WebSocketMessageReader;
}(stream_1.AbstractStreamMessageReader));
exports.SocketMessageReader = SocketMessageReader;
exports.WebSocketMessageReader = WebSocketMessageReader;
import { Disposable } from "../disposable";
export interface Socket extends Disposable {
export interface IWebSocket extends Disposable {
send(content: string): void;

@@ -4,0 +4,0 @@ onMessage(cb: (data: any) => void): void;

import { AbstractStreamMessageWriter } from "../stream";
import { Socket } from "./socket";
export declare class SocketMessageWriter extends AbstractStreamMessageWriter {
protected readonly socket: Socket;
constructor(socket: Socket);
import { IWebSocket } from "./socket";
export declare class WebSocketMessageWriter extends AbstractStreamMessageWriter {
protected readonly socket: IWebSocket;
constructor(socket: IWebSocket);
protected send(content: string): void;
}

@@ -18,5 +18,5 @@ "use strict";

var stream_1 = require("../stream");
var SocketMessageWriter = (function (_super) {
__extends(SocketMessageWriter, _super);
function SocketMessageWriter(socket) {
var WebSocketMessageWriter = (function (_super) {
__extends(WebSocketMessageWriter, _super);
function WebSocketMessageWriter(socket) {
var _this = _super.call(this) || this;

@@ -26,3 +26,3 @@ _this.socket = socket;

}
SocketMessageWriter.prototype.send = function (content) {
WebSocketMessageWriter.prototype.send = function (content) {
try {

@@ -35,4 +35,4 @@ this.socket.send(content);

};
return SocketMessageWriter;
return WebSocketMessageWriter;
}(stream_1.AbstractStreamMessageWriter));
exports.SocketMessageWriter = SocketMessageWriter;
exports.WebSocketMessageWriter = WebSocketMessageWriter;
{
"name": "vscode-ws-jsonrpc",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"description": "VSCode JSON RPC over WebSocket",

@@ -5,0 +5,0 @@ "author": "TypeFox GmbH (http://www.typefox.io)",

# 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 (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)

@@ -6,9 +6,5 @@ /* --------------------------------------------------------------------------------------------

import { MessageConnection, Logger } from 'vscode-jsonrpc';
import { createSocketConnection } from './socket';
import { createWebSocketConnection, IWebSocket } from './socket';
import { ConsoleLogger } from './logger';
export {
MessageConnection, Logger
}
export function listen(options: {

@@ -22,15 +18,20 @@ webSocket: WebSocket;

webSocket.onopen = () => {
const connection = createSocketConnection({
send: content => webSocket.send(content),
onMessage: cb => webSocket.onmessage = event => cb(event.data),
onError: cb => webSocket.onerror = event => {
if (event instanceof ErrorEvent) {
cb(event.message)
}
},
onClose: cb => webSocket.onclose = event => cb(event.code, event.reason),
dispose: () => webSocket.close()
}, logger);
const socket = toSocket(webSocket);
const connection = createWebSocketConnection(socket, logger);
onConnection(connection);
};
}
export function toSocket(webSocket: WebSocket): IWebSocket {
return {
send: content => webSocket.send(content),
onMessage: cb => webSocket.onmessage = event => cb(event.data),
onError: cb => webSocket.onerror = event => {
if (event instanceof ErrorEvent) {
cb(event.message)
}
},
onClose: cb => webSocket.onclose = event => cb(event.code, event.reason),
dispose: () => webSocket.close()
}
}

@@ -5,2 +5,4 @@ /* --------------------------------------------------------------------------------------------

* ------------------------------------------------------------------------------------------ */
export * from 'vscode-jsonrpc';
export * from 'vscode-jsonrpc/lib/messages';
export * from './disposable';

@@ -7,0 +9,0 @@ export * from './stream';

@@ -6,9 +6,9 @@ /* --------------------------------------------------------------------------------------------

import { MessageConnection, createMessageConnection, Logger } from "vscode-jsonrpc";
import { Socket } from "./socket";
import { SocketMessageReader } from "./reader";
import { SocketMessageWriter } from "./writer";
import { IWebSocket } from "./socket";
import { WebSocketMessageReader } from "./reader";
import { WebSocketMessageWriter } from "./writer";
export function createSocketConnection(socket: Socket, logger: Logger): MessageConnection {
const messageReader = new SocketMessageReader(socket);
const messageWriter = new SocketMessageWriter(socket);
export function createWebSocketConnection(socket: IWebSocket, logger: Logger): MessageConnection {
const messageReader = new WebSocketMessageReader(socket);
const messageWriter = new WebSocketMessageWriter(socket);
const connection = createMessageConnection(messageReader, messageWriter, logger);

@@ -15,0 +15,0 @@ connection.onClose(() => connection.dispose());

@@ -7,7 +7,7 @@ /* --------------------------------------------------------------------------------------------

import { AbstractStreamMessageReader } from "../stream";
import { Socket } from "./socket";
import { IWebSocket } from "./socket";
export class SocketMessageReader extends AbstractStreamMessageReader {
export class WebSocketMessageReader extends AbstractStreamMessageReader {
constructor(protected readonly socket: Socket) {
constructor(protected readonly socket: IWebSocket) {
super();

@@ -14,0 +14,0 @@ }

@@ -7,3 +7,3 @@ /* --------------------------------------------------------------------------------------------

export interface Socket extends Disposable {
export interface IWebSocket extends Disposable {
send(content: string): void;

@@ -10,0 +10,0 @@ onMessage(cb: (data: any) => void): void;

@@ -6,7 +6,7 @@ /* --------------------------------------------------------------------------------------------

import { AbstractStreamMessageWriter } from "../stream";
import { Socket } from "./socket";
import { IWebSocket } from "./socket";
export class SocketMessageWriter extends AbstractStreamMessageWriter {
export class WebSocketMessageWriter extends AbstractStreamMessageWriter {
constructor(protected readonly socket: Socket) {
constructor(protected readonly socket: IWebSocket) {
super();

@@ -13,0 +13,0 @@ }

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc