fix bad rpc finding for class member

This commit is contained in:
2020-02-01 11:08:48 +01:00
parent fa45dc6b4f
commit fff118d9d2
3 changed files with 10 additions and 13 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "rpclibrary", "name": "rpclibrary",
"version": "1.6.2", "version": "1.6.3",
"description": "rpclibrary is a websocket on steroids!", "description": "rpclibrary is a websocket on steroids!",
"main": "./js/Index.js", "main": "./js/Index.js",
"repository": { "repository": {
+5 -5
View File
@@ -53,8 +53,8 @@ export class RPCServer<
if(conf.connectionHandler) conf.connectionHandler(socket) if(conf.connectionHandler) conf.connectionHandler(socket)
} }
let badRPC let badRPC = exporters.flatMap(ex => ex.exportRPCs()).find(rpc => !rpc.name)
if(badRPC = exporters.flatMap(ex => ex.exportRPCs()).find(rpc => !rpc.name)) if(badRPC)
throw new Error(` throw new Error(`
RPC did not provide a name. RPC did not provide a name.
\nUse 'funtion name(..){ .. }' syntax instead. \nUse 'funtion name(..){ .. }' syntax instead.
@@ -69,14 +69,14 @@ export class RPCServer<
try{ try{
this.io.attach(this.ws) this.io.attach(this.ws)
this.io.on('socket', (socket:I.Socket) => { this.io.on('socket', (socket:I.Socket) => {
socket.on('error', (err) => this.errorHandler(socket, err, "bind", [])) socket.on('error', (err) => this.errorHandler(socket, err, "system", []))
socket.on('close', () => this.closeHandler(socket)) socket.on('close', () => this.closeHandler(socket))
this.connectionHandler(socket) this.connectionHandler(socket)
this.initRPCs(socket) this.initRPCs(socket)
}) })
this.ws.listen(this.port, this.visibility) this.ws.listen(this.port, this.visibility)
}catch(e){ }catch(e){
this.errorHandler(this.io, e, 'start', []) this.errorHandler(this.io, e, 'system', [])
} }
} }
@@ -87,7 +87,7 @@ export class RPCServer<
] ]
} }
async destroy(): Promise<void> { destroy(): void {
this.io.close() this.io.close()
this.ws.close() this.ws.close()
} }
+4 -7
View File
@@ -8,6 +8,8 @@ import { SubscriptionResponse } from "./Types";
* Translate an RPC to RPCInfo for serialization. * Translate an RPC to RPCInfo for serialization.
* @param rpc The RPC to transform * @param rpc The RPC to transform
* @param owner The owning RPC group's name * @param owner The owning RPC group's name
* @param errorHandler The error handler to invoke when something goes wrong
* @param sesame optional sesame phrase to prepend before all RPC arguments
* @throws Error on RPC without name property * @throws Error on RPC without name property
*/ */
export const rpcToRpcinfo = <SubResT = {}>(socket: I.Socket, rpc : T.RPC<any, any, SubResT>, owner: string, errorHandler: T.ErrorHandler, sesame?:T.SesameFunction):T.RpcInfo => { 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
const suffix = makeUnique?"-"+uuidv4().substr(0,4):"" const suffix = makeUnique?"-"+uuidv4().substr(0,4):""
const ret:any = info const ret:any = info
ret.uniqueName = info.name+suffix ret.uniqueName = info.name+suffix
let rpcFunction = info.type === 'Hook'? info.generator(socket)
let rpcFunction : info.call
if(info.type === 'Hook')
rpcFunction = info.generator(socket)
else
rpcFunction = info.call
socket.hook(ret.uniqueName, callGenerator(info.name, socket, rpcFunction, errorHandler)) socket.hook(ret.uniqueName, callGenerator(info.name, socket, rpcFunction, errorHandler))
return ret return ret