Skip to content

Commit

Permalink
send client spectating broadcasts on connect for bookkeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlee337 committed Apr 19, 2024
1 parent 8c86b30 commit 0a8faa3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/broadcast/spectate.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Methods {
dolphinClosed(playbackId: string): Promise<void>;
connect(authToken: string): Promise<void>;
refreshBroadcastList(): Promise<void>;
getOpenBroadcasts(): Promise<{ broadcastId: string; dolphinId: string }[]>;
getLogObservable(): Observable<string>;
getErrorObservable(): Observable<Error | string>;
getBroadcastListObservable(): Observable<BroadcasterItem[]>;
Expand Down Expand Up @@ -91,6 +92,9 @@ const methods: WorkerSpec = {
async refreshBroadcastList(): Promise<void> {
await spectateManager.refreshBroadcastList();
},
async getOpenBroadcasts() {
return await spectateManager.getOpenBroadcasts();
},
getLogObservable(): Observable<string> {
return Observable.from(logSubject);
},
Expand Down
7 changes: 7 additions & 0 deletions src/broadcast/spectate_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,11 @@ export class SpectateManager extends EventEmitter {

this.stopWatchingBroadcast(broadcastInfo.broadcastId);
}

public getOpenBroadcasts() {
return Object.values(this.openBroadcasts).map((value) => ({
broadcastId: value.broadcastId,
dolphinId: value.dolphinId,
}));
}
}
1 change: 1 addition & 0 deletions src/broadcast/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface SpectateController {
dolphinClosed(playbackId: string): Promise<void>;
connect(authToken: string): Promise<void>;
refreshBroadcastList(): Promise<void>;
getOpenBroadcasts(): Promise<{ broadcastId: string; dolphinId: string }[]>;
getBroadcastListObservable(): Observable<BroadcasterItem[]>;
getSpectateDetailsObservable(): Observable<{ playbackId: string; filePath: string; broadcasterName: string }>;
getGameEndObservable(): Observable<string>;
Expand Down
6 changes: 6 additions & 0 deletions src/remote/remote_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ export class RemoteServer {
});
this.connection = newConnection;
ipc_remoteStateEvent.main!.trigger({ connected: true, started: true }).catch(log.error);
this.connection.sendUTF(
JSON.stringify({
op: "spectating-broadcasts-event",
spectatingBroadcasts: await this.spectateController!.getOpenBroadcasts(),
}),
);
} else {
request.reject();
}
Expand Down

0 comments on commit 0a8faa3

Please sign in to comment.