Skip to content

Commit

Permalink
fix(FEC-9575): improve jointime calculation (#63)
Browse files Browse the repository at this point in the history
if not preloaded then calc jointime as playing - startload
if preloaded (auto or manual) - calc as playing - play
auto preload is checked in config ('auto'). manual preloaded is true when canplay occured before the first play
  • Loading branch information
RoyBregman authored Jan 5, 2020
1 parent 0dc3334 commit c441a0e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Kava extends BasePlugin {
_performanceEntries: window.PerformanceEntry[] = [];
_pendingFragLoadedUrls: string[] = [];
_fragLoadedFiredOnce: boolean = false;
_canPlayOccured: boolean = false;
_isManualPreload: boolean = false;

/**
* Default config of the plugin.
Expand Down Expand Up @@ -232,6 +234,8 @@ class Kava extends BasePlugin {
PLAY_REACHED_75_PERCENT: false,
PLAY_REACHED_100_PERCENT: false
};
this._canPlayOccured = false;
this._isManualPreload = false;
}

_resetSession(): void {
Expand Down Expand Up @@ -466,8 +470,10 @@ class Kava extends BasePlugin {
this._updateSoundModeInModel();
this._timer.start();
this._isFirstPlay = false;
const playRequestStartTime =
this.player.config.playback.preload === 'auto' || this._isManualPreload ? this._firstPlayRequestTime : this._loadStartTime;
this._model.updateModel({
joinTime: Kava._getTimeDifferenceInSeconds(this._firstPlayRequestTime)
joinTime: Kava._getTimeDifferenceInSeconds(playRequestStartTime)
});
this._sendAnalytics(KavaEventModel.PLAY);
this._onReport();
Expand All @@ -483,12 +489,16 @@ class Kava extends BasePlugin {
}

_onCanPlay(): void {
this._canPlayOccured = true;
this._model.updateModel({
canPlayTime: Kava._getTimeDifferenceInSeconds(this._loadStartTime)
});
}

_onFirstPlay(): void {
if (this._canPlayOccured) {
this._isManualPreload = true;
}
this._firstPlayRequestTime = Date.now();
this._sendAnalytics(KavaEventModel.PLAY_REQUEST);
}
Expand Down

0 comments on commit c441a0e

Please sign in to comment.