Skip to content

Commit

Permalink
feat(FEC-10376): add full screen to screen mode on view events (#79)
Browse files Browse the repository at this point in the history
Fix typing.
Add screen mode in view event:

screenMode=1 (not full screen)
screenMode=2 (full screen)
  • Loading branch information
Yuvalke authored Aug 19, 2020
1 parent 2c3f6e2 commit cd73937
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
30 changes: 23 additions & 7 deletions src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {getEventModel} from './kava-event-model';
class KavaModel {
sessionStartTime: number;
eventIndex: number;
errorPosition: number;
errorPosition: $Values<typeof ErrorPosition>;
playTimeSum: number;
bufferTime: number;
bufferTimeSum: number;
Expand All @@ -28,8 +28,9 @@ class KavaModel {
maxManifestDownloadTime: number = 0;
forwardBufferHealth: number;
droppedFramesRatio: ?number = null;
soundMode: typeof SoundMode;
tabMode: typeof TabMode;
soundMode: $Values<typeof SoundMode>;
tabMode: $Values<typeof TabMode>;
screenMode: $Values<typeof ScreenMode> = ScreenMode.NOT_IN_FULLSCREEN;
maxNetworkConnectionOverhead: number = 0;
flavorParamsId: number = NaN;
networkConnectionType: string;
Expand Down Expand Up @@ -217,17 +218,27 @@ class KavaModel {
* @memberof KavaModel
* @instance
*/
getSoundMode(): typeof SoundMode {
getSoundMode(): $Values<typeof SoundMode> {
return this.soundMode;
}

/**
* Gets the screen mode of the browser player.
* @returns {number} the state of the full screen if is on or not.
* @memberof KavaModel
* @instance
*/
getScreenMode(): $Values<typeof ScreenMode> {
return this.screenMode;
}

/**
* Gets the Tab mode of the browser.
* @returns {TabMode} the state of the tab (focused or not)
* @memberof KavaModel
* @instance
*/
getTabMode(): typeof TabMode {
getTabMode(): $Values<typeof TabMode> {
return this.tabMode;
}

Expand Down Expand Up @@ -306,7 +317,7 @@ class KavaModel {
* @memberof KavaModel
* @instance
*/
getErrorPosition(): number {
getErrorPosition(): $Values<typeof ErrorPosition> {
return this.errorPosition;
}

Expand Down Expand Up @@ -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};
6 changes: 5 additions & 1 deletion src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions test/src/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class FakeModel {
return 1;
}

getScreenMode() {
return 1;
}

getAvailableBuffer() {
return 2;
}
Expand Down Expand Up @@ -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(),
Expand Down
17 changes: 16 additions & 1 deletion test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -778,6 +792,7 @@ describe('KavaPlugin', function () {
'referrer',
'sessionId',
'soundMode',
'screenMode',
'tabMode',
'networkConnectionType',
'userId'
Expand Down

0 comments on commit cd73937

Please sign in to comment.