Skip to content

Commit

Permalink
fix(FEC-8320): SOURCE_SELECTED event triggered on user selection of A…
Browse files Browse the repository at this point in the history
…BR mode (#16)

Remove logic of setting actualBitrate of 0 and trigger SOURCE_SELECTED event when user selected ABR mode.
  • Loading branch information
Dan Ziv authored Jun 14, 2018
1 parent 9f70dc6 commit 3ca02c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
18 changes: 4 additions & 14 deletions src/kava-rate-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
*/
export default class KavaRateHandler {
_rates: Array<Object> = [];
_isSwitchedToAbrMode: boolean = false;

constructor() {
this._rates = [];
this._isSwitchedToAbrMode = false;
}

/**
Expand All @@ -37,14 +35,10 @@ export default class KavaRateHandler {
* @returns {void}
*/
setCurrent(rate: number): void {
if (rate === 0) {
this._isSwitchedToAbrMode = true;
} else {
this._rates.forEach(o => (o.active = false));
const obj = this._rates.find(o => o.rate === rate);
if (obj) {
obj.active = true;
}
this._rates.forEach(o => (o.active = false));
const obj = this._rates.find(o => o.rate === rate);
if (obj) {
obj.active = true;
}
}

Expand All @@ -54,10 +48,6 @@ export default class KavaRateHandler {
* @returns {number} - The current rate.
*/
getCurrent(): number {
if (this._isSwitchedToAbrMode) {
this._isSwitchedToAbrMode = false;
return 0;
}
const current = this._rates.find(o => o.active);
return current ? current.rate : -1;
}
Expand Down
13 changes: 2 additions & 11 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export default class Kava extends BasePlugin {
this.eventManager.listen(this.player, this.player.Event.ENDED, () => this._onEnded());
this.eventManager.listen(this.player, this.player.Event.TIME_UPDATE, () => this._onTimeUpdate());
this.eventManager.listen(this.player, this.player.Event.VIDEO_TRACK_CHANGED, event => this._onVideoTrackChanged(event));
this.eventManager.listen(this.player, this.player.Event.ABR_MODE_CHANGED, event => this._onAbrModeChanged(event));
this.eventManager.listen(this.player, this.player.Event.AUDIO_TRACK_CHANGED, event => this._onAudioTrackChanged(event));
this.eventManager.listen(this.player, this.player.Event.TEXT_TRACK_CHANGED, event => this._onTextTrackChanged(event));
this.eventManager.listen(this.player, this.player.Event.PLAYER_STATE_CHANGED, event => this._onPlayerStateChanged(event));
Expand Down Expand Up @@ -271,17 +270,9 @@ export default class Kava extends BasePlugin {
_onVideoTrackChanged(event: FakeEvent): void {
const videoTrack = event.payload.selectedVideoTrack;
this._rateHandler.setCurrent(videoTrack.bandwidth);
if (!this.player.isAdaptiveBitrateEnabled()) {
this._sendAnalytics(KavaEventModel.SOURCE_SELECTED);
} else {
if (this.player.isAdaptiveBitrateEnabled()) {
this._sendAnalytics(KavaEventModel.FLAVOR_SWITCH);
}
}

_onAbrModeChanged(event: FakeEvent) {
const mode = event.payload.mode;
if (mode === this.player.AbrMode.AUTO) {
this._rateHandler.setCurrent(0);
} else {
this._sendAnalytics(KavaEventModel.SOURCE_SELECTED);
}
}
Expand Down

0 comments on commit 3ca02c8

Please sign in to comment.