Skip to content

Commit

Permalink
chore: Fix playback demo (#51)
Browse files Browse the repository at this point in the history
* fix: use override for transform methods instead of passing functions (unable to use via postMessage)

* chore: upd deps
  • Loading branch information
dzianis-dashkevich authored Feb 5, 2025
1 parent cef7ecb commit 756c570
Show file tree
Hide file tree
Showing 7 changed files with 651 additions and 653 deletions.
1,216 changes: 610 additions & 606 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@
"preserve": "npm run prepare-deploy"
},
"devDependencies": {
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@eslint/js": "^9.18.0",
"@nx/js": "20.3.1",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@eslint/js": "^9.19.0",
"@nx/js": "20.4.0",
"@size-limit/preset-big-lib": "^11.1.6",
"@types/eslint__js": "^8.42.3",
"@types/react": "^19.0.7",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@typestrong/ts-mockito": "^2.7.12",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/browser": "^2.1.8",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"eslint": "^9.18.0",
"@vitest/browser": "^2.1.9",
"@vitest/coverage-v8": "^2.1.9",
"@vitest/ui": "^2.1.9",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-jsdoc": "^50.6.1",
"eslint-plugin-prettier": "^5.2.2",
"eslint-plugin-jsdoc": "^50.6.3",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.18",
"eslint-plugin-unicorn": "^56.0.1",
Expand All @@ -54,22 +54,22 @@
"http-server": "^14.1.1",
"husky": "^9.1.7",
"jsdom": "^26.0.0",
"lint-staged": "^15.3.0",
"lint-staged": "^15.4.3",
"npm-run-all": "^4.1.5",
"nx": "20.3.1",
"playwright": "^1.49.1",
"nx": "20.4.0",
"playwright": "^1.50.1",
"prettier": "^3.4.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rimraf": "^6.0.1",
"size-limit": "^11.1.6",
"typedoc": "^0.27.6",
"typescript": "~5.7.3",
"typescript-eslint": "^8.20.0",
"vite": "^6.0.7",
"typescript-eslint": "^8.23.0",
"vite": "^6.1.0",
"vite-plugin-banner": "^0.8.0",
"vite-plugin-dts": "^4.5.0",
"vite-plugin-static-copy": "^2.2.0",
"vitest": "^2.1.8"
"vitest": "^2.1.9"
}
}
41 changes: 23 additions & 18 deletions packages/hls-parser/src/lib/parser/base-parser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import type {
CustomTagMap,
DebugCallback,
ParseOptions,
ParserOptions,
TransformTagAttributes,
TransformTagValue,
WarnCallback,
} from '../types/parser-options';
import type { CustomTagMap, DebugCallback, ParseOptions, ParserOptions, WarnCallback } from '../types/parser-options';
import type { EmptyTagProcessor } from '../tags/empty-tag-processors';
import {
ExtM3u,
Expand Down Expand Up @@ -106,8 +98,6 @@ export class Parser {
private debugCallback_: DebugCallback;
private customTagMap_: CustomTagMap;
private ignoreTags_: Set<string>;
private transformTagValue_: TransformTagValue;
private transformTagAttributes_: TransformTagAttributes;

private readonly emptyTagMap_: Record<string, EmptyTagProcessor>;
private readonly tagValueMap_: Record<string, TagWithValueProcessor>;
Expand All @@ -121,9 +111,6 @@ export class Parser {
this.debugCallback_ = options.debugCallback || ((): void => {});
this.customTagMap_ = options.customTagMap || new Map();
this.ignoreTags_ = options.ignoreTags || new Set();
this.transformTagValue_ = options.transformTagValue || ((tagKey, tagValue): string | null => tagValue);
this.transformTagAttributes_ =
options.transformTagAttributes || ((tagKey, tagAttributes): Record<string, string> => tagAttributes);

this.parsedPlaylist_ = createDefaultParsedPlaylist();
this.sharedState_ = createDefaultSharedState();
Expand Down Expand Up @@ -170,13 +157,31 @@ export class Parser {
};
}

/**
* Transforms tag attributes before processing them.
* Override this method for custom tag attribute transformations.
* @param tagKey - tag key
* @param tagValue - tag value
*/
public transformTagValue(tagKey: string, tagValue: string | null): string | null {
return tagValue;
}

/**
* Transforms tag attributes before processing them.
* Override this method for custom tag attribute transformations.
* @param tagKey - tag key
* @param tagAttributes - tag attributes
*/
public transformTagAttributes(tagKey: string, tagAttributes: Record<string, string>): Record<string, string> {
return tagAttributes;
}

public updateOptions(options: ParserOptions): void {
this.warnCallback_ = options.warnCallback ?? this.warnCallback_;
this.debugCallback_ = options.debugCallback ?? this.debugCallback_;
this.customTagMap_ = options.customTagMap ?? this.customTagMap_;
this.ignoreTags_ = options.ignoreTags ?? this.ignoreTags_;
this.transformTagValue_ = options.transformTagValue ?? this.transformTagValue_;
this.transformTagAttributes_ = options.transformTagAttributes ?? this.transformTagAttributes_;
}

protected readonly tagInfoCallback_ = (
Expand All @@ -198,7 +203,7 @@ export class Parser {

//2. Process tags with values:
if (tagKey in this.tagValueMap_) {
tagValue = this.transformTagValue_(tagKey, tagValue);
tagValue = this.transformTagValue(tagKey, tagValue);

if (tagValue === null) {
return this.warnCallback_(missingTagValueWarn(tagKey));
Expand All @@ -210,7 +215,7 @@ export class Parser {

//3. Process tags with attributes:
if (tagKey in this.tagAttributesMap_) {
tagAttributes = this.transformTagAttributes_(tagKey, tagAttributes);
tagAttributes = this.transformTagAttributes(tagKey, tagAttributes);
const tagWithAttributesProcessor = this.tagAttributesMap_[tagKey];

return tagWithAttributesProcessor.process(tagAttributes, this.parsedPlaylist_, this.sharedState_);
Expand Down
5 changes: 0 additions & 5 deletions packages/hls-parser/src/lib/types/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ export type CustomTagMap = Map<
) => void
>;

export type TransformTagValue = (tagKey: string, tagValue: string | null) => string | null;
export type TransformTagAttributes = (tagKey: string, tagAttributes: Record<string, string>) => Record<string, string>;

// used in the parser's constructor
export interface ParserOptions {
warnCallback?: WarnCallback;
debugCallback?: DebugCallback;
customTagMap?: CustomTagMap;
ignoreTags?: Set<string>;
transformTagValue?: TransformTagValue;
transformTagAttributes?: TransformTagAttributes;
}

// used in the parse methods (eg parseFullPlaylistString, parseFullPlaylistBuffer, pushBuffer, pushString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export const getPlayerMseConfigurationDefaults = (): PlayerMseConfiguration => (
export const getPlayerHlsConfigurationDefaults = (): PlayerHlsConfiguration => ({
ignoreTags: new Set(),
customTagMap: new Map(),
transformTagValue: (tagKey, tagValue) => tagValue,
transformTagAttributes: (tagKey, tagAttributes) => tagAttributes,
});

export const getPlayerConfigurationDefaults = (): PlayerConfiguration => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export class HlsPipelineLoader implements IPipelineLoader {
debugCallback: (...debug) => logger.debug(...debug),
customTagMap: dependencies.configuration.hls.customTagMap,
ignoreTags: dependencies.configuration.hls.ignoreTags,
transformTagValue: dependencies.configuration.hls.transformTagValue,
transformTagAttributes: dependencies.configuration.hls.transformTagAttributes,
});

return new HlsPipelineLoader({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CustomTagMap, TransformTagValue, TransformTagAttributes } from '@videojs/hls-parser';
import type { CustomTagMap } from '@videojs/hls-parser';
import type { RequestType } from '../consts/request-type';

export interface NetworkConfiguration {
Expand Down Expand Up @@ -59,8 +59,6 @@ export interface PlayerMseConfiguration {
export interface PlayerHlsConfiguration {
ignoreTags: Set<string>;
customTagMap: CustomTagMap;
transformTagValue: TransformTagValue;
transformTagAttributes: TransformTagAttributes;
}

export interface PlayerConfiguration {
Expand Down

0 comments on commit 756c570

Please sign in to comment.