Skip to content

Commit

Permalink
fix(FEC-8415): kava should report bitrate in kbps (#21)
Browse files Browse the repository at this point in the history
convert bps to kbps unit for reporting bitrate.
  • Loading branch information
OrenMe authored Jul 18, 2018
1 parent 5d52ca9 commit fc52347
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import {KavaRateHandler} from './kava-rate-handler';
import {KavaTimer} from './kava-timer';
import {KavaModel} from './kava-model';

/**
* The bps to kbps divsor
* @type {number}
* @const
*/
const DIVIDER: number = 1024;

/**
* KAVA (Kaltura Advanced Analytics) plugin class.
* @constructor
Expand Down Expand Up @@ -174,7 +181,7 @@ class Kava extends BasePlugin {
_getRates(): Array<number> {
const rates = [];
const videoTracks = this.player.getTracks(this.player.Track.VIDEO);
videoTracks.forEach(videoTrack => rates.push(videoTrack.bandwidth));
videoTracks.forEach(videoTrack => rates.push(videoTrack.bandwidth / DIVIDER));
return rates;
}

Expand All @@ -183,7 +190,7 @@ class Kava extends BasePlugin {
const activeTracks = this.player.getActiveTracks();
this._rateHandler.setRates(rates);
if (activeTracks.video) {
this._rateHandler.setCurrent(activeTracks.video.bandwidth);
this._rateHandler.setCurrent(activeTracks.video.bandwidth / DIVIDER);
}
if (activeTracks.audio) {
this._model.updateModel({language: activeTracks.audio.language});
Expand Down Expand Up @@ -274,7 +281,7 @@ class Kava extends BasePlugin {

_onVideoTrackChanged(event: FakeEvent): void {
const videoTrack = event.payload.selectedVideoTrack;
this._rateHandler.setCurrent(videoTrack.bandwidth);
this._rateHandler.setCurrent(videoTrack.bandwidth / DIVIDER);
if (this.player.isAdaptiveBitrateEnabled()) {
this._sendAnalytics(KavaEventModel.FLAVOR_SWITCH);
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('KavaPlugin', function() {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.SOURCE_SELECTED.index) return;
validateCommonParams(params, KavaEventModel.SOURCE_SELECTED.index);
params.actualBitrate.should.equal(480256);
params.actualBitrate.should.equal(480256 / 1024);
done();
return new RequestBuilder();
});
Expand All @@ -348,7 +348,7 @@ describe('KavaPlugin', function() {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType !== KavaEventModel.FLAVOR_SWITCH.index) return;
validateCommonParams(params, KavaEventModel.FLAVOR_SWITCH.index);
params.actualBitrate.should.equal(480256);
params.actualBitrate.should.equal(480256 / 1024);
done();
return new RequestBuilder();
});
Expand Down

0 comments on commit fc52347

Please sign in to comment.