Browse Source

set protocol when connecting but this time for real

master
peter 4 years ago
parent
commit
c8dd780fdf
2 changed files with 8 additions and 2 deletions
  1. 1
    1
      package.json
  2. 7
    1
      src/Frontend.ts

+ 1
- 1
package.json View File

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

+ 7
- 1
src/Frontend.ts View File

16
         return await socket.connect(sesame)
16
         return await socket.connect(sesame)
17
     }
17
     }
18
 
18
 
19
+    private protocol: 'http:' | 'https:'
19
     private socket: I.Socket
20
     private socket: I.Socket
20
     private handlers : {
21
     private handlers : {
21
         [name in string]: T.AnyFunction[]
22
         [name in string]: T.AnyFunction[]
33
      */
34
      */
34
     constructor(public port:number, private server: string, private conf:T.SocketConf = { tls: false }){
35
     constructor(public port:number, private server: string, private conf:T.SocketConf = { tls: false }){
35
         Object.defineProperty(this, 'socket', {value: undefined, writable: true})
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
     public async connect( sesame?: string ) : Promise<T.ConnectedSocket<Ifc>> {
145
     public async connect( sesame?: string ) : Promise<T.ConnectedSocket<Ifc>> {
140
 
146
 
141
         try{
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
         }catch(e){
149
         }catch(e){
144
             this.handlers['error'].forEach(h => h(e))
150
             this.handlers['error'].forEach(h => h(e))
145
             throw e
151
             throw e

Loading…
Cancel
Save