refactor(ws): event layout (#10376)

* refactor(ws): event layout

BREAKING CHANGE: All events now emit shard id as its own param

* fix: worker event forwarding

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
DD
2024-07-24 21:40:34 +03:00
committed by GitHub
parent fcd35ea2e7
commit bf6761a44a
7 changed files with 137 additions and 134 deletions

View File

@@ -28,8 +28,8 @@ export class SimpleShardingStrategy implements IShardingStrategy {
const strategy = new SimpleContextFetchingStrategy(this.manager, strategyOptions);
const shard = new WebSocketShard(strategy, shardId);
for (const event of Object.values(WebSocketShardEvents)) {
// @ts-expect-error: Intentional
shard.on(event, (payload) => this.manager.emit(event, { ...payload, shardId }));
// @ts-expect-error Event props can't be resolved properly, but they are correct
shard.on(event, (...args) => this.manager.emit(event, ...args, shardId));
}
this.shards.set(shardId, shard);