Skip to content

Commit

Permalink
fix: make parser static member
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Feb 5, 2025
1 parent e78ed47 commit 2877469
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
16 changes: 16 additions & 0 deletions packages/playback/src/lib/pipelines/mse/hls-pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { IPipelineDependencies } from '../../types/pipeline.declarations';
import MsePipeline from './mse-pipeline';
import { ChunkPlaylistParser, type FullPlaylistParser } from '@videojs/hls-parser';

export class HlsPipeline extends MsePipeline {
public static parser: ChunkPlaylistParser | FullPlaylistParser;

public static create(dependencies: IPipelineDependencies): HlsPipeline {
dependencies.logger = dependencies.logger.createSubLogger('HlsPipeline');
this.parser = ChunkPlaylistParser.create({
debugCallback: dependencies.logger.debug,
warnCallback: dependencies.logger.warn,
});
return new HlsPipeline(dependencies);
}
}
51 changes: 50 additions & 1 deletion packages/playback/src/lib/pipelines/mse/mse-pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
import type { IQualityLevel } from 'src/lib/types/quality-level.declarations';
import { BasePipeline } from '../base-pipeline';
import type { IPlayerAudioTrack } from 'src/lib/types/audio-track.declarations';
import type {
IPlayerTextTrack,
IRemoteVttThumbnailTrackOptions,
IPlayerThumbnailTrack,
} from 'src/entry-points/api-reference';
import type { PlaybackState } from 'src/lib/consts/playback-state';

export default abstract class MsePipeline extends BasePipeline {}
/* eslint-disable */
export default abstract class MsePipeline extends BasePipeline {
public dispose(): void {
throw new Error('Method not implemented.');
}

Check warning on line 15 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
public getAudioTracks(): Array<IPlayerAudioTrack> {
throw new Error('Method not implemented.');
}

Check warning on line 18 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
public selectAudioTrack(id: string): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 21 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
public getQualityLevels(): Array<IQualityLevel> {
throw new Error('Method not implemented.');
}

Check warning on line 24 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L23-L24

Added lines #L23 - L24 were not covered by tests
public selectQualityLevel(): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 27 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L26-L27

Added lines #L26 - L27 were not covered by tests
public selectAutoQualityLevel(): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 30 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L29-L30

Added lines #L29 - L30 were not covered by tests
public getTextTracks(): Array<IPlayerTextTrack> {
throw new Error('Method not implemented.');
}

Check warning on line 33 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L32-L33

Added lines #L32 - L33 were not covered by tests
public removeRemoteThumbnailTrack(id: string): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 36 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L35-L36

Added lines #L35 - L36 were not covered by tests
public addRemoteVttThumbnailTrack(options: IRemoteVttThumbnailTrackOptions): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 39 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L38-L39

Added lines #L38 - L39 were not covered by tests
public selectThumbnailTrack(id: string): boolean {
throw new Error('Method not implemented.');
}

Check warning on line 42 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L41-L42

Added lines #L41 - L42 were not covered by tests
public getThumbnailTracks(): Array<IPlayerThumbnailTrack> {
throw new Error('Method not implemented.');
}

Check warning on line 45 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L44-L45

Added lines #L44 - L45 were not covered by tests
public getPlaybackState(): PlaybackState {
throw new Error('Method not implemented.');
}

Check warning on line 48 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L47-L48

Added lines #L47 - L48 were not covered by tests
public start(): void {
throw new Error('Method not implemented.');
}

Check warning on line 51 in packages/playback/src/lib/pipelines/mse/mse-pipeline.ts

View check run for this annotation

Codecov / codecov/patch

packages/playback/src/lib/pipelines/mse/mse-pipeline.ts#L50-L51

Added lines #L50 - L51 were not covered by tests
}
11 changes: 4 additions & 7 deletions packages/playback/src/lib/service-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { EventEmitter } from './utils/event-emitter';
import { NetworkManager } from './network/network-manager';
import { PlayerEventType } from './consts/events';
import { PipelineLoaderFactoryStorage } from './utils/pipeline-loader-factory-storage';
import { FullPlaylistParser } from '@videojs/hls-parser';
import type { ChunkPlaylistParser, FullPlaylistParser } from '@videojs/hls-parser';
import { HlsPipeline } from './pipelines/mse/hls-pipeline';

export class ServiceLocator {
public readonly logger: ILogger;
Expand Down Expand Up @@ -68,11 +69,7 @@ export class ServiceLocator {
return new NetworkManager(dependencies);
}

public getHlsParser(): FullPlaylistParser {
const hlsParserLogger = this.logger.createSubLogger('HLSFullPlaylistParser');
return FullPlaylistParser.create({
debugCallback: hlsParserLogger.debug,
warnCallback: hlsParserLogger.warn,
});
public getHlsParser(): FullPlaylistParser | ChunkPlaylistParser {
return HlsPipeline.parser;
}
}
11 changes: 8 additions & 3 deletions packages/playback/test/lib/service-locator.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FullPlaylistParser } from '@videojs/hls-parser';
import { ChunkPlaylistParser } from '@videojs/hls-parser';
import { ServiceLocator } from '../../src/lib/service-locator';
import { beforeEach, describe, expect, it } from 'vitest';
import { HlsPipeline } from '../../src/lib/pipelines/mse/hls-pipeline';
import type { IPipelineDependencies } from '../../src/entry-points/api-reference';
describe('Service locator spec', () => {
let serviceLocator: ServiceLocator;
beforeEach(() => {
Expand All @@ -11,7 +13,10 @@ describe('Service locator spec', () => {
expect(serviceLocator).toBeInstanceOf(ServiceLocator);
});

it('should return the full hls parser', () => {
expect(serviceLocator.getHlsParser()).toBeInstanceOf(FullPlaylistParser);
it('should return the chunk hls parser', () => {
HlsPipeline.create({
logger: serviceLocator.logger,
} as IPipelineDependencies);
expect(serviceLocator.getHlsParser()).toBeInstanceOf(ChunkPlaylistParser);
});
});

0 comments on commit 2877469

Please sign in to comment.