From c8dd780fdfc05c13d4fe878c6fa02782135a46fe Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 21 Sep 2020 03:16:04 +0200 Subject: [PATCH] set protocol when connecting but this time for real --- package.json | 2 +- src/Frontend.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d5132a4..5a5baed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rpclibrary", - "version": "2.1.1", + "version": "2.1.2", "description": "rpclibrary is a websocket RPC library", "main": "./js/Index.js", "repository": { diff --git a/src/Frontend.ts b/src/Frontend.ts index 1686973..b6665d2 100644 --- a/src/Frontend.ts +++ b/src/Frontend.ts @@ -16,6 +16,7 @@ export class RPCSocket implements I return await socket.connect(sesame) } + private protocol: 'http:' | 'https:' private socket: I.Socket private handlers : { [name in string]: T.AnyFunction[] @@ -33,6 +34,11 @@ export class RPCSocket implements I */ constructor(public port:number, private server: string, private conf:T.SocketConf = { tls: false }){ Object.defineProperty(this, 'socket', {value: undefined, writable: true}) + if(conf.tls){ + this.protocol = "https:" + }else{ + this.protocol = "http:" + } } /** @@ -139,7 +145,7 @@ export class RPCSocket implements I public async connect( sesame?: string ) : Promise> { try{ - this.socket = await PromiseIOClient.connect(this.port, this.server, /*this.conf.tls?this.conf.tls:false*/) + this.socket = await PromiseIOClient.connect(this.port, this.server, this.protocol) }catch(e){ this.handlers['error'].forEach(h => h(e)) throw e