Skip to content

Commit

Permalink
feat(FEC-9139): adding flavorParamsId (#37)
Browse files Browse the repository at this point in the history
* feat(FEC-9139): adding flavorParamsId
  • Loading branch information
RoyBregman authored Jun 30, 2019
1 parent 69c863e commit 0817b70
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
if (model.getNetworkConnectionOverhead()) {
eventModel.networkConnectionOverhead = model.getNetworkConnectionOverhead();
}
if (!isNaN(model.getFlavorParamsId())) {
eventModel.flavorParamsId = model.getFlavorParamsId();
}

return eventModel;
}
Expand Down
11 changes: 11 additions & 0 deletions src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KavaModel {
soundMode: typeof SoundMode;
tabMode: typeof TabMode;
maxNetworkConnectionOverhead: number = 0;
flavorParamsId: number = NaN;
networkConnectionType: string;
playerJSLoadTime: ?number = null;
getActualBitrate: Function;
Expand Down Expand Up @@ -257,6 +258,16 @@ class KavaModel {
return this.errorCode;
}

/**
* Gets the flavor id from ID3 tag in the packager
* @returns {number} - The flavor id.
* @memberof KavaModel
* @instance
*/
getFlavorParamsId(): number {
return this.flavorParamsId;
}

/**
* Gets the error additional data.
* @returns {string} - The stringifyed error data.
Expand Down
15 changes: 14 additions & 1 deletion src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {KavaTimer} from './kava-timer';
import {KavaModel, SoundMode, TabMode} from './kava-model';

const DIVIDER: number = 1024;
const ID3_TRACK_LABEL: string = 'id3';

/**
* Kaltura Advanced Analytics plugin.
Expand Down Expand Up @@ -240,6 +241,7 @@ class Kava extends BasePlugin {
this.eventManager.listen(this.player, this.player.Event.FIRST_PLAY, () => this._onFirstPlay());
this.eventManager.listen(this.player, this.player.Event.FRAG_LOADED, event => this._onFragLoaded(event));
this.eventManager.listen(this.player, this.player.Event.MANIFEST_LOADED, event => this._onManifestLoaded(event));
this.eventManager.listen(this.player, this.player.Event.TIMED_METADATA, event => this._onTimedMetadataLoaded(event));
this.eventManager.listen(this.player, this.player.Event.TRACKS_CHANGED, () => this._setInitialTracks());
this.eventManager.listen(this.player, this.player.Event.PLAYING, () => this._onPlaying());
this.eventManager.listen(this.player, this.player.Event.FIRST_PLAYING, () => this._onFirstPlaying());
Expand Down Expand Up @@ -487,7 +489,7 @@ class Kava extends BasePlugin {
maxSegmentDownloadTime: Math.max(seconds, this._model.maxSegmentDownloadTime),
maxNetworkConnectionOverhead: lastFragResourceTiming
? Math.max(this._model.maxNetworkConnectionOverhead, lastFragResourceTiming.connectEnd - lastFragResourceTiming.domainLookupStart)
: 0
: this._model.maxNetworkConnectionOverhead
});
}

Expand All @@ -498,6 +500,17 @@ class Kava extends BasePlugin {
});
}

_onTimedMetadataLoaded(event: FakeEvent): void {
const id3TagCues = event.payload.cues.filter(entry => entry.track && entry.track.label === ID3_TRACK_LABEL);
if (id3TagCues.length) {
try {
this._model.updateModel({flavorParamsId: Number(JSON.parse(id3TagCues[id3TagCues.length - 1].value.data).sequenceId)});
} catch (e) {
this.logger.debug('error parsing id3', e);
}
}
}

_onVideoTrackChanged(event: FakeEvent): void {
const videoTrack = event.payload.selectedVideoTrack;
this._rateHandler.setCurrent(videoTrack.bandwidth / DIVIDER);
Expand Down
7 changes: 6 additions & 1 deletion test/src/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class FakeModel {
getNetworkConnectionOverhead() {
return '0.12';
}

getFlavorParamsId() {
return 32;
}
}

describe('KavaEventModel', () => {
Expand All @@ -121,7 +125,8 @@ describe('KavaEventModel', () => {
forwardBufferHealth: fakeModel.getForwardBufferHealth(),
targetBuffer: fakeModel.getTargetBuffer(),
networkConnectionType: fakeModel.getNetworkConnectionType(),
networkConnectionOverhead: fakeModel.getNetworkConnectionOverhead()
networkConnectionOverhead: fakeModel.getNetworkConnectionOverhead(),
flavorParamsId: fakeModel.getFlavorParamsId()
});
});

Expand Down
60 changes: 57 additions & 3 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,36 @@ describe('KavaPlugin', function() {
player.play();
});

it('should send VIEW event with manifest download time, segment download time and bandwidth', done => {
it('should send VIEW event with manifest download time, segment download time, bandwidth, networkConnectionOverhead', done => {
sandbox.stub(window.performance, 'getEntriesByType').callsFake(() => {
return [
{
name: 'http://www.somesite.com/movie.ts',
entryType: 'resource',
startTime: 118.6400000001413,
duration: 149.8900000001413,
initiatorType: 'script',
nextHopProtocol: 'http/1.1',
workerStart: 0,
redirectStart: 0,
redirectEnd: 0,
fetchStart: 118.6400000001413,
domainLookupStart: 20.2,
domainLookupEnd: 0,
connectStart: 0,
connectEnd: 120.5,
secureConnectionStart: 0,
requestStart: 0,
responseStart: 0,
responseEnd: 268.5300000002826,
transferSize: 0,
encodedBodySize: 0,
decodedBodySize: 0,
serverTiming: []
}
];
});

const DUMMY_MANIFEST_DOWNLOAD_TIME = 57;
const FRAG1_DOWNLOAD_TIME = 100;
const FRAG2_DOWNLOAD_TIME = 20;
Expand All @@ -531,16 +560,41 @@ describe('KavaPlugin', function() {
const TOTAL_SECONDS = (FRAG1_DOWNLOAD_TIME + FRAG2_DOWNLOAD_TIME) / 1000;
params.bandwidth.should.equal(Math.round(((FRAG1_BYTES + FRAG2_BYTES) * 8) / TOTAL_SECONDS) / 1000);
params.segmentDownloadTime.should.equal(FRAG1_DOWNLOAD_TIME / 1000);
params.networkConnectionOverhead.should.equal(0.1);
params.flavorParamsId.should.equal(36);
done();
}
return new RequestBuilder();
});
setupPlayer(config);
kava = getKavaPlugin();
player.play();
player.dispatchEvent(
new FakeEvent(CustomEventType.TIMED_METADATA, {
cues: [
{
value: {
key: 'TEXT',
data: '{"timestamp":1561448342872,"sequenceId":"36"}'
},
track: {
label: 'id3'
}
}
]
})
);
player.dispatchEvent(new FakeEvent(CustomEventType.MANIFEST_LOADED, {miliSeconds: DUMMY_MANIFEST_DOWNLOAD_TIME}));
player.dispatchEvent(new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG1_DOWNLOAD_TIME, bytes: FRAG1_BYTES}));
player.dispatchEvent(new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG2_DOWNLOAD_TIME, bytes: FRAG2_BYTES}));
player.dispatchEvent(
new FakeEvent(CustomEventType.FRAG_LOADED, {
miliSeconds: FRAG1_DOWNLOAD_TIME,
bytes: FRAG1_BYTES,
url: 'http://www.somesite.com/movie.ts'
})
);
player.dispatchEvent(
new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG2_DOWNLOAD_TIME, bytes: FRAG2_BYTES, url: 'http://www.somesite.com/movie2.ts'})
);
});

it('should send VIEW event with volume set to 0', done => {
Expand Down

0 comments on commit 0817b70

Please sign in to comment.