import { RPCServer } from "../src/Backend"; import { SubscriptionResponse, RPCInterface } from "../src/Types"; import { RPCSocket } from "../src/Frontend"; import { makeSubResponse } from "../src/Utils"; type SubresExtension = {a:string} type MyInterface = { Group1: { triggerCallbacks: (...args:any[]) => Promise, subscribe: (param:string, callback:Function) => Promise>, unsubscribe: (uuid:string) => Promise }, Group2: { echo: (x:string) => Promise } } new RPCServer(20000, [{ name: 'Group1', exportRPCs: () => [{ name: 'triggerCallbacks', call: async () => { /*...*/ } },{ name: 'subscribe', hook: async (param, callback) => { return makeSubResponse({a: "test"}) } },{ name: 'unsubscribe', call: async(uuid) => { } } ] },{ name: 'Group2', exportRPCs: () => [{ name: 'echo', call: async (x) => "..." }] }] ) RPCSocket.makeSocket(20000, 'localhost').then((async (client) => { console.log(client) const res = await client.Group1.subscribe('test', async (...args:any) => { console.log.apply(console, args) /* close the callbacks once you're done */ await client.Group1.unsubscribe(res.uuid) client.unhook(res.uuid) }) await client.Group1.triggerCallbacks("Hello", "World", "Callbacks") }))