I have this basic client code:
if(this.state.game_started) {
console.log("Game already started")
return
}
this.setState({
game_started:true
})
this.client=new Client("ws://localhost:2657")
this.room=this.client.join("game-room")
this.room.onJoin.add(()=>{
console.log(`Joined room with client id ${this.client.id}`)
})
this.room.onStateChange.add(()=>{
console.log("State change:")
console.log(this.room.state)
this.forceUpdate()
})
This is using React.
And this basic server room:
const colyseus=require("colyseus")
class GameRoom extends colyseus.Room {
constructor(){
super(...arguments)
this.maxClients=2
}
onInit(options){
// this.setState({
// message_history: []
// })
this.setState({})
this.state={
messages:[]
}
}
requestJoin(options, isNewRoom) {
return true
}
onJoin(client, options, auth) {
console.log(`Client with id ${client.id} joined. Options: ${JSON.stringify(options)}`)
this.state.messages.push({
sender:"Server",
content:`Client with id ${client.id} joined`
})
}
onMessage(client, data) {
if(data.type==="message"){
this.state.message_history.push(data.message)
}
}
onLeave(client, consented) {
console.log(`Client with id ${client.id} left. Consented: ${consented}`)
}
onDispose() {
}
}
module.exports = GameRoom
When I comment out the setState
in onInit
, the client joins perfectly fine. When I leave it uncommented, the client throws this error:
index.js:1446 colyseus.js: server error: SchemaSerializer error. See: https://docs.colyseus.io/migrating/0.10/#new-default-serializer
And the server prints nothing.
This is using latest version of server and client packages, so why is this happening?