From eb70a1cc045359903a1a227fb3e7419c9ca18b40 Mon Sep 17 00:00:00 2001 From: Dan Ziv Date: Thu, 28 Jun 2018 16:27:20 +0300 Subject: [PATCH] fix(FEC-8354): When selecting Audio language and refresh the page, the display language returns to default (but actual audio proper) (#18) --- karma.conf.js | 4 ++- src/kava.js | 11 +++++-- test/src/kava-model.spec.js | 49 +++++++++++++++--------------- test/src/kava-rate-handler.spec.js | 5 --- test/src/kava.spec.js | 43 +++++++++++++------------- 5 files changed, 58 insertions(+), 54 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index d232dbf7..47d9eac9 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -10,7 +10,7 @@ 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'] } }; @@ -18,6 +18,8 @@ module.exports = function(config) { let karmaConf = { logLevel: config.LOG_INFO, browsers: ['Chrome', 'Firefox'], + browserDisconnectTimeout: 30000, + browserNoActivityTimeout: 60000, concurrency: 1, singleRun: true, colors: true, diff --git a/src/kava.js b/src/kava.js index 4ae716e3..93adb5a6 100644 --- a/src/kava.js +++ b/src/kava.js @@ -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. @@ -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; @@ -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()); @@ -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 { diff --git a/test/src/kava-model.spec.js b/test/src/kava-model.spec.js index 64456768..2093e08f 100644 --- a/test/src/kava-model.spec.js +++ b/test/src/kava-model.spec.js @@ -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', @@ -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, @@ -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() { @@ -107,7 +106,9 @@ describe('KavaModel', () => { ks: ks, uiConfId: uic, sessionStartTime: sst, - customVar2: cv2 + customVar2: cv2, + playbackContext: pc, + applicationVersion: av }); }); }); diff --git a/test/src/kava-rate-handler.spec.js b/test/src/kava-rate-handler.spec.js index f7c9e963..4b4c684c 100644 --- a/test/src/kava-rate-handler.spec.js +++ b/test/src/kava-rate-handler.spec.js @@ -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', () => { diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index e49fb7e4..afb86776 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -96,6 +96,7 @@ describe('KavaPlugin', function() { }, plugins: { kava: { + referrer: 'referrer', serviceUrl: '//analytics.kaltura.com/api_v3/index.php', viewEventCountdown: 10, resetSessionCountdown: 30, @@ -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; @@ -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); @@ -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); @@ -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; @@ -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; @@ -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(); }); @@ -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); @@ -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(); }); @@ -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); @@ -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); @@ -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); @@ -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(); @@ -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(); @@ -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(); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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; @@ -479,7 +480,7 @@ describe('KavaPlugin', function() { setTimeout(resolve, 1000); return Promise.resolve({ time: 12345, - viewEventEnabled: false + viewEventsEnabled: false }); }); setupPlayer(config);