Files
ChannelTests-TS/test/workflows/strategies/StreamKindStrategy.ts

80 lines
1.8 KiB
TypeScript

export interface IStreamKindStrategy {
getStreamKind(): string;
getChannelOptions(): string[];
getTestDescription(): string;
}
export class RealTimeStreamStrategy implements IStreamKindStrategy {
getStreamKind(): string {
return 'RealTime';
}
getChannelOptions(): string[] {
return [];
}
getTestDescription(): string {
return 'RealTime stream subscription test';
}
}
export class ChunkedStreamHLSStrategy implements IStreamKindStrategy {
getStreamKind(): string {
return 'ChunkedStream HLS';
}
getChannelOptions(): string[] {
return ['hls'];
}
getTestDescription(): string {
return 'ChunkedStream HLS subscription test';
}
}
export class ChunkedStreamDASHStrategy implements IStreamKindStrategy {
getStreamKind(): string {
return 'ChunkedStream DASH';
}
getChannelOptions(): string[] {
return ['dash'];
}
getTestDescription(): string {
return 'ChunkedStream DASH subscription test';
}
}
// Example of how easy it is to add new stream types
export class WebRTCStreamStrategy implements IStreamKindStrategy {
getStreamKind(): string {
return 'WebRTC';
}
getChannelOptions(): string[] {
return ['webrtc', 'low-latency'];
}
getTestDescription(): string {
return 'WebRTC stream subscription test';
}
}
export class StreamKindStrategyFactory {
static createStrategy(streamType: string): IStreamKindStrategy {
switch (streamType.toLowerCase()) {
case 'realtime':
return new RealTimeStreamStrategy();
case 'hls':
return new ChunkedStreamHLSStrategy();
case 'dash':
return new ChunkedStreamDASHStrategy();
case 'webrtc':
return new WebRTCStreamStrategy();
default:
throw new Error(`Unknown stream type: ${streamType}`);
}
}
}