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

Feature Suggestion: Stream-specific broadcasting #108

Open
Sakeran opened this issue Oct 8, 2019 · 0 comments
Open

Feature Suggestion: Stream-specific broadcasting #108

Sakeran opened this issue Oct 8, 2019 · 0 comments

Comments

@Sakeran
Copy link
Contributor

Sakeran commented Oct 8, 2019

One issue developers might run into while developing for multiple TransportStream types is the need to send different types of information to different streams. For example, a websockets/GMCP-enabled stream might render a sidebar for character status (done with a single JSON payload), while telnet-only streams require printed text (ten calls to Broadcast#say). Notably, we don't want the calls to say to be sent to non-telnet streams.

The TransportStream#command method solves this to some extent, but requires the developer to bypass Broadcast and interface directly with the player's stream. Additionally, while command prevents streams from trying to do something they can't (sending JSON), it doesn't prevent them from doing something they can do but shouldn't (ten calls to Broadcast#say).

With the ability for TransportStreams to identify themselves via an identifier property (as specified in the stream decorator issue: #59), it is possible for Broadcast to pick and choose what socket types it should send to. For the sake of explicitness, I'd propose this callback-based approach, Broadcast#for, which is easiest to show by example:

// Show the character's status.

Broadcast.for("telnet", b => {
  // 'b' is a decorated version of Broadcast that will only
  // send to telnet-type streams.

  b.sayAt(player, '------');
  b.sayAt(player, "HP: 100");
  b.sayAt(player, "Strength: 12");
  b.sayAt(player, "Intellect: 6");
  b.sayAt(player, '------');
});

Broadcast.for("ws", b => {
  // 'b' is a decorated version of Broadcast that will only
  // send to websocket-type streams.

  // (This 'send' API is currently made up, but Broadcast could probably use
  // some function like this to generalize the "send arbitrary data" action)
  b.send(player, {
    type: 'character_status',
    hp: 100,
    strength: 12,
    intellect: 6
  });
});

This method would allow developers a clean way to separate the presentation of data based on the interface being used by the player.

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

1 participant