Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: handle onMessage by message type

See original GitHub issue

This would be a big breaking change, I’d like to know your thoughts and opinions about this. Will it be valuable/worth doing? Feedback is highly appreciated!


client.send() to replace this.send() + message type:

// new
client.send("skill", { name: "fireball" })

// deprecate
this.send(client, { type: "skill", name: "fireball" }

client.send() a schema-encoded message

This is already supported by the server-side. See below plans to support this from client-side as well.

class SkillMessage extends Schema {
  @type("string") name: string;

const skill = new SkillMessage(); = "fireball";

Broadcast with type + data

// new
this.broadcast("skill", { name: "fireball" })

// deprecate
this.broadcast({ type: "skill", name: "fireball" })

onMessage to handle messages sent from the clients

// new
onCreate() {
    this.onMessage("move", (client, message) => {
        // handle "move" message

    this.onMessage(MoveMessage, (client, message) => {
        // handle schema-encoded "SchemaMessage"
        // (get autocompletion for "message")

// deprecate
onMessage(client, message) {


Allow sending the type of a message along with its data:

// new
room.send("move", { angle: 270 });

// deprecate
room.send({ type: "move", angle: 170 });

Allow sending a Schema structure from the client-side (this will be specially useful for strongly-typed languages, such as C#, C++, etc.)

class MoveMessage extends Schema {
    @type("number") angle: number;

const message = new MoveMessage();
message.angle = 170;


Receiving messages by type:

// new
room.onMessage("skill", (message) => {
  // handle "skill" message

room.onMessage(SkillMessage, (message) => {
  // handle schema-encoded "skill" message

// deprecate
room.onMessage((message) => {
  // handle any type of message

As always suggestions are welcome.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

statscommented, Feb 23, 2020

I like this change.

zgz682000commented, Mar 1, 2020

It sounds like an amazing change, and I would more like to use Schema instead of Fossil Delta. Why I choose Fossil Delta but not Schema? Because the schema code generator is not customable. Would you consider to implement the generator by template mechanism?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ADM Message Types - Amazon Developer
The ADM SDK handles your messages with the onMessage method. The behavior of ADM messages on a device depends on the state of...
Read more >
Design pattern for handling multiple message types
The basic idea is to register a set of handlers that dispatch the received messages to the handler for processing based on the...
Read more >
About FCM messages | Firebase Cloud Messaging - Google
With FCM, you can send two types of messages to clients: Notification messages, sometimes thought of as "display messages." These are handled by...
Read more >
Interaction Patterns - Documentation - Akka
This ensures that only the right kind of messages can be sent to an actor and ... adapt the response message to a...
Read more >
Creating a chat application with WebRTC - LogRocket Blog
ws.on("message", msg => { .... const { type, name, offer } = data; //Handle message by type switch (type) { .... case "offer":...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found