Skip to content

Commit

Permalink
fix(FEC-8773): local storage mute state is not updated when user drag…
Browse files Browse the repository at this point in the history
… volume bar (#190)


Manipulate the muted value saved in the local storage in case user changed volume.
  • Loading branch information
Dan Ziv authored and OrenMe committed Dec 19, 2018
1 parent 792fed4 commit 28d098f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/common/storage/storage-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default class StorageManager {
});
player.addEventListener(player.Event.UI.USER_CHANGED_VOLUME, () => {
if (!player.isCasting()) {
if (player.volume > 0) {
StorageWrapper.setItem(StorageManager.StorageKeys.MUTED, false);
} else {
StorageWrapper.setItem(StorageManager.StorageKeys.MUTED, true);
}
StorageWrapper.setItem(StorageManager.StorageKeys.VOLUME, player.volume);
}
});
Expand Down
44 changes: 43 additions & 1 deletion test/src/common/storage/storage-manager.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import StorageManager from '../../../../src/common/storage/storage-manager';
import StorageWrapper from '../../../../src/common/storage/storage-wrapper';
import * as TestUtils from '../../utils/test-utils';
import {setup} from '../../../../src';
import {FakeEvent} from '@playkit-js/playkit-js';

const targetId = 'player-placeholder_storage-manager.spec';

describe('StorageManager', function() {
let sandbox;
let config, player, sandbox;
const partnerId = 1091;
const entryId = '0_wifqaipd';

before(function() {
TestUtils.createElement('DIV', targetId);
});

beforeEach(function() {
sandbox = sinon.sandbox.create();
config = {
targetId: targetId,
provider: {
partnerId: partnerId
}
};
});

afterEach(function() {
sandbox.restore();
TestUtils.removeVideoElementsFromTestPage();
window.localStorage.clear();
});

after(function() {
TestUtils.removeElement(targetId);
});

it('should return it has no storage', function() {
sandbox.stub(StorageWrapper, '_testForLocalStorage').callsFake(() => {
StorageWrapper._isLocalStorageAvailable = true;
Expand Down Expand Up @@ -69,4 +91,24 @@ describe('StorageManager', function() {
}
});
});

it('should set muted to true/false depends on changed volume', function() {
sandbox.stub(StorageWrapper, '_testForLocalStorage').callsFake(() => {
StorageWrapper._isLocalStorageAvailable = true;
});
player = setup(config);
player.loadMedia({entryId: entryId}).then(() => {
player.muted = true;
player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CLICKED_MUTE));
StorageManager.getStorageConfig().playback.muted.should.be.true;
player.volume = 0.5;
player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CHANGED_VOLUME));
StorageManager.getStorageConfig().playback.muted.should.be.false;
StorageManager.getStorageConfig().playback.volume.should.equals(0.5);
player.volume = 0;
player.dispatchEvent(new FakeEvent(player.Event.UI.USER_CHANGED_VOLUME));
StorageManager.getStorageConfig().playback.muted.should.be.true;
StorageManager.getStorageConfig().playback.volume.should.equals(0);
});
});
});

0 comments on commit 28d098f

Please sign in to comment.