Browse Source

fix bad rpc finding for class member

master
peter 4 years ago
parent
commit
fff118d9d2
3 changed files with 10 additions and 13 deletions
  1. 1
    1
      package.json
  2. 5
    5
      src/Backend.ts
  3. 4
    7
      src/Utils.ts

+ 1
- 1
package.json View File

1
 {
1
 {
2
   "name": "rpclibrary",
2
   "name": "rpclibrary",
3
-  "version": "1.6.2",
3
+  "version": "1.6.3",
4
   "description": "rpclibrary is a websocket on steroids!",
4
   "description": "rpclibrary is a websocket on steroids!",
5
   "main": "./js/Index.js",
5
   "main": "./js/Index.js",
6
   "repository": {
6
   "repository": {

+ 5
- 5
src/Backend.ts View File

53
             if(conf.connectionHandler) conf.connectionHandler(socket)
53
             if(conf.connectionHandler) conf.connectionHandler(socket)
54
         }
54
         }
55
 
55
 
56
-        let badRPC 
57
-        if(badRPC = exporters.flatMap(ex => ex.exportRPCs()).find(rpc => !rpc.name))
56
+        let badRPC = exporters.flatMap(ex => ex.exportRPCs()).find(rpc => !rpc.name)
57
+        if(badRPC)
58
         throw new Error(`
58
         throw new Error(`
59
             RPC did not provide a name. 
59
             RPC did not provide a name. 
60
             \nUse 'funtion name(..){ .. }' syntax instead.
60
             \nUse 'funtion name(..){ .. }' syntax instead.
69
         try{
69
         try{
70
             this.io.attach(this.ws)
70
             this.io.attach(this.ws)
71
             this.io.on('socket', (socket:I.Socket) => {
71
             this.io.on('socket', (socket:I.Socket) => {
72
-                socket.on('error', (err) => this.errorHandler(socket, err, "bind", []))
72
+                socket.on('error', (err) => this.errorHandler(socket, err, "system", []))
73
                 socket.on('close', () => this.closeHandler(socket))
73
                 socket.on('close', () => this.closeHandler(socket))
74
                 this.connectionHandler(socket)
74
                 this.connectionHandler(socket)
75
                 this.initRPCs(socket)
75
                 this.initRPCs(socket)
76
             })
76
             })
77
             this.ws.listen(this.port, this.visibility)
77
             this.ws.listen(this.port, this.visibility)
78
         }catch(e){
78
         }catch(e){
79
-            this.errorHandler(this.io, e, 'start', [])
79
+            this.errorHandler(this.io, e, 'system', [])
80
         }
80
         }
81
     }
81
     }
82
 
82
 
87
         ]
87
         ]
88
     }
88
     }
89
 
89
 
90
-    async destroy(): Promise<void> {
90
+    destroy(): void {
91
         this.io.close()
91
         this.io.close()
92
         this.ws.close()
92
         this.ws.close()
93
     }
93
     }

+ 4
- 7
src/Utils.ts View File

8
  * Translate an RPC to RPCInfo for serialization.
8
  * Translate an RPC to RPCInfo for serialization.
9
  * @param rpc The RPC to transform
9
  * @param rpc The RPC to transform
10
  * @param owner The owning RPC group's name
10
  * @param owner The owning RPC group's name
11
+ * @param errorHandler The error handler to invoke when  something goes wrong
12
+ * @param sesame optional sesame phrase to prepend before all RPC arguments 
11
  * @throws Error on RPC without name property
13
  * @throws Error on RPC without name property
12
  */
14
  */
13
 export const rpcToRpcinfo = <SubResT = {}>(socket: I.Socket, rpc : T.RPC<any, any, SubResT>, owner: string, errorHandler: T.ErrorHandler, sesame?:T.SesameFunction):T.RpcInfo => {
15
 export const rpcToRpcinfo = <SubResT = {}>(socket: I.Socket, rpc : T.RPC<any, any, SubResT>, owner: string, errorHandler: T.ErrorHandler, sesame?:T.SesameFunction):T.RpcInfo => {
66
         const suffix = makeUnique?"-"+uuidv4().substr(0,4):""
68
         const suffix = makeUnique?"-"+uuidv4().substr(0,4):""
67
         const ret:any = info
69
         const ret:any = info
68
         ret.uniqueName = info.name+suffix
70
         ret.uniqueName = info.name+suffix
69
-
70
-        let rpcFunction
71
-
72
-        if(info.type === 'Hook')
73
-            rpcFunction = info.generator(socket)
74
-        else
75
-            rpcFunction = info.call
71
+        let rpcFunction = info.type === 'Hook'? info.generator(socket)
72
+                                              : info.call
76
 
73
 
77
         socket.hook(ret.uniqueName, callGenerator(info.name, socket, rpcFunction, errorHandler))
74
         socket.hook(ret.uniqueName, callGenerator(info.name, socket, rpcFunction, errorHandler))
78
         return ret
75
         return ret

Loading…
Cancel
Save