Skip to content

Conversation

@tobiasstrebitzer
Copy link

@tobiasstrebitzer tobiasstrebitzer commented Oct 21, 2021

This Pull Request allows automatic serialization of Schema data when using the room.send method.

Client Example:

class UpdateArgs extends Schema {
  @type('uint8') x: number
  @type('uint8') y: number
}

const updateArgs = new UpdateArgs({ x: 1, y: 2 })
room.send(updateArgs)

Server Example:

class UpdateArgs extends Schema {
  @type('uint8') x: number
  @type('uint8') y: number
}

class GameRoom extends Room {
  async onCreate() {
    this.onMessage(UpdateArgs, (client, args) => {
      console.log(args) // UpdateArgs { x: 1, y: 2 }
      console.log(args instanceof UpdateArgs) // true
    })
  }
}

Notes:

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

Successfully merging this pull request may close these issues.

1 participant