Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-10376): add full screen to screen mode on view events #79

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 17 additions & 1 deletion src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KavaModel {
droppedFramesRatio: ?number = null;
soundMode: typeof SoundMode;
tabMode: typeof TabMode;
screenMode: number = ScreenMode.NOT_IN_FULLSCREEN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxNetworkConnectionOverhead: number = 0;
flavorParamsId: number = NaN;
networkConnectionType: string;
Expand Down Expand Up @@ -221,6 +222,16 @@ class KavaModel {
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(): number {
return this.screenMode;
}

/**
* Gets the Tab mode of the browser.
* @returns {TabMode} the state of the tab (focused or not)
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