v 1.2.5 moar README
This commit is contained in:
@@ -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',
|
||||
|
||||
+1
-1
@@ -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": {
|
||||
|
||||
@@ -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: () => [
|
||||
|
||||
Reference in New Issue
Block a user