感谢教程,有所帮助
1
Reputation
12
Posts
809
Profile views
0
Followers
0
Following
Posts made by lyh1091106900
broadcast Mechanism Question
posted in General Discussion •
All I know is in colyseus sever different player can live in different proccessId sever,with redispresence they can communicate。when I read soucecode in Room.ts about broadcast,I find it just sent message to clients of Room instance,I think Room instance is totally Independent of other proccessId sever。so it is confuse for me that without ipc call how can I call make a broadcast to send mssage to everyone.
the code follow :
broadcast(typeOrSchema, messageOrOptions, options) {
const isSchema = (typeof (typeOrSchema) === 'object');
const opts = ((isSchema) ? messageOrOptions : options);
if (opts && opts.afterNextPatch) {
delete opts.afterNextPatch;
this._afterNextPatchQueue.push(['broadcast', arguments]);
return;
}
if (isSchema) {
this.broadcastMessageSchema(typeOrSchema, opts);
}
else {
this.broadcastMessageType(typeOrSchema, messageOrOptions, opts);
}
}
broadcastMessageSchema(message, options = {}) {
const encodedMessage = Protocol.getMessageBytes[Protocol.Protocol.ROOM_DATA_SCHEMA](message);
let numClients = this.clients.length;
while (numClients--) {
const client = this.clients[numClients];
if (options.except !== client) {
client.enqueueRaw(encodedMessage);
}
}
}
broadcastMessageType(type, message, options = {}) {
const encodedMessage = Protocol.getMessageBytes[Protocol.Protocol.ROOM_DATA](type, message);
let numClients = this.clients.length;
while (numClients--) {
const client = this.clients[numClients];
if (options.except !== client) {
client.enqueueRaw(encodedMessage);
}
}
}