Skip to content

Commit

Permalink
feat: add new method room.sendGameFrameToViews()
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeg committed Oct 19, 2024
1 parent 4fb1f40 commit ef4f30f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions domains/MatchRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,13 @@ class MatchRoom extends Room {
message = new Uint8Array(message);
}
message[0] = (message[0] & 0b11111000) | p_idx; // sets player number in header byte of binary message
this.sendToViews(message);
this.sendGameFrameToViews(message);
} else if (Array.isArray(message)) {
this.sendToViews([message[0], p_idx, ...message.slice(1)]);
// TODO: send message to admin page as well?
} else {
// assume frame
this.sendToViews(['frame', p_idx, message]);
this.sendGameFrameToViews(['frame', p_idx, message]);
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions domains/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,29 @@ class Room extends EventEmitter {
this.views.forEach(connection => connection.send(message));
}

sendGameFrameToViews(message) {
this.views.forEach(connection => {
if (!connection.no_frames) {
connection => connection.send(message);
}
});
}

close(reason) {
this.views.forEach(connection => connection.kick(reason));
this.views.clear();
}

handleProducerMessage(user, message) {
if (message instanceof Uint8Array) {
this.sendToViews(message);
this.sendGameFrameToViews(message);
} else if (Array.isArray(message)) {
if (message[0] === 'setVdoNinjaURL') {
user.vdo_ninja_url = message[1];
}
this.sendToViews([message[0], 0, ...message.slice(1)]);
} else {
this.sendToViews(['frame', 0, message]);
this.sendGameFrameToViews(['frame', 0, message]);
}
}
}
Expand Down

0 comments on commit ef4f30f

Please sign in to comment.