Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-7226, FEC-7243): player config stronger then storage config #43

Merged
merged 2 commits into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions src/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ function addKalturaPoster(metadata: Object, width: number, height: number): void
* @param {Object} playerConfig - the player config
* @returns {void}
*/
function setDefaultPlayerConfig(playerConfig: Object): void{
function setDefaultPlayerConfig(playerConfig: Object): void {
checkNativeHlsSupport(playerConfig);
checkNativeTextTracksSupport(playerConfig);
}

/**
* Sets config option for native HLS playback
* @param {Object} playerConfig - the player config
Expand Down Expand Up @@ -149,7 +150,9 @@ function checkNativeTextTracksSupport(playerConfig: Object): void {
*/
function setStorageConfig(disableUserCache: boolean, playerConfig: Object): void {
if (!disableUserCache && StorageManager.isLocalStorageAvailable() && StorageManager.hasStorage()) {
Utils.Object.mergeDeep(playerConfig, StorageManager.getStorage());
const playerStorageConfig = {};
Utils.Object.mergeDeep(playerStorageConfig, StorageManager.getStorage(), playerConfig);
Utils.Object.mergeDeep(playerConfig, playerStorageConfig);
}
}

Expand All @@ -168,15 +171,15 @@ function applyStorageSupport(player: any): void {
* Returns true if user agent indicate that browser is Safari
* @returns {boolean} - if browser is Safari
*/
function isSafari(): boolean{
function isSafari(): boolean {
return Env.browser.name.includes("Safari");
}

/**
* Returns true if user agent indicate that browser is Chrome on iOS
* @returns {boolean} - if browser is Chrome on iOS
*/
function isIos(): boolean{
function isIos(): boolean {
return (Env.os.name === "iOS");
}

Expand Down
52 changes: 51 additions & 1 deletion test/src/utils/setup-helpers.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as TestUtils from 'playkit-js/test/src/utils/test-utils'
import {ValidationErrorType} from '../../../src/utils/validation-error'
import StorageManager from '../../../src/storage/storage-manager'
import {
extractPlayerConfig,
extractProvidersConfig,
Expand All @@ -9,7 +10,8 @@ import {
addKalturaPoster,
checkNativeHlsSupport,
isSafari,
isIos
isIos,
setStorageConfig
} from '../../../src/utils/setup-helpers'

const targetId = 'player-placeholder_setup-helpers.spec';
Expand Down Expand Up @@ -333,3 +335,51 @@ describe('checkNativeHlsSupport', function () {
}
});
});

describe('setStorageConfig', function () {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.restore();
});

it('should merge the player and storage config with priority to the player config', function () {
let playerConfig = {
playback: {
textLanguage: 'ita'
}
};
let storageConfig = {
playback: {
textLanguage: 'eng',
audioLanguage: 'fra'
}
};
sandbox.stub(StorageManager, 'isLocalStorageAvailable', () => true);
sandbox.stub(StorageManager, 'hasStorage', () => true);
sandbox.stub(StorageManager, 'getStorage', () => storageConfig);
setStorageConfig(false, playerConfig);
playerConfig.playback.textLanguage.should.equal('ita');
playerConfig.playback.audioLanguage.should.equal('fra');
});

it('should take the storage config in case no player config', function () {
let playerConfig = {};
let storageConfig = {
playback: {
textLanguage: 'eng',
audioLanguage: 'fra'
}
};
sandbox.stub(StorageManager, 'isLocalStorageAvailable', () => true);
sandbox.stub(StorageManager, 'hasStorage', () => true);
sandbox.stub(StorageManager, 'getStorage', () => storageConfig);
setStorageConfig(false, playerConfig);
playerConfig.playback.textLanguage.should.equal('eng');
playerConfig.playback.audioLanguage.should.equal('fra');
});
});