Before PioSocket dropin replacement
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { RPCServer, RPCSocket } from './Index'
|
import { RPCServer, RPCSocket } from './Index'
|
||||||
import { RPCExporter } from './src/Interfaces'
|
import { RPCExporter } from './src/Interfaces'
|
||||||
|
import { RPCInterface } from './src/Types'
|
||||||
|
|
||||||
// TL;DR
|
// TL;DR
|
||||||
const echo = (text: string) => text
|
const echo = (text: string) => text
|
||||||
@@ -175,17 +176,16 @@ interface IMyImplementation {
|
|||||||
getCallback: (callback:Function) => string
|
getCallback: (callback:Function) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
type MyIfc = {
|
type IfcGenerator<Name extends string, Interface, keys extends keyof Interface = keyof Interface> = {
|
||||||
MyRPCGroup1: {
|
[name in Name]: {
|
||||||
echo: IMyImplementation['echo']
|
[key in keys] : Interface[key]
|
||||||
add: IMyImplementation['add']
|
|
||||||
getAsync: IMyImplementation['getAsync']
|
|
||||||
getCallback: IMyImplementation['getCallback']
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MyIfc = IfcGenerator<"MyRPCGroup1", IMyImplementation>
|
||||||
|
|
||||||
class MyImplementation implements IMyImplementation, RPCExporter<MyIfc>{
|
class MyImplementation implements IMyImplementation, RPCExporter<MyIfc>{
|
||||||
//"X" as "X" syntax is required to satisfy the type system (as it assumed string)
|
//"X" as "X" syntax is required to satisfy the type system (as it assumes string)
|
||||||
name = "MyRpcGroup11" as "MyRPCGroup1"
|
name = "MyRpcGroup11" as "MyRPCGroup1"
|
||||||
|
|
||||||
//List the functions you declared in MyIfc
|
//List the functions you declared in MyIfc
|
||||||
|
|||||||
+2
-1
@@ -38,7 +38,8 @@ function makeServer() {
|
|||||||
function triggerCallback(...messages: any[]): number { return subcallback.apply({}, messages) },
|
function triggerCallback(...messages: any[]): number { return subcallback.apply({}, messages) },
|
||||||
]
|
]
|
||||||
}], {
|
}], {
|
||||||
connectionHandler: (socket) => { },
|
connectionHandler: (socket) => {
|
||||||
|
},
|
||||||
closeHandler: (socket) => { },
|
closeHandler: (socket) => { },
|
||||||
errorHandler: (socket, err) => { throw err }
|
errorHandler: (socket, err) => { throw err }
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user