Serialize lifecycle changes and make cancellation, deadlines, and match side effects recoverable and idempotent. Archive accepted bids durably, quarantine invalid payloads, and preserve compatibility with empty round IDs. Synchronize HTTP polling and socket state with scoped resync events. Add cancellation cleanup index migration and regression coverage. Validated with 744 API tests, 65 Redis integration tests, and 28 Mongo integration tests.
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import type { Namespace } from 'socket.io';
|
|
import type { AuctionStateResponse } from './auction.service';
|
|
import type { MatchSideEffectDelta } from './auction-side-effect.service';
|
|
import { serializeRealtimeAuction } from './auction-realtime-serializer';
|
|
|
|
@Injectable()
|
|
export class AuctionEventBusService {
|
|
private auctionNamespace?: Namespace;
|
|
|
|
public attachAuctionNamespace(namespace: Namespace): void {
|
|
this.auctionNamespace = namespace;
|
|
}
|
|
|
|
public broadcastMatchSideEffect(
|
|
matchId: string,
|
|
delta: MatchSideEffectDelta,
|
|
): void {
|
|
this.auctionNamespace?.to(matchId).emit('match-side-effect', delta);
|
|
}
|
|
|
|
public broadcastState(matchId: string, state: AuctionStateResponse): void {
|
|
this.auctionNamespace
|
|
?.to(matchId)
|
|
.emit('state', serializeRealtimeAuction(state));
|
|
}
|
|
|
|
public broadcastReset(matchId: string, auctionLifecycleId: string): void {
|
|
this.auctionNamespace
|
|
?.to(matchId)
|
|
.emit('reset', { matchId, auctionLifecycleId });
|
|
}
|
|
}
|