Colyseus: "afterNextPatch:true" is missing on "client.send()"

Created on 29 Jan 2020  路  6Comments  路  Source: colyseus/colyseus

Does room.send also use the state change patch push strategy, because I expect the interface to modify data and send data in the same push?

feature

Most helpful comment

That's a good point, this.send() does not currently have the {afterNextPatch:true} option that this.broadcast() has.

Gonna add this option for this.send() soon!

All 6 comments

That's a good point, this.send() does not currently have the {afterNextPatch:true} option that this.broadcast() has.

Gonna add this option for this.send() soon!

hi @endel Do you mean that the synchronization of this.send and data state change may not be completed in the same patch, so whether the client receiving onMessage and onStateChange will result in data inconsistency?

@dengzhaofun exactly, this.send() and this.broadcast() are sent immediatelly. Only this.broadcast(data, { afterNextPatch: true }) will ensure the message will be sent after the next state patch

Ok, look forward to solving

Hi, @endel
It is hoped that this issue can be resolved as soon as possible. Imagine a scenario where people in the room need to initiate a vote to end the game. Players vote to modify data on the state, and the final result of the vote is to notify the client through this.send. Then it is possible that this.send arrives at the client in advance, causing the game to end without seeing the voting status.

Hi @dengzhaofun, supporting afterNextPatch: true on send() should be implemented soonish (next week probably)

You can handle this scenario without relying on sending messages though. When mutating the state, you can listen for a change on the particular variable you're interested on, and display it for all users.

Example

/**
  * Server-side
  */
class VoteResults extends Schema {
  @type("string") result;
}

class GameState extends Schema {
  @type(VoteResults) voteResult = new VoteResults();
}
// ...
this.state.voteResult.result = "something";

/**
  * Client-side
  */
room.state.voteResult.listen("result", (value) => {
  console.log("Result is", value);
});
Was this page helpful?
0 / 5 - 0 ratings