@gedit/connection
Advanced tools
Comparing version
@@ -21,3 +21,5 @@ /******************************************************************************** | ||
import { WebSocketChannel } from '../common/messaging/web-socket-channel'; | ||
import { Endpoint } from '@gedit/utils/lib/browser'; | ||
import ReconnectingWebSocket from 'reconnecting-websocket'; | ||
export declare const WebSocketOptions: unique symbol; | ||
export interface WebSocketOptions { | ||
@@ -28,4 +30,9 @@ /** | ||
reconnecting?: boolean; | ||
/** | ||
* Location for end point | ||
*/ | ||
location?: Endpoint.Location; | ||
} | ||
export declare class WebSocketConnectionProvider implements IConnectionProvider { | ||
protected readonly defaultOptions?: WebSocketOptions | undefined; | ||
protected channelIdSeq: number; | ||
@@ -36,3 +43,3 @@ protected readonly socket: ReconnectingWebSocket; | ||
onIncomingMessageActivity: Event<void>; | ||
constructor(); | ||
constructor(defaultOptions?: WebSocketOptions | undefined); | ||
/** | ||
@@ -68,3 +75,3 @@ * Create a proxy object to remote interface of T type | ||
listen(handler: ConnectionHandler, options?: WebSocketOptions): void; | ||
openChannel(path: string, handler: (channel: WebSocketChannel) => void, options?: WebSocketOptions): void; | ||
openChannel(path: string, handler: (channel: WebSocketChannel) => void, options?: WebSocketOptions | undefined): void; | ||
protected doOpenChannel(path: string, handler: (channel: WebSocketChannel) => void, options?: WebSocketOptions): void; | ||
@@ -71,0 +78,0 @@ protected createChannel(id: number): WebSocketChannel; |
@@ -37,2 +37,5 @@ "use strict"; | ||
}; | ||
var __param = (this && this.__param) || function (paramIndex, decorator) { | ||
return function (target, key) { decorator(target, key, paramIndex); } | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -70,3 +73,3 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WebSocketConnectionProvider = void 0; | ||
exports.WebSocketConnectionProvider = exports.WebSocketOptions = void 0; | ||
var inversify_1 = require("inversify"); | ||
@@ -81,5 +84,7 @@ var lib_1 = require("vscode-ws-jsonrpc/lib"); | ||
inversify_1.decorate(inversify_1.unmanaged(), common_1.JsonRpcProxyFactory, 0); | ||
exports.WebSocketOptions = Symbol('WebSocketOptions'); | ||
var WebSocketConnectionProvider = /** @class */ (function () { | ||
function WebSocketConnectionProvider() { | ||
function WebSocketConnectionProvider(defaultOptions) { | ||
var _this = this; | ||
this.defaultOptions = defaultOptions; | ||
this.channelIdSeq = 0; | ||
@@ -148,2 +153,3 @@ this.channels = new Map(); | ||
var _this = this; | ||
if (options === void 0) { options = this.defaultOptions; } | ||
if (this.socket.readyState === WebSocket.OPEN) { | ||
@@ -194,3 +200,4 @@ this.doOpenChannel(path, handler, options); | ||
WebSocketConnectionProvider.prototype.createWebSocketUrl = function (path) { | ||
var endpoint = new browser_1.Endpoint({ path: path }); | ||
var _a; | ||
var endpoint = new browser_1.Endpoint({ path: path }, (_a = this.defaultOptions) === null || _a === void 0 ? void 0 : _a.location); | ||
return endpoint.getWebSocketUrl().toString(); | ||
@@ -214,3 +221,4 @@ }; | ||
inversify_1.injectable(), | ||
__metadata("design:paramtypes", []) | ||
__param(0, inversify_1.inject(exports.WebSocketOptions)), __param(0, inversify_1.optional()), | ||
__metadata("design:paramtypes", [Object]) | ||
], WebSocketConnectionProvider); | ||
@@ -217,0 +225,0 @@ return WebSocketConnectionProvider; |
{ | ||
"name": "@gedit/connection", | ||
"version": "0.1.30", | ||
"version": "0.1.31", | ||
"license": "MIT", | ||
@@ -12,4 +12,4 @@ "main": "lib/common/index", | ||
"dependencies": { | ||
"@gedit/application-common": "^0.1.30", | ||
"@gedit/utils": "^0.1.30", | ||
"@gedit/application-common": "^0.1.31", | ||
"@gedit/utils": "^0.1.31", | ||
"@types/lodash.throttle": "^4.1.3", | ||
@@ -36,3 +36,3 @@ "lodash.throttle": "^4.1.1", | ||
}, | ||
"gitHead": "ab0cd05649af3aaf89ff271982896bbda38f8634" | ||
"gitHead": "12d3eec48b48c60a7f56c6d4dabe5e94e087b7c9" | ||
} |
@@ -17,3 +17,3 @@ /******************************************************************************** | ||
import { decorate, injectable, interfaces, unmanaged } from 'inversify'; | ||
import { decorate, injectable, inject, interfaces, unmanaged, optional } from 'inversify'; | ||
import { ConsoleLogger, createWebSocketConnection, Logger } from 'vscode-ws-jsonrpc/lib'; | ||
@@ -29,2 +29,3 @@ import { Emitter, Event } from '@gedit/utils'; | ||
export const WebSocketOptions = Symbol('WebSocketOptions'); | ||
export interface WebSocketOptions { | ||
@@ -35,2 +36,6 @@ /** | ||
reconnecting?: boolean; | ||
/** | ||
* Location for end point | ||
*/ | ||
location?: Endpoint.Location | ||
} | ||
@@ -47,3 +52,5 @@ | ||
constructor() { | ||
constructor( | ||
@inject(WebSocketOptions) @optional() protected readonly defaultOptions?: WebSocketOptions | ||
) { | ||
const url = this.createWebSocketUrl(WebSocketChannel.wsPath); | ||
@@ -122,3 +129,3 @@ const socket = this.createWebSocket(url); | ||
openChannel(path: string, handler: (channel: WebSocketChannel) => void, options?: WebSocketOptions): void { | ||
openChannel(path: string, handler: (channel: WebSocketChannel) => void, options: WebSocketOptions | undefined = this.defaultOptions): void { | ||
if (this.socket.readyState === WebSocket.OPEN) { | ||
@@ -169,3 +176,3 @@ this.doOpenChannel(path, handler, options); | ||
protected createWebSocketUrl(path: string): string { | ||
const endpoint = new Endpoint({path}); | ||
const endpoint = new Endpoint({path}, this.defaultOptions?.location); | ||
return endpoint.getWebSocketUrl().toString(); | ||
@@ -172,0 +179,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
168462
0.97%2980
0.74%Updated