Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client also need register rpc method #97

Open
wizd opened this issue Mar 1, 2021 · 5 comments
Open

client also need register rpc method #97

wizd opened this issue Mar 1, 2021 · 5 comments

Comments

@wizd
Copy link

wizd commented Mar 1, 2021

server.register(method, handler[, namespace]) -> RPCMethod

this should be available to client also to support server callback.

@mkozjak
Copy link
Member

mkozjak commented Mar 1, 2021

Hi, @wizd, thanks for the comment. This one is part of the v6 which isn’t released yet. You can try testing that release, it’s up on npm! #29

@mkozjak
Copy link
Member

mkozjak commented Mar 12, 2021

@wizd have you tried v6?

@wizd
Copy link
Author

wizd commented Mar 12, 2021

not yet but I added a server callback to make it works:

      // If this is an object with error, it is an error response.
      else if ('error' in response && this._wsCallbacks[response.id]) {
        // Get the error callback.
        var errorCb = this._wsCallbacks[response.id].errorCb;

        // Delete the callback from the storage.
        delete this._wsCallbacks[response.id];

        // Run callback with the error object as parameter.
        errorCb(response.error);
        return;
      }

      // a server call back
      else if ('method' in response) {
        // Construct the JSON-RPC 2.0 result.
        var cbresult = await this.options.oncallback(response);
        var request = {
          jsonrpc: '2.0',
          id: response.id,
          result:  cbresult
        };

        if(cbresult != null) {
          // Try making a WebSocket call.
          var socket = this.options.getSocket(this.wsOnMessage);
          if (socket !== null) {
            this._wsCall(socket, request);
          }
        }

@gpxl-dev
Copy link

@mkozjak I am confused by this - can you confirm if v6 is live?
AFAICT we're now on v7, but I can't see how a server can call a client method?

Thanks.

@mkozjak
Copy link
Member

mkozjak commented Sep 17, 2021

Yup, v6 is beta only, in v7 we continued developing regular version since we didn't get any feedback on v6 so we ignored it.

https://www.npmjs.com/package/rpc-websockets/v/6.0.2-beta.0

PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants