Skip to content

Commit

Permalink
fix(FEC-8354): When selecting Audio language and refresh the page, th…
Browse files Browse the repository at this point in the history
…e display language returns to default (but actual audio proper) (#18)
  • Loading branch information
Dan Ziv authored Jun 28, 2018
1 parent 039fbfe commit eb70a1c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 54 deletions.
4 changes: 3 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const isMacOS = /^darwin/.test(process.platform);
const customLaunchers = {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
flags: ['--no-sandbox', '--autoplay-policy=no-user-gesture-required']
}
};

module.exports = function(config) {
let karmaConf = {
logLevel: config.LOG_INFO,
browsers: ['Chrome', 'Firefox'],
browserDisconnectTimeout: 30000,
browserNoActivityTimeout: 60000,
concurrency: 1,
singleRun: true,
colors: true,
Expand Down
11 changes: 8 additions & 3 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class Kava extends BasePlugin {
_isPaused: boolean;
_isBuffering: boolean;
_timePercentEvent: {[time: string]: boolean};
_isPlaying: boolean;

/**
* The default config of the plugin.
Expand Down Expand Up @@ -104,6 +105,7 @@ export default class Kava extends BasePlugin {

_resetFlags(): void {
this._previousCurrentTime = 0;
this._isPlaying = false;
this._isFirstPlay = true;
this._isEnded = false;
this._isPaused = false;
Expand Down Expand Up @@ -158,6 +160,7 @@ export default class Kava extends BasePlugin {
this.eventManager.listen(this.player, this.player.Event.FIRST_PLAY, () => this._onFirstPlay());
this.eventManager.listen(this.player, this.player.Event.TRACKS_CHANGED, () => this._setInitialTracks());
this.eventManager.listen(this.player, this.player.Event.PLAYING, () => this._onPlaying());
this.eventManager.listen(this.player, this.player.Event.PLAYBACK_STARTED, () => (this._isPlaying = true));
this.eventManager.listen(this.player, this.player.Event.SEEKING, () => this._onSeeking());
this.eventManager.listen(this.player, this.player.Event.PAUSE, () => this._onPause());
this.eventManager.listen(this.player, this.player.Event.ENDED, () => this._onEnded());
Expand Down Expand Up @@ -286,9 +289,11 @@ export default class Kava extends BasePlugin {
}

_onTextTrackChanged(event: FakeEvent): void {
const textTrack = event.payload.selectedTextTrack;
this._model.updateModel({caption: textTrack.language});
this._sendAnalytics(KavaEventModel.CAPTIONS);
if (this._isPlaying) {
const textTrack = event.payload.selectedTextTrack;
this._model.updateModel({caption: textTrack.language});
this._sendAnalytics(KavaEventModel.CAPTIONS);
}
}

_onError(event: FakeEvent): void {
Expand Down
49 changes: 25 additions & 24 deletions test/src/kava-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ const ab = 3,
cap = 'cap',
ec = 200,
jt = 1213,
tp = '12';
tp = '12',
pc = 'pc',
av = 'av';

describe('KavaModel', () => {
let model;
let sandbox;
const eventModel = {
MY_EVENT: {
type: 'MY_EVENT',
Expand All @@ -45,23 +46,6 @@ describe('KavaModel', () => {
};

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(KavaModel.prototype, 'getActualBitrate').callsFake(() => ab);
sandbox.stub(KavaModel.prototype, 'getAverageBitrate').callsFake(() => avb);
sandbox.stub(KavaModel.prototype, 'getPartnerId').callsFake(() => pid);
sandbox.stub(KavaModel.prototype, 'getEntryId').callsFake(() => eid);
sandbox.stub(KavaModel.prototype, 'getSessionId').callsFake(() => sid);
sandbox.stub(KavaModel.prototype, 'getReferrer').callsFake(() => referrer);
sandbox.stub(KavaModel.prototype, 'getClientVer').callsFake(() => cv);
sandbox.stub(KavaModel.prototype, 'getClientTag').callsFake(() => ct);
sandbox.stub(KavaModel.prototype, 'getKS').callsFake(() => ks);
sandbox.stub(KavaModel.prototype, 'getUIConfId').callsFake(() => uic);
sandbox.stub(KavaModel.prototype, 'getCustomVar1').callsFake(() => cv1);
sandbox.stub(KavaModel.prototype, 'getCustomVar2').callsFake(() => cv2);
sandbox.stub(KavaModel.prototype, 'getCustomVar3').callsFake(() => cv3);
sandbox.stub(KavaModel.prototype, 'getPosition').callsFake(() => pos);
sandbox.stub(KavaModel.prototype, 'getDeliveryType').callsFake(() => del);
sandbox.stub(KavaModel.prototype, 'getPlaybackType').callsFake(() => pback);
model = new KavaModel({
sessionStartTime: sst,
eventIndex: ei,
Expand All @@ -74,10 +58,25 @@ describe('KavaModel', () => {
joinTime: jt,
targetPosition: tp
});
});

afterEach(() => {
sandbox.restore();
model.getActualBitrate = () => ab;
model.getAverageBitrate = () => avb;
model.getPartnerId = () => pid;
model.getEntryId = () => eid;
model.getSessionId = () => sid;
model.getReferrer = () => referrer;
model.getClientVer = () => cv;
model.getClientTag = () => ct;
model.getKS = () => ks;
model.getUIConfId = () => uic;
model.getCustomVar1 = () => cv1;
model.getCustomVar2 = () => cv2;
model.getCustomVar3 = () => cv3;
model.getPosition = () => pos;
model.getDeliveryType = () => del;
model.getPlaybackType = () => pback;
model.getPlaybackType = () => pback;
model.getPlaybackContext = () => pc;
model.getApplicationVersion = () => av;
});

it('should update the model', function() {
Expand Down Expand Up @@ -107,7 +106,9 @@ describe('KavaModel', () => {
ks: ks,
uiConfId: uic,
sessionStartTime: sst,
customVar2: cv2
customVar2: cv2,
playbackContext: pc,
applicationVersion: av
});
});
});
5 changes: 0 additions & 5 deletions test/src/kava-rate-handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ describe('KavaRateHandler', function() {
rateHandler.setCurrent(1080);
rateHandler.getCurrent().should.equal(1080);
});

it('should set the zero bitrate', () => {
rateHandler.setCurrent(0);
rateHandler.getCurrent().should.equal(0);
});
});

describe('getAverage', () => {
Expand Down
43 changes: 22 additions & 21 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('KavaPlugin', function() {
},
plugins: {
kava: {
referrer: 'referrer',
serviceUrl: '//analytics.kaltura.com/api_v3/index.php',
viewEventCountdown: 10,
resetSessionCountdown: 30,
Expand Down Expand Up @@ -131,14 +132,14 @@ describe('KavaPlugin', function() {
sandbox.restore();
});

function validateCommonParmas(params, eventIndex) {
function validateCommonParams(params, eventIndex) {
params.eventType.should.equal(eventIndex);
params.partnerId.should.equal(config.session.partnerId.toString());
params.entryId.should.equal(config.id);
params.sessionId.should.equal(config.session.id);
params.eventIndex.should.equal(1);
params.ks.should.equal(config.session.ks);
params.referrer.should.equal(btoa(document.referrer));
params.referrer.should.equal(btoa(config.plugins.kava.referrer));
params.deliveryType.should.equal('url');
params.playbackType.should.equal('vod');
(!!params.sessionStartTime).should.be.false;
Expand All @@ -150,7 +151,7 @@ describe('KavaPlugin', function() {
it('should send IMPRESSION event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.IMPRESSION.index) return;
validateCommonParmas(params, KavaEventModel.IMPRESSION.index);
validateCommonParams(params, KavaEventModel.IMPRESSION.index);
done();
});
setupPlayer(config);
Expand All @@ -161,7 +162,7 @@ describe('KavaPlugin', function() {
it('should send PLAY_REQUEST event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY_REQUEST.index) return;
validateCommonParmas(params, KavaEventModel.PLAY_REQUEST.index);
validateCommonParams(params, KavaEventModel.PLAY_REQUEST.index);
done();
});
setupPlayer(config);
Expand All @@ -172,7 +173,7 @@ describe('KavaPlugin', function() {
it('should send PLAY event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY.index) return;
validateCommonParmas(params, KavaEventModel.PLAY.index);
validateCommonParams(params, KavaEventModel.PLAY.index);
params.bufferTime.should.exist;
params.bufferTimeSum.should.exist;
params.actualBitrate.should.exist;
Expand All @@ -187,7 +188,7 @@ describe('KavaPlugin', function() {
it('should send RESUME event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.RESUME.index) return;
validateCommonParmas(params, KavaEventModel.RESUME.index);
validateCommonParams(params, KavaEventModel.RESUME.index);
params.bufferTime.should.exist;
params.bufferTimeSum.should.exist;
params.actualBitrate.should.exist;
Expand All @@ -211,7 +212,7 @@ describe('KavaPlugin', function() {
it('should send PAUSE event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PAUSE.index) return;
validateCommonParmas(params, KavaEventModel.PAUSE.index);
validateCommonParams(params, KavaEventModel.PAUSE.index);
kava._timer._stopped.should.be.true;
done();
});
Expand All @@ -228,7 +229,7 @@ describe('KavaPlugin', function() {
it('should send REPLAY event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.REPLAY.index) return;
validateCommonParmas(params, KavaEventModel.REPLAY.index);
validateCommonParams(params, KavaEventModel.REPLAY.index);
done();
});
setupPlayer(config);
Expand All @@ -249,7 +250,7 @@ describe('KavaPlugin', function() {
it('should send SEEK event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.SEEK.index) return;
validateCommonParmas(params, KavaEventModel.SEEK.index);
validateCommonParams(params, KavaEventModel.SEEK.index);
params.targetPosition.should.exist;
done();
});
Expand All @@ -266,7 +267,7 @@ describe('KavaPlugin', function() {
it('should send PLAY_REACHED_25_PERCENT event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY_REACHED_25_PERCENT.index) return;
validateCommonParmas(params, KavaEventModel.PLAY_REACHED_25_PERCENT.index);
validateCommonParams(params, KavaEventModel.PLAY_REACHED_25_PERCENT.index);
done();
});
setupPlayer(config);
Expand All @@ -282,7 +283,7 @@ describe('KavaPlugin', function() {
it('should send PLAY_REACHED_50_PERCENT event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY_REACHED_50_PERCENT.index) return;
validateCommonParmas(params, KavaEventModel.PLAY_REACHED_50_PERCENT.index);
validateCommonParams(params, KavaEventModel.PLAY_REACHED_50_PERCENT.index);
done();
});
setupPlayer(config);
Expand All @@ -298,7 +299,7 @@ describe('KavaPlugin', function() {
it('should send PLAY_REACHED_75_PERCENT event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY_REACHED_75_PERCENT.index) return;
validateCommonParmas(params, KavaEventModel.PLAY_REACHED_75_PERCENT.index);
validateCommonParams(params, KavaEventModel.PLAY_REACHED_75_PERCENT.index);
done();
});
setupPlayer(config);
Expand All @@ -314,14 +315,14 @@ describe('KavaPlugin', function() {
it('should send PLAY_REACHED_100_PERCENT event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.PLAY_REACHED_100_PERCENT.index) return;
validateCommonParmas(params, KavaEventModel.PLAY_REACHED_100_PERCENT.index);
validateCommonParams(params, KavaEventModel.PLAY_REACHED_100_PERCENT.index);
done();
});
setupPlayer(config);
kava = getKavaPlugin();
const onPlaying = () => {
player.removeEventListener(player.Event.PLAYING, onPlaying);
player.currentTime = player.duration;
player.currentTime = player.duration - 1;
};
player.addEventListener(player.Event.PLAYING, onPlaying);
player.play();
Expand All @@ -330,7 +331,7 @@ describe('KavaPlugin', function() {
it('should send SOURCE_SELECTED event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.SOURCE_SELECTED.index) return;
validateCommonParmas(params, KavaEventModel.SOURCE_SELECTED.index);
validateCommonParams(params, KavaEventModel.SOURCE_SELECTED.index);
params.actualBitrate.should.equal(480256);
done();
return new RequestBuilder();
Expand All @@ -346,7 +347,7 @@ describe('KavaPlugin', function() {
it('should send FLAVOR_SWITCH event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.FLAVOR_SWITCH.index) return;
validateCommonParmas(params, KavaEventModel.FLAVOR_SWITCH.index);
validateCommonParams(params, KavaEventModel.FLAVOR_SWITCH.index);
params.actualBitrate.should.equal(480256);
done();
return new RequestBuilder();
Expand All @@ -362,7 +363,7 @@ describe('KavaPlugin', function() {
it('should send AUDIO_SELECTED event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.AUDIO_SELECTED.index) return;
validateCommonParmas(params, KavaEventModel.AUDIO_SELECTED.index);
validateCommonParams(params, KavaEventModel.AUDIO_SELECTED.index);
params.language.should.equal('heb');
done();
});
Expand All @@ -374,7 +375,7 @@ describe('KavaPlugin', function() {

it('should send CAPTIONS event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
validateCommonParmas(params, KavaEventModel.CAPTIONS.index);
validateCommonParams(params, KavaEventModel.CAPTIONS.index);
params.caption.should.equal('eng');
done();
});
Expand All @@ -386,7 +387,7 @@ describe('KavaPlugin', function() {

it('should send ERROR event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
validateCommonParmas(params, KavaEventModel.ERROR.index);
validateCommonParams(params, KavaEventModel.ERROR.index);
params.errorCode.should.equal(200);
done();
});
Expand All @@ -398,7 +399,7 @@ describe('KavaPlugin', function() {

it('should send VIEW event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
validateCommonParmas(params, KavaEventModel.VIEW.index);
validateCommonParams(params, KavaEventModel.VIEW.index);
params.playTimeSum.should.exist;
params.bufferTime.should.exist;
params.bufferTimeSum.should.exist;
Expand Down Expand Up @@ -479,7 +480,7 @@ describe('KavaPlugin', function() {
setTimeout(resolve, 1000);
return Promise.resolve({
time: 12345,
viewEventEnabled: false
viewEventsEnabled: false
});
});
setupPlayer(config);
Expand Down

0 comments on commit eb70a1c

Please sign in to comment.