From 288a57a61ccbcd05bfcbb81ff4522da753cc1ff9 Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Mon, 4 Nov 2019 10:41:29 +0200 Subject: [PATCH 1/6] feat(FEC-9220): QoE tidbits --- src/kava.js | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/kava.js b/src/kava.js index 032fa7a7..23840892 100644 --- a/src/kava.js +++ b/src/kava.js @@ -37,6 +37,8 @@ class Kava extends BasePlugin { _performanceEntries: window.PerformanceEntry[] = []; _pendingFragLoadedUrls: string[] = []; _fragLoadedFiredOnce: boolean = false; + _hiddenAttr: string; + _visibilityChangeEventName: string; /** * Default config of the plugin. @@ -87,6 +89,15 @@ class Kava extends BasePlugin { this._model.updateModel({playerJSLoadTime: entry.duration}); } } + + this._updateSoundModeInModel(); + this._initTabMode(); + } + + _updateSoundModeInModel() { + this._model.updateModel({ + soundMode: this.player.muted || this.player.volume === 0 ? SoundMode.SOUND_OFF : SoundMode.SOUND_ON + }); } _handleNewPerformanceEntries(list: window.PerformanceObserverEntryList) { @@ -291,6 +302,8 @@ class Kava extends BasePlugin { this.eventManager.listen(this.player, this.player.Event.RATE_CHANGE, () => this._onPlaybackRateChanged()); this.eventManager.listen(this.player, this.player.Event.CAN_PLAY, () => this._onCanPlay()); 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()); } _onFirstPlaying(): void { @@ -424,8 +437,6 @@ class Kava extends BasePlugin { if (this._viewEventEnabled) { this._updatePlayTimeSumModel(); this._model.updateModel({ - soundMode: this.player.muted || this.player.volume === 0 ? SoundMode.SOUND_OFF : SoundMode.SOUND_ON, - tabMode: this._isDocumentHidden() ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED, forwardBufferHealth: this._getForwardBufferHealth(), targetBuffer: this._getTargetBuffer(), droppedFramesRatio: this._getDroppedFramesRatio(), @@ -746,20 +757,30 @@ class Kava extends BasePlugin { return (Date.now() - time) / 1000.0; } - _isDocumentHidden(): boolean { - let hidden = ''; + _updateTabModeinModel(): void { + this._model.updateModel({ + // $FlowFixMe + tabMode: document[this._hiddenAttr] ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED + }); + } + + _initTabMode(): void { if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support - hidden = 'hidden'; + this._hiddenAttr = 'hidden'; + this._visibilityChangeEventName = 'visibilitychange'; } else if (typeof document.msHidden !== 'undefined') { - hidden = 'msHidden'; + this._hiddenAttr = 'msHidden'; + this._visibilityChangeEventName = 'msvisibilitychange'; } else if (typeof document.webkitHidden !== 'undefined') { - hidden = 'webkitHidden'; - } else { - return false; + this._hiddenAttr = 'webkitHidden'; + this._visibilityChangeEventName = 'webkitvisibilitychange'; + } + + if (this._hiddenAttr !== 'undefined') { + document.addEventListener(this._visibilityChangeEventName, this._updateTabModeinModel.bind(this)); + this._updateTabModeinModel(); } - // $FlowFixMe - return document[hidden]; } } From 78b2f88ca66cbe6a841f2b3ca07f3c4332e0efc1 Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Mon, 4 Nov 2019 13:29:51 +0200 Subject: [PATCH 2/6] updating netConnectionType through event --- src/kava.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/kava.js b/src/kava.js index 23840892..af2d36fb 100644 --- a/src/kava.js +++ b/src/kava.js @@ -39,6 +39,7 @@ class Kava extends BasePlugin { _fragLoadedFiredOnce: boolean = false; _hiddenAttr: string; _visibilityChangeEventName: string; + _navConnection: any; /** * Default config of the plugin. @@ -92,6 +93,7 @@ class Kava extends BasePlugin { this._updateSoundModeInModel(); this._initTabMode(); + this._initNetworkConnectionType(); } _updateSoundModeInModel() { @@ -427,20 +429,13 @@ class Kava extends BasePlugin { } } - _getNetworkConnectionType(): string { - return window.navigator && window.navigator.connection && window.navigator.connection.effectiveType - ? window.navigator.connection.effectiveType - : ''; - } - _onReport(): void { if (this._viewEventEnabled) { this._updatePlayTimeSumModel(); this._model.updateModel({ forwardBufferHealth: this._getForwardBufferHealth(), targetBuffer: this._getTargetBuffer(), - droppedFramesRatio: this._getDroppedFramesRatio(), - networkConnectionType: this._getNetworkConnectionType() + droppedFramesRatio: this._getDroppedFramesRatio() }); this._sendAnalytics(KavaEventModel.VIEW); } else { @@ -456,6 +451,21 @@ class Kava extends BasePlugin { }); } + _updateNetworkConnectionTypeinModel(): void { + this._model.updateModel({ + networkConnectionType: this._navConnection.effectiveType + }); + } + + _initNetworkConnectionType(): void { + this._navConnection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection; + + if (this._navConnection) { + this._navConnection.addEventListener('change', this._updateNetworkConnectionTypeinModel.bind(this)); + this._updateNetworkConnectionTypeinModel(); + } + } + _onPlaying(): void { if (this._isFirstPlay) { this._timer.start(); From 95647ddad4ef0771da32a7a9ca03737222c5e672 Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Mon, 4 Nov 2019 17:07:19 +0200 Subject: [PATCH 3/6] removed unused code --- src/kava.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/kava.js b/src/kava.js index af2d36fb..5bd845f3 100644 --- a/src/kava.js +++ b/src/kava.js @@ -471,8 +471,7 @@ class Kava extends BasePlugin { this._timer.start(); this._isFirstPlay = false; this._model.updateModel({ - joinTime: Kava._getTimeDifferenceInSeconds(this._firstPlayRequestTime), - networkConnectionType: this._getNetworkConnectionType() + joinTime: Kava._getTimeDifferenceInSeconds(this._firstPlayRequestTime) }); this._sendAnalytics(KavaEventModel.PLAY); } else if (this._isEnded) { From ad61145b6b7aa5ba09ca2f2dcced5f32639659d6 Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Tue, 5 Nov 2019 09:17:28 +0200 Subject: [PATCH 4/6] soundmode first update should be when first playing --- src/kava.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kava.js b/src/kava.js index 5bd845f3..16000a01 100644 --- a/src/kava.js +++ b/src/kava.js @@ -91,7 +91,6 @@ class Kava extends BasePlugin { } } - this._updateSoundModeInModel(); this._initTabMode(); this._initNetworkConnectionType(); } @@ -468,6 +467,7 @@ class Kava extends BasePlugin { _onPlaying(): void { if (this._isFirstPlay) { + this._updateSoundModeInModel(); this._timer.start(); this._isFirstPlay = false; this._model.updateModel({ From 839fc0493f7d1ed2a5630a541c6569052460816b Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Thu, 7 Nov 2019 18:56:08 +0200 Subject: [PATCH 5/6] after code review with YairAns --- src/kava.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/kava.js b/src/kava.js index 16000a01..c29c6720 100644 --- a/src/kava.js +++ b/src/kava.js @@ -37,9 +37,6 @@ class Kava extends BasePlugin { _performanceEntries: window.PerformanceEntry[] = []; _pendingFragLoadedUrls: string[] = []; _fragLoadedFiredOnce: boolean = false; - _hiddenAttr: string; - _visibilityChangeEventName: string; - _navConnection: any; /** * Default config of the plugin. @@ -90,9 +87,6 @@ class Kava extends BasePlugin { this._model.updateModel({playerJSLoadTime: entry.duration}); } } - - this._initTabMode(); - this._initNetworkConnectionType(); } _updateSoundModeInModel() { @@ -305,6 +299,8 @@ 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._initTabMode(); + this._initNetworkConnectionType(); } _onFirstPlaying(): void { @@ -450,18 +446,18 @@ class Kava extends BasePlugin { }); } - _updateNetworkConnectionTypeinModel(): void { + _updateNetworkConnectionTypeinModel(navConnection: any): void { this._model.updateModel({ - networkConnectionType: this._navConnection.effectiveType + networkConnectionType: navConnection.effectiveType }); } _initNetworkConnectionType(): void { - this._navConnection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection; + const navConnection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection; - if (this._navConnection) { - this._navConnection.addEventListener('change', this._updateNetworkConnectionTypeinModel.bind(this)); - this._updateNetworkConnectionTypeinModel(); + if (navConnection) { + this.eventManager.listen(navConnection, 'change', () => this._updateNetworkConnectionTypeinModel(navConnection)); + this._updateNetworkConnectionTypeinModel(navConnection); } } @@ -766,29 +762,33 @@ class Kava extends BasePlugin { return (Date.now() - time) / 1000.0; } - _updateTabModeinModel(): void { + _updateTabModeinModel(hiddenAttr: string): void { this._model.updateModel({ // $FlowFixMe - tabMode: document[this._hiddenAttr] ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED + tabMode: document[hiddenAttr] ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED }); } _initTabMode(): void { + let hiddenAttr: string; + let visibilityChangeEventName: string; if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support - this._hiddenAttr = 'hidden'; - this._visibilityChangeEventName = 'visibilitychange'; + hiddenAttr = 'hidden'; + visibilityChangeEventName = 'visibilitychange'; } else if (typeof document.msHidden !== 'undefined') { - this._hiddenAttr = 'msHidden'; - this._visibilityChangeEventName = 'msvisibilitychange'; + hiddenAttr = 'msHidden'; + visibilityChangeEventName = 'msvisibilitychange'; } else if (typeof document.webkitHidden !== 'undefined') { - this._hiddenAttr = 'webkitHidden'; - this._visibilityChangeEventName = 'webkitvisibilitychange'; + hiddenAttr = 'webkitHidden'; + visibilityChangeEventName = 'webkitvisibilitychange'; } - if (this._hiddenAttr !== 'undefined') { - document.addEventListener(this._visibilityChangeEventName, this._updateTabModeinModel.bind(this)); - this._updateTabModeinModel(); + if (hiddenAttr && visibilityChangeEventName) { + document.addEventListener(visibilityChangeEventName, () => { + this._updateTabModeinModel(hiddenAttr); + }); + this._updateTabModeinModel(hiddenAttr); } } } From b2e76e45eb7489e302e0779e9a097a54b2679271 Mon Sep 17 00:00:00 2001 From: Roy Bregman Date: Thu, 7 Nov 2019 21:31:20 +0200 Subject: [PATCH 6/6] changing event listening to eventmanager --- src/kava.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/kava.js b/src/kava.js index c29c6720..d1bed9cd 100644 --- a/src/kava.js +++ b/src/kava.js @@ -785,9 +785,7 @@ class Kava extends BasePlugin { } if (hiddenAttr && visibilityChangeEventName) { - document.addEventListener(visibilityChangeEventName, () => { - this._updateTabModeinModel(hiddenAttr); - }); + this.eventManager.listen(document, visibilityChangeEventName, () => this._updateTabModeinModel(hiddenAttr)); this._updateTabModeinModel(hiddenAttr); } }