client also need register rpc method
Opened this issue · 5 comments
wizd commented
server.register(method, handler[, namespace]) -> RPCMethod
this should be available to client also to support server callback.
mkozjak commented
wizd commented
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 commented
@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 commented
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.