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,6 +1,6 @@
1 1
 {
2 2
   "name": "rpclibrary",
3
-  "version": "1.6.2",
3
+  "version": "1.6.3",
4 4
   "description": "rpclibrary is a websocket on steroids!",
5 5
   "main": "./js/Index.js",
6 6
   "repository": {

+ 5
- 5
src/Backend.ts View File

@@ -53,8 +53,8 @@ export class RPCServer<
53 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 58
         throw new Error(`
59 59
             RPC did not provide a name. 
60 60
             \nUse 'funtion name(..){ .. }' syntax instead.
@@ -69,14 +69,14 @@ export class RPCServer<
69 69
         try{
70 70
             this.io.attach(this.ws)
71 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 73
                 socket.on('close', () => this.closeHandler(socket))
74 74
                 this.connectionHandler(socket)
75 75
                 this.initRPCs(socket)
76 76
             })
77 77
             this.ws.listen(this.port, this.visibility)
78 78
         }catch(e){
79
-            this.errorHandler(this.io, e, 'start', [])
79
+            this.errorHandler(this.io, e, 'system', [])
80 80
         }
81 81
     }
82 82
 
@@ -87,7 +87,7 @@ export class RPCServer<
87 87
         ]
88 88
     }
89 89
 
90
-    async destroy(): Promise<void> {
90
+    destroy(): void {
91 91
         this.io.close()
92 92
         this.ws.close()
93 93
     }

+ 4
- 7
src/Utils.ts View File

@@ -8,6 +8,8 @@ import { SubscriptionResponse } from "./Types";
8 8
  * Translate an RPC to RPCInfo for serialization.
9 9
  * @param rpc The RPC to transform
10 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 13
  * @throws Error on RPC without name property
12 14
  */
13 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,13 +68,8 @@ export function rpcHooker<SubResT = {}>(socket: I.Socket, exporter:I.RPCExporter
66 68
         const suffix = makeUnique?"-"+uuidv4().substr(0,4):""
67 69
         const ret:any = info
68 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 74
         socket.hook(ret.uniqueName, callGenerator(info.name, socket, rpcFunction, errorHandler))
78 75
         return ret

Loading…
Cancel
Save