Send message between clients
f-rank opened this issue · comments
Trying to send a message from one client to the others, in the nyamcat example, but not getting there.
shouldn't this.room.send({ msg: "TEST"}); register with the onmessage functions?
this.room.onMessage = function (message) {
trace("ROOM MESSAGE: " + Std.string(message));
};
Is there a way to broadcast like in 01-chat-room.ts example ?
Hi @f-rank,
Colyseus is an authoritative game server, so that's not really how it works. The clients can only send messages directly to the server, and the server can either send messages back or update the room's state, which is synched automatically with all clients.
The nyancat example is using the state-handler
from the examples project.
The messages sent from the clients will arrive at the onMessage
callback in the server-side: https://github.com/gamestdio/colyseus-examples/blob/master/rooms/02-state-handler.ts#L47-L50
Hope this helps! Cheers!