Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

[SDK] rpc subsystem updates #449

Merged
merged 1 commit into from
Sep 30, 2019
Merged

[SDK] rpc subsystem updates #449

merged 1 commit into from
Sep 30, 2019

Conversation

eanders-ms
Copy link
Contributor

Changes to the RPC subsystem to introduce the notion of "channels". An app can now register an RPC dispatcher to a channel, and messages sent on the channel will be passed to the corresponding dispatcher, which will in turn find and call the correct handler. Example:

// In App constructor:
  // Create an rpc dispatcher.
  const rpc = new RPC(context);
  // Register the rpc dispatcher to the "video-player" channel.
  context.rpcChannels.setChannelHandler(rpc, "video-player");
  // Add a handler to the rpc dispatcher. Will handle the "play-video" message sent on the "video-player" channel.
  rpc.on("play-video", (url) => this.playVideo(url));

This design allows for better separation of concerns particularly on the C# side. Using channel-based rpc is optional.

Also in this PR:

  • Added userId parameter to the rpc handler invocation.
  • Removed the notion of UserRPC vs. ContextRPC. All rpc happens on context, and an optional userId can be passed to filter the call to a single user. Otherwise it is sent to all users.
  • Fixed a bug where rpc parameters were being passed as an array instead of destructured.
  • Removed altspacevr-extras package.

Why this change?
For the Web Projector project (the remote web browser), I needed the id of the user making the rpc call on the Node side so that I could check whether they're authorized to do what they're trying to do. At the same time, I was pondering how to organize the code on the C# side in a nicely separated way. The introduction of channels allows for better code structure, and more succinct rpc procedure naming.

Copy link
Contributor

@tombuMS tombuMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@eanders-ms eanders-ms merged commit 951ed9e into red Sep 30, 2019
@eanders-ms eanders-ms deleted the eanders/rpc branch September 30, 2019 18:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants