mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
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:
@@ -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);
|
||||
|
||||
@@ -48,7 +48,7 @@ export enum WorkerReceivePayloadOp {
|
||||
|
||||
export type WorkerReceivePayload =
|
||||
// Can't seem to get a type-safe union based off of the event, so I'm sadly leaving data as any for now
|
||||
| { data: any; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }
|
||||
| { data: any[]; event: WebSocketShardEvents; op: WorkerReceivePayloadOp.Event; shardId: number }
|
||||
| { nonce: number; op: WorkerReceivePayloadOp.CancelIdentify }
|
||||
| { nonce: number; op: WorkerReceivePayloadOp.FetchStatusResponse; status: WebSocketShardStatus }
|
||||
| { nonce: number; op: WorkerReceivePayloadOp.RetrieveSessionInfo; shardId: number }
|
||||
@@ -293,7 +293,8 @@ export class WorkerShardingStrategy implements IShardingStrategy {
|
||||
}
|
||||
|
||||
case WorkerReceivePayloadOp.Event: {
|
||||
this.manager.emit(payload.event, { ...payload.data, shardId: payload.shardId });
|
||||
// @ts-expect-error Event props can't be resolved properly, but they are correct
|
||||
this.manager.emit(payload.event, ...payload.data, payload.shardId);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user