28 lines
865 B
TypeScript
28 lines
865 B
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));
|
|
}
|
|
}
|