diff --git a/README.md b/README.md index 994cb5d..703b4a8 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ client.connect().then(async () => { rpclibrary offers a special type of call that can be used with callbacks. The callback **has to be the last argument** and **may be the only passed function**. -In order to function, some metadata has to be included in the return value of hooks. On success, the function is expected to return a `type SubscriptionResponse = { result: 'Success', uuid: string }` or in case of errors a `type ErrorResponse = { result: 'Error' }`. +In order to function, some metadata has to be included in the return value of hooks. On success, the function is expected to return a `{ result: 'Success', uuid: string }` (Types.SubscriptionResponse) or in case of errors a `{ result: 'Error' }`(Types.ErrorResponse). The uuid, as the name implies, is used to uniquely identify the callback for a given invocation and also dictates the name given to the client-side RPC. Unless you got a preferred way of generating these (e.g. using some kind of unique information important to your task) we recommend [uuid](https://www.npmjs.com/package/uuid) for this purpose. @@ -58,9 +58,9 @@ const server = new Backend.RPCServer(port, [{ { name: 'subscribe', hook: async (callback) => { - const resp:SubscriptionResponse = { result: 'Success', uuid: 'generate_a_random_string_here' } - callbacks.set(resp.uuid, callback); - return resp + const randStr = 'generate_a_random_string_here' + callbacks.set(randStr, callback); + return { result: 'Success', uuid: randStr} } },{ name: 'unsubscribe', diff --git a/package.json b/package.json index 7c68a51..2d243e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rpclibrary", - "version": "1.2.4", + "version": "1.2.5", "description": "rpclibrary is a websocket on steroids!", "main": "./js/Index.js", "repository": { diff --git a/test/Test.ts b/test/Test.ts index 6526251..f5066a0 100644 --- a/test/Test.ts +++ b/test/Test.ts @@ -66,7 +66,9 @@ describe('RPCServer', () => { }) it('should be able to use all kinds of RPC definitions', (done) => { + const echo = (x) => x + const server = new RPCServer(20003, [{ name: 'HelloWorldRPCGroup', exportRPCs: () => [