I'm only getting the first state and it's not being updated beyond that.
Is there something obvious that I'm not seeing that is causing the issue?
Here is my room code:
import BaseRoom from "./BaseRoom";
import {Client} from "colyseus";
export class State {
ticks: number;
constructor() {
this.ticks = 0;
}
}
export default class ChatRoom extends BaseRoom<State> {
onDispose(): void | Promise<any> {
return undefined;
}
onInit(options: any): void {
console.log('ChatRoom created');
this.setState(new State());
setInterval(() => {
this.setState({ticks: this.state.ticks + 1});
console.log('Updated state', this.state);
}, 1000);
}
onJoin(client: Client, options?: any, auth?: any): void | Promise<any> {
return undefined;
}
onLeave(client: Client): void | Promise<any> {
return undefined;
}
onMessage(client: Client, data: any): void {
console.log('ChatRoom received message', data);
}
}
And on the Unity Side:
Client client = new Colyseus.Client("ws://localhost:6900");
client.OnError += Client_OnError;
yield return StartCoroutine(client.Connect());
Room room = client.Join("chat", new Dictionary<string, object>() {
{"accessToken",accessToken},
{"username", username}
});
room.OnReadyToConnect += (sender, e) => {
Debug.Log("Ready to join room");
StartCoroutine(room.Connect());
};
room.OnError += Room_OnError;
room.OnStateChange += OnStateChange;
room.Listen("message", this.OnMessage);
room.Listen("ticks", this.OnTick);
room.OnJoin += Room_OnJoin;
room.OnMessage += Room_OnMessage;
int i = 0;
while (true)
{
client.Recv();
i++;
if (i % 50 == 0)
{
room.Send("some_command");
}
yield return 0;
}