From bba3eb90894f0f0a877503a8ee71226230d801a1 Mon Sep 17 00:00:00 2001 From: "yuval.keidar" Date: Wed, 12 Aug 2020 14:27:30 +0300 Subject: [PATCH 1/3] feat(FEC-10376): add full screen to screen mode on view events Add screen mode in view event: screenMode=1 (not full screen) screenMode=2 (full screen) --- src/kava-event-model.js | 3 ++- src/kava-model.js | 18 +++++++++++++++++- src/kava.js | 6 +++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/kava-event-model.js b/src/kava-event-model.js index 53c45028..f7665451 100644 --- a/src/kava-event-model.js +++ b/src/kava-event-model.js @@ -22,7 +22,8 @@ export const KavaEventModel: {[event: string]: KavaEvent} = { averageBitrate: model.getAverageBitrate(), audioLanguage: model.getLanguage(), soundMode: model.getSoundMode(), - tabMode: model.getTabMode() + tabMode: model.getTabMode(), + screenMode: model.getScreenMode() }; if (!isNaN(model.getForwardBufferHealth())) { diff --git a/src/kava-model.js b/src/kava-model.js index be8f3c7f..23e5c338 100644 --- a/src/kava-model.js +++ b/src/kava-model.js @@ -30,6 +30,7 @@ class KavaModel { droppedFramesRatio: ?number = null; soundMode: typeof SoundMode; tabMode: typeof TabMode; + screenMode: typeof ScreenMode = ScreenMode.NOT_IN_FULLSCREEN; maxNetworkConnectionOverhead: number = 0; flavorParamsId: number = NaN; networkConnectionType: string; @@ -221,6 +222,16 @@ class KavaModel { return this.soundMode; } + /** + * Gets the screen mode of the browser player. + * @returns {FullScreenMode} the state of the full screen if is on or not. + * @memberof KavaModel + * @instance + */ + getScreenMode(): typeof ScreenMode { + return this.screenMode; + } + /** * Gets the Tab mode of the browser. * @returns {TabMode} the state of the tab (focused or not) @@ -353,10 +364,15 @@ const TabMode = { TAB_FOCUSED: 2 }; +const ScreenMode = { + NOT_IN_FULLSCREEN: 1, + FULLSCREEN: 2 +}; + const ErrorPosition = { PRE_PLAY: 3, PRE_PLAYING: 1, MID_STREAM: 2 }; -export {KavaModel, SoundMode, TabMode, ErrorPosition}; +export {KavaModel, SoundMode, TabMode, ErrorPosition, ScreenMode}; diff --git a/src/kava.js b/src/kava.js index a70977a9..8f943963 100644 --- a/src/kava.js +++ b/src/kava.js @@ -4,7 +4,7 @@ import {OVPAnalyticsService} from 'playkit-js-providers/dist/playkit-analytics-s import {KavaEventModel, KavaEventType} from './kava-event-model'; import {KavaRateHandler} from './kava-rate-handler'; import {KavaTimer} from './kava-timer'; -import {ErrorPosition, KavaModel, SoundMode, TabMode} from './kava-model'; +import {ErrorPosition, KavaModel, SoundMode, TabMode, ScreenMode} from './kava-model'; const {Error: PKError, FakeEvent, Utils} = core; const DIVIDER: number = 1024; @@ -306,6 +306,10 @@ class Kava extends BasePlugin { this.eventManager.listen(this.player, this.player.Event.LOAD_START, () => this._onLoadStart()); this.eventManager.listen(this.player, this.player.Event.VOLUME_CHANGE, () => this._updateSoundModeInModel()); this.eventManager.listen(this.player, this.player.Event.MUTE_CHANGE, () => this._updateSoundModeInModel()); + this.eventManager.listen(this.player, this.player.Event.ENTER_FULLSCREEN, () => this._model.updateModel({screenMode: ScreenMode.FULLSCREEN})); + this.eventManager.listen(this.player, this.player.Event.EXIT_FULLSCREEN, () => + this._model.updateModel({screenMode: ScreenMode.NOT_IN_FULLSCREEN}) + ); this._initTabMode(); this._initNetworkConnectionType(); } From 127d9ae6b5793b84ff0046ce0ef48b1d7ca72495 Mon Sep 17 00:00:00 2001 From: "yuval.keidar" Date: Wed, 12 Aug 2020 16:47:51 +0300 Subject: [PATCH 2/3] add tests and fix flow --- src/kava-model.js | 6 +++--- test/src/kava-event-model.spec.js | 5 +++++ test/src/kava.spec.js | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/kava-model.js b/src/kava-model.js index 23e5c338..1300f869 100644 --- a/src/kava-model.js +++ b/src/kava-model.js @@ -30,7 +30,7 @@ class KavaModel { droppedFramesRatio: ?number = null; soundMode: typeof SoundMode; tabMode: typeof TabMode; - screenMode: typeof ScreenMode = ScreenMode.NOT_IN_FULLSCREEN; + screenMode: number = ScreenMode.NOT_IN_FULLSCREEN; maxNetworkConnectionOverhead: number = 0; flavorParamsId: number = NaN; networkConnectionType: string; @@ -224,11 +224,11 @@ class KavaModel { /** * Gets the screen mode of the browser player. - * @returns {FullScreenMode} the state of the full screen if is on or not. + * @returns {number} the state of the full screen if is on or not. * @memberof KavaModel * @instance */ - getScreenMode(): typeof ScreenMode { + getScreenMode(): number { return this.screenMode; } diff --git a/test/src/kava-event-model.spec.js b/test/src/kava-event-model.spec.js index 7130a9cc..2bc309ed 100644 --- a/test/src/kava-event-model.spec.js +++ b/test/src/kava-event-model.spec.js @@ -69,6 +69,10 @@ class FakeModel { return 1; } + getScreenMode() { + return 1; + } + getAvailableBuffer() { return 2; } @@ -128,6 +132,7 @@ describe('KavaEventModel', () => { manifestDownloadTime: fakeModel.getMaxManifestDownloadTime(), soundMode: fakeModel.getSoundMode(), tabMode: fakeModel.getTabMode(), + screenMode: fakeModel.getScreenMode(), segmentDownloadTime: fakeModel.getSegmentDownloadTime(), forwardBufferHealth: fakeModel.getForwardBufferHealth(), targetBuffer: fakeModel.getTargetBuffer(), diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index 0f06f0c6..60b660f2 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -3,7 +3,7 @@ import {core, setup} from 'kaltura-player-js'; import * as TestUtils from './utils/test-utils'; import {OVPAnalyticsService, RequestBuilder} from 'playkit-js-providers/dist/playkit-analytics-service'; import {KavaEventModel} from '../../src/kava-event-model'; -import {ErrorPosition, SoundMode, TabMode} from '../../src/kava-model'; +import {ErrorPosition, SoundMode, TabMode, ScreenMode} from '../../src/kava-model'; const {FakeEvent, CustomEventType} = core; const targetId = 'player-placeholder_kava.spec'; @@ -69,6 +69,20 @@ describe('KavaPlugin', function () { kava._rateHandler.getAverage().should.equal(0); }); + it('should change screen mode on enter and exit fullscreen', () => { + setupPlayer(config); + kava = getKavaPlugin(); + kava._model.getScreenMode().should.equal(ScreenMode.NOT_IN_FULLSCREEN); + player.addEventListener(player.Event.ENTER_FULLSCREEN, () => { + kava._model.getScreenMode().should.equal(ScreenMode.FULLSCREEN); + }); + player.addEventListener(player.Event.EXIT_FULLSCREEN, () => { + kava._model.getScreenMode().should.equal(ScreenMode.NOT_IN_FULLSCREEN); + }); + player.enterFullscreen(); + player.exitFullscreen(); + }); + it('should reset kava plugin correctly', () => { setupPlayer(config); kava = getKavaPlugin(); @@ -778,6 +792,7 @@ describe('KavaPlugin', function () { 'referrer', 'sessionId', 'soundMode', + 'screenMode', 'tabMode', 'networkConnectionType', 'userId' From a183deee2ab8486120502f2c700e671e2b1ede39 Mon Sep 17 00:00:00 2001 From: "yuval.keidar" Date: Thu, 13 Aug 2020 13:00:45 +0300 Subject: [PATCH 3/3] fix types --- src/kava-model.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/kava-model.js b/src/kava-model.js index 1300f869..1d77c467 100644 --- a/src/kava-model.js +++ b/src/kava-model.js @@ -10,7 +10,7 @@ import {getEventModel} from './kava-event-model'; class KavaModel { sessionStartTime: number; eventIndex: number; - errorPosition: number; + errorPosition: $Values; playTimeSum: number; bufferTime: number; bufferTimeSum: number; @@ -28,9 +28,9 @@ class KavaModel { maxManifestDownloadTime: number = 0; forwardBufferHealth: number; droppedFramesRatio: ?number = null; - soundMode: typeof SoundMode; - tabMode: typeof TabMode; - screenMode: number = ScreenMode.NOT_IN_FULLSCREEN; + soundMode: $Values; + tabMode: $Values; + screenMode: $Values = ScreenMode.NOT_IN_FULLSCREEN; maxNetworkConnectionOverhead: number = 0; flavorParamsId: number = NaN; networkConnectionType: string; @@ -218,7 +218,7 @@ class KavaModel { * @memberof KavaModel * @instance */ - getSoundMode(): typeof SoundMode { + getSoundMode(): $Values { return this.soundMode; } @@ -228,7 +228,7 @@ class KavaModel { * @memberof KavaModel * @instance */ - getScreenMode(): number { + getScreenMode(): $Values { return this.screenMode; } @@ -238,7 +238,7 @@ class KavaModel { * @memberof KavaModel * @instance */ - getTabMode(): typeof TabMode { + getTabMode(): $Values { return this.tabMode; } @@ -317,7 +317,7 @@ class KavaModel { * @memberof KavaModel * @instance */ - getErrorPosition(): number { + getErrorPosition(): $Values { return this.errorPosition; }