|
@@ -40,7 +40,7 @@ client.connect().then(async () => {
|
40
|
40
|
|
41
|
41
|
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**.
|
42
|
42
|
|
43
|
|
-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' }`.
|
|
43
|
+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).
|
44
|
44
|
|
45
|
45
|
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.
|
46
|
46
|
|
|
@@ -58,9 +58,9 @@ const server = new Backend.RPCServer(port, [{
|
58
|
58
|
{
|
59
|
59
|
name: 'subscribe',
|
60
|
60
|
hook: async (callback) => {
|
61
|
|
- const resp:SubscriptionResponse = { result: 'Success', uuid: 'generate_a_random_string_here' }
|
62
|
|
- callbacks.set(resp.uuid, callback);
|
63
|
|
- return resp
|
|
61
|
+ const randStr = 'generate_a_random_string_here'
|
|
62
|
+ callbacks.set(randStr, callback);
|
|
63
|
+ return { result: 'Success', uuid: randStr}
|
64
|
64
|
}
|
65
|
65
|
},{
|
66
|
66
|
name: 'unsubscribe',
|