refactor: let sync handle info embed

This commit is contained in:
cha0s 2019-10-01 22:42:41 -05:00
parent dd0f4da9ad
commit 4340be5e2d
2 changed files with 7 additions and 8 deletions

View File

@ -59,16 +59,9 @@ export class ServerSynchronizer {
payload.push(synchronized.destroyPacket(informed));
}
else {
const id = synchronized.synchronizationId();
const type = idFromSynchronized(synchronized.constructor);
const packets = synchronized.packetsFor(informed);
for (let j = 0; j < packets.length; j++) {
const packet = packets[j];
packet.data.synchronized = {
id,
type,
};
payload.push(packet);
payload.push(packets[j]);
}
}
}

View File

@ -63,6 +63,12 @@ export function SynchronizedMixin(Superclass) {
if (!Array.isArray(packets)) {
packets = [packets];
}
// Embed synchronization info.
const id = this.synchronizationId();
const type = idFromSynchronized(this.constructor);
for (let i = 0; i < packets.length; i++) {
packets[i].data.synchronized = {id, type};
}
if (this.packetsAreIdempotent()) {
this._idempotentPackets = packets;
}