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

Implement Client-to-Server Schema serialization / deserialization #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant