Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ChunkPlaylistParser } from '@videojs/hls-parser';

import type { IPipeline, IPipelineLoader, IPipelineLoaderDependencies } from '../types/pipeline.declarations';
import type { INetworkManager, INetworkRequest } from '../types/network.declarations';
import type { ILogger } from '../types/logger.declarations';
Expand All @@ -18,6 +17,10 @@ export class HlsPipelineLoader implements IPipelineLoader {
HlsPipelineLoader.hlsParserFactory_ = parser;
}

public static getHlsParser(): typeof ChunkPlaylistParser | null {
return HlsPipelineLoader.hlsParserFactory_;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename getters and setter as getHlsParserFactory and setHlsParserFactory?


public static setVodPipelineFactory(): void {}

public static setLivePipelineFactory(): void {}
Expand Down
6 changes: 6 additions & 0 deletions packages/playback/src/lib/service-locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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 type { ChunkPlaylistParser } from '@videojs/hls-parser';
import { HlsPipelineLoader } from './pipeline-loaders/hls-pipeline-loader';

export class ServiceLocator {
public readonly logger: ILogger;
Expand Down Expand Up @@ -66,4 +68,8 @@ export class ServiceLocator {
protected createNetworkManager_(dependencies: NetworkManagerDependencies): INetworkManager {
return new NetworkManager(dependencies);
}

public getHlsParser(): typeof ChunkPlaylistParser | null {
return HlsPipelineLoader.getHlsParser();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets just remove HLS parser from service locator for now

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest';
import { HlsPipelineLoader } from '../../../src/lib/pipeline-loaders/hls-pipeline-loader';
import { ChunkPlaylistParser } from '@videojs/hls-parser';

describe('hls-pipeline-loader spec', () => {
it('parser is static pipeline loader member', () => {
expect(HlsPipelineLoader.getHlsParser()).toBe(null);
// set parser
HlsPipelineLoader.setHlsParser(ChunkPlaylistParser);
const ChunkHlsParser = HlsPipelineLoader.getHlsParser();
expect(ChunkHlsParser).toBeTypeOf('function');
const parser = ChunkHlsParser ? ChunkHlsParser.create({}) : null;
expect(parser).toBeInstanceOf(ChunkPlaylistParser);
});
});
25 changes: 25 additions & 0 deletions packages/playback/test/lib/service-locator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ChunkPlaylistParser } from '@videojs/hls-parser';
import { ServiceLocator } from '../../src/lib/service-locator';
import { beforeEach, describe, expect, it } from 'vitest';
import { HlsPipelineLoader } from '../../src/lib/pipeline-loaders/hls-pipeline-loader';

describe('Service locator spec', () => {
let serviceLocator: ServiceLocator;
beforeEach(() => {
serviceLocator = new ServiceLocator();
});

it('should create a service locator instance', () => {
expect(serviceLocator).toBeInstanceOf(ServiceLocator);
});

it('should return the chunk hls parser', () => {
expect(serviceLocator.getHlsParser()).toEqual(null);
// set parser
HlsPipelineLoader.setHlsParser(ChunkPlaylistParser);
const ChunkHlsParser = serviceLocator.getHlsParser();
expect(ChunkHlsParser).toBeTypeOf('function');
const parser = ChunkHlsParser ? ChunkHlsParser.create({}) : null;
expect(parser).toBeInstanceOf(ChunkPlaylistParser);
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this test for now?