set protocol when connecting but this time for real

This commit is contained in:
2020-09-21 03:16:04 +02:00
parent 55ae61283c
commit c8dd780fdf
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -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": {
+7 -1
View File
@@ -16,6 +16,7 @@ export class RPCSocket<Ifc extends T.RPCInterface = T.RPCInterface> 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<Ifc extends T.RPCInterface = T.RPCInterface> 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<Ifc extends T.RPCInterface = T.RPCInterface> implements I
public async connect( sesame?: string ) : Promise<T.ConnectedSocket<Ifc>> {
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