Skip to content

Commit

Permalink
Merge pull request #1308 from canalplus/feat/reload-keySystems
Browse files Browse the repository at this point in the history
Add the possibility to set a new `keySystems` option on the `reload` API
  • Loading branch information
peaBerberian committed Dec 3, 2023
2 parents d1fde0d + 5ea30b4 commit 2d9b22d
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 116 deletions.
11 changes: 11 additions & 0 deletions doc/api/Basic_Methods/reload.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ The options argument is an object containing :
content was playing the last time it was played and stay in the `"LOADED"`
state (and paused) if it was paused last time it was played.

- _keySystems_ (`Array.<Object> | undefined`): If set, a new configuration will
be set on this reloaded content regarding its decryption.

The value of this property follows the exact same structure than for the
original `loadVideo` call, it is described in the [decryption options
documentation page](../Decryption_Options.md).

You might for example want to update that way the `keySystems` option compared
to the one of the original `loadVideo` call when you suspect that there is a
decryption-related issue with the original `keySystems` given.

Note that despite this method's name, the player will not go through the
`RELOADING` state while reloading the content but through the regular `LOADING`
state - as if `loadVideo` was called on that same content again.
Expand Down
101 changes: 55 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"demo": "node ./scripts/generate_full_demo.js --production-mode",
"demo:min": "node ./scripts/generate_full_demo.js --production-mode --minify",
"demo:watch": "node ./scripts/generate_full_demo.js --watch --production-mode",
"doc": "docgen.ico doc/ doc/generated \"$(cat VERSION)\"",
"doc": "readme.doc doc/ doc/generated \"$(cat VERSION)\"",
"lint": "eslint src -c .eslintrc.js",
"lint:demo": "eslint -c demo/full/.eslintrc.js demo/full/scripts",
"lint:tests": "eslint tests/**/*.js --ignore-pattern '/tests/performance/bundle*'",
Expand Down Expand Up @@ -84,6 +84,7 @@
"@babel/plugin-transform-runtime": "7.22.15",
"@babel/preset-env": "7.22.20",
"@babel/preset-react": "7.22.15",
"@canalplus/readme.doc": "^0.3.0",
"@types/chai": "4.3.6",
"@types/jest": "29.5.5",
"@types/mocha": "10.0.1",
Expand All @@ -97,7 +98,6 @@
"babel-loader": "9.1.3",
"chai": "4.3.8",
"core-js": "3.32.2",
"docgen.ico": "^0.2.3",
"esbuild": "0.19.3",
"eslint": "8.50.0",
"eslint-plugin-ban": "1.6.0",
Expand Down Expand Up @@ -127,7 +127,6 @@
"terser-webpack-plugin": "5.3.9",
"ts-jest": "29.1.1",
"ts-loader": "9.4.4",
"tslint": "6.1.3",
"typescript": "5.2.2",
"webpack": "5.88.2",
"webpack-bundle-analyzer": "4.9.1",
Expand Down
7 changes: 2 additions & 5 deletions src/core/api/debug/buffer_graph.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Representation } from "../../../manifest";
import { IBufferedChunk } from "../../segment_buffers";

const BUFFER_WIDTH_IN_SECONDS = 10000;
const BUFFER_WIDTH_IN_SECONDS = 30 * 60;

const COLORS = [
"#2ab7ca",
Expand Down Expand Up @@ -95,10 +95,7 @@ export default class SegmentBufferGraph {
let minimumPosition;
let maximumPosition;
if (maximumPoint - minimumPoint > BUFFER_WIDTH_IN_SECONDS) {
if (currentTime === undefined) {
minimumPosition = minimumPoint;
maximumPosition = maximumPoint;
} else if (maximumPoint - currentTime < BUFFER_WIDTH_IN_SECONDS / 2) {
if (maximumPoint - currentTime < BUFFER_WIDTH_IN_SECONDS / 2) {
maximumPosition = maximumPoint;
minimumPosition = maximumPoint - BUFFER_WIDTH_IN_SECONDS;
} else if (currentTime - minimumPoint < BUFFER_WIDTH_IN_SECONDS / 2) {
Expand Down
8 changes: 8 additions & 0 deletions src/core/api/option_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ function parseConstructorOptions(
*/
function checkReloadOptions(options?: {
reloadAt?: { position?: number; relative?: number };
keySystems?: IKeySystemOption[];
autoPlay?: boolean;
}): void {
if (options === null ||
(typeof options !== "object" && options !== undefined)) {
Expand All @@ -414,6 +416,12 @@ function checkReloadOptions(options?: {
options?.reloadAt?.relative !== undefined) {
throw new Error("API: reload - Invalid 'reloadAt.relative' option format.");
}
if (!Array.isArray(options?.keySystems) && options?.keySystems !== undefined) {
throw new Error("API: reload - Invalid 'keySystems' option format.");
}
if (options?.autoPlay !== undefined && typeof options.autoPlay !== "boolean") {
throw new Error("API: reload - Invalid 'autoPlay' option format.");
}
}

/**
Expand Down
22 changes: 18 additions & 4 deletions src/core/api/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
IConstructorOptions,
IDecipherabilityUpdateContent,
IKeySystemConfigurationOutput,
IKeySystemOption,
ILoadVideoOptions,
IPeriod,
IPlayerError,
Expand Down Expand Up @@ -577,6 +578,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
*/
reload(reloadOpts?: {
reloadAt?: { position?: number; relative?: number };
keySystems?: IKeySystemOption[];
autoPlay?: boolean;
}): void {
const { options,
Expand Down Expand Up @@ -609,6 +611,13 @@ class Player extends EventEmitter<IPublicAPIEvent> {
autoPlay = !reloadInPause;
}

let keySystems : IKeySystemOption[] | undefined;
if (reloadOpts?.keySystems !== undefined) {
keySystems = reloadOpts.keySystems;
} else if (this._priv_reloadingMetadata.options?.keySystems !== undefined) {
keySystems = this._priv_reloadingMetadata.options.keySystems;
}

const newOptions = { ...options,
initialManifest: manifest };
if (startAt !== undefined) {
Expand All @@ -617,6 +626,9 @@ class Player extends EventEmitter<IPublicAPIEvent> {
if (autoPlay !== undefined) {
newOptions.autoPlay = autoPlay;
}
if (keySystems !== undefined) {
newOptions.keySystems = keySystems;
}
this._priv_initializeContentPlayback(newOptions);
}

Expand All @@ -626,7 +638,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
if (features.createDebugElement === null) {
throw new Error("Feature `DEBUG_ELEMENT` not added to the RxPlayer");
}
const canceller = new TaskCanceller() ;
const canceller = new TaskCanceller();
features.createDebugElement(element, this, canceller.signal);
return {
dispose() {
Expand Down Expand Up @@ -2429,9 +2441,11 @@ class Player extends EventEmitter<IPublicAPIEvent> {
}
const segmentBufferStatus = this._priv_contentInfos
.segmentBuffersStore.getStatus(bufferType);
return segmentBufferStatus.type === "initialized" ?
segmentBufferStatus.value.getInventory() :
null;
if (segmentBufferStatus.type === "initialized") {
segmentBufferStatus.value.synchronizeInventory();
return segmentBufferStatus.value.getInventory();
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ describe("HTML Text buffer utils - areNearlyEqual", () => {
it("should return true if input number are equals", () => {
expect(areNearlyEqual(5, 5)).toBe(true);
});
it(
"should return false if input number are not nearly equals with delta parameter",
() => {
expect(areNearlyEqual(5, 5.1, 0.02)).toBe(false);
});
it(
"should return true if input number are nearly equals with delta parameter",
() => {
expect(areNearlyEqual(5, 5.01, 0.02)).toBe(true);
});
it(
"should return true if input number are equals with delta parameter",
() => {
expect(areNearlyEqual(5, 5, 0.02)).toBe(true);
});
});

describe("HTML Text buffer utils - removeCuesInfosBetween", () => {
Expand Down

0 comments on commit 2d9b22d

Please sign in to comment.