Pārlūkot izejas kodu

set protocol when connecting but this time for real

master
peter 4 gadus atpakaļ
vecāks
revīzija
c8dd780fdf
2 mainītis faili ar 8 papildinājumiem un 2 dzēšanām
  1. 1
    1
      package.json
  2. 7
    1
      src/Frontend.ts

+ 1
- 1
package.json Parādīt failu

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "rpclibrary",
3
-  "version": "2.1.1",
3
+  "version": "2.1.2",
4 4
   "description": "rpclibrary is a websocket RPC library",
5 5
   "main": "./js/Index.js",
6 6
   "repository": {

+ 7
- 1
src/Frontend.ts Parādīt failu

@@ -16,6 +16,7 @@ export class RPCSocket<Ifc extends T.RPCInterface = T.RPCInterface> implements I
16 16
         return await socket.connect(sesame)
17 17
     }
18 18
 
19
+    private protocol: 'http:' | 'https:'
19 20
     private socket: I.Socket
20 21
     private handlers : {
21 22
         [name in string]: T.AnyFunction[]
@@ -33,6 +34,11 @@ export class RPCSocket<Ifc extends T.RPCInterface = T.RPCInterface> implements I
33 34
      */
34 35
     constructor(public port:number, private server: string, private conf:T.SocketConf = { tls: false }){
35 36
         Object.defineProperty(this, 'socket', {value: undefined, writable: true})
37
+        if(conf.tls){
38
+            this.protocol = "https:"
39
+        }else{
40
+            this.protocol = "http:"
41
+        }
36 42
     }
37 43
 
38 44
     /**
@@ -139,7 +145,7 @@ export class RPCSocket<Ifc extends T.RPCInterface = T.RPCInterface> implements I
139 145
     public async connect( sesame?: string ) : Promise<T.ConnectedSocket<Ifc>> {
140 146
 
141 147
         try{
142
-            this.socket = await PromiseIOClient.connect(this.port, this.server, /*this.conf.tls?this.conf.tls:false*/)
148
+            this.socket = await PromiseIOClient.connect(this.port, this.server, this.protocol)
143 149
         }catch(e){
144 150
             this.handlers['error'].forEach(h => h(e))
145 151
             throw e

Notiek ielāde…
Atcelt
Saglabāt