Skip to content

Commit f806955

Browse files
committed
feat: add /shot socket.io nsp logic
1 parent e020ea1 commit f806955

2 files changed

Lines changed: 508 additions & 47 deletions

File tree

src/server/modules/live-contest/live-contest.service.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,42 @@ export type LiveContestMember = User & {
2525
broadcasterToken?: string;
2626
};
2727

28+
export interface BroadcasterStoreTrackItem {
29+
trackId: string;
30+
type: 'screen' | 'camera' | 'microphone';
31+
// other fields...
32+
}
33+
34+
export type BroadcasterStoreTracks = BroadcasterStoreTrackItem[];
35+
2836
export interface BroadcasterStoreInfo {
2937
status: 'ready' | 'broadcasting';
30-
tracks: {
31-
trackId: string;
32-
type: 'screen' | 'camera' | 'microphone';
33-
}[];
38+
tracks: Pick<BroadcasterStoreTrackItem, 'trackId' | 'type'>[];
3439
broadcastingTrackIds: string[];
3540
}
3641

37-
export interface BroadcasterStoreTrackItem {
42+
export interface ShotStoreTrackItem {
3843
trackId: string;
39-
type: 'screen' | 'camera' | 'microphone';
44+
name: string;
45+
type: 'video' | 'audio';
4046
// other fields...
4147
}
4248

43-
export type BroadcasterStoreTracks = BroadcasterStoreTrackItem[];
49+
export type ShotStoreTracks = ShotStoreTrackItem[];
50+
51+
export interface ShotStoreInfo {
52+
shotName: string;
53+
status: 'ready' | 'broadcasting';
54+
tracks: ShotStoreTrackItem[];
55+
broadcastingTrackIds: string[];
56+
}
4457

4558
@Provide()
4659
export default class LiveContestService {
4760
private readonly redis: Redis;
4861
private readonly apiClient: AxiosInstance;
4962
private readonly baseUrl: string;
63+
private shotStoreMap: Map</** uca */ string, Map</** shotId */ string, ShotStoreInfo>> = new Map();
5064

5165
public constructor(@Inject() private readonly redisClient: RedisClient) {
5266
this.redis = this.redisClient.getClient();
@@ -216,4 +230,25 @@ export default class LiveContestService {
216230
return null;
217231
}
218232
}
233+
234+
public getShotStore(uca: string): Map</** shotId */ string, ShotStoreInfo> | undefined {
235+
if (!this.shotStoreMap.has(uca)) {
236+
return undefined;
237+
}
238+
return this.shotStoreMap.get(uca)!;
239+
}
240+
241+
public setShotStore(uca: string, shotId: string, info: ShotStoreInfo): void {
242+
if (!this.shotStoreMap.has(uca)) {
243+
this.shotStoreMap.set(uca, new Map());
244+
}
245+
this.shotStoreMap.get(uca)!.set(shotId, info);
246+
}
247+
248+
public delShotStore(uca: string, shotId: string): void {
249+
if (!this.shotStoreMap.has(uca)) {
250+
return;
251+
}
252+
this.shotStoreMap.get(uca)!.delete(shotId);
253+
}
219254
}

0 commit comments

Comments
 (0)