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 #462

Closed

Conversation

tobiasstrebitzer
Copy link

@tobiasstrebitzer tobiasstrebitzer commented Oct 21, 2021

This Pull Request allows deserialization of encoded Schema data using the onMessage handler.

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:

@newbidoo
Copy link

newbidoo commented Nov 27, 2021

Exactly what i am looking for. Ill hope this will come soon :)

Edit:
Ok...there was a strong missunderstanding...
There is no realy need in sending schema from client side. I can use plain classes in ts/js.
This helped me colyseus/colyseus.js#82
maybe a hint in documentation would be helpful.

@github-actions
Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Jan 12, 2022
@github-actions
Copy link

This PR was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants