feat(streams): add phase-1 single-server SFU session and transport APIs
This commit is contained in:
41
Backend/media/sfu/registry.ts
Normal file
41
Backend/media/sfu/registry.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { SfuSessionDescriptor, SfuSessionState } from './types';
|
||||
|
||||
type StoredSfuSession = SfuSessionDescriptor & {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export class SfuSessionRegistry {
|
||||
private readonly sessions = new Map<string, StoredSfuSession>();
|
||||
|
||||
get(streamSessionId: string): SfuSessionDescriptor | null {
|
||||
const found = this.sessions.get(streamSessionId);
|
||||
if (!found) return null;
|
||||
const { updatedAt: _updatedAt, ...descriptor } = found;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
set(session: SfuSessionDescriptor): SfuSessionDescriptor {
|
||||
const now = new Date().toISOString();
|
||||
this.sessions.set(session.streamSessionId, { ...session, updatedAt: now });
|
||||
return session;
|
||||
}
|
||||
|
||||
updateState(streamSessionId: string, state: SfuSessionState): SfuSessionDescriptor | null {
|
||||
const existing = this.sessions.get(streamSessionId);
|
||||
if (!existing) return null;
|
||||
|
||||
const next: StoredSfuSession = {
|
||||
...existing,
|
||||
state,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
this.sessions.set(streamSessionId, next);
|
||||
const { updatedAt: _updatedAt, ...descriptor } = next;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
list(): SfuSessionDescriptor[] {
|
||||
return Array.from(this.sessions.values()).map(({ updatedAt: _updatedAt, ...descriptor }) => descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user