Skip to content

Commit

Permalink
feat(FEC-8975): adding QoS Data to enhance KAVA (#35)
Browse files Browse the repository at this point in the history
Adding Bandwidth, segment download time, soundMode and tabMode to 99 view report
  • Loading branch information
RoyBregman authored and OrenMe committed Jun 16, 2019
1 parent 67ca77e commit e1e4eda
Show file tree
Hide file tree
Showing 7 changed files with 563 additions and 94 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"access": "public"
},
"devDependencies": {
"@playkit-js/playkit-js": "^0.37.0",
"@playkit-js/playkit-js": "^0.47.0",
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-eslint": "^7.1.1",
Expand Down
52 changes: 42 additions & 10 deletions src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,41 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
VIEW: {
type: 'VIEW',
index: 99,
getEventModel: (model: KavaModel) => ({
playTimeSum: model.getPlayTimeSum(),
bufferTime: model.getBufferTime(),
bufferTimeSum: model.getBufferTimeSum(),
actualBitrate: model.getActualBitrate(),
averageBitrate: model.getAverageBitrate(),
audioLanguage: model.getLanguage(),
captionsLanguage: model.getCaption()
})
getEventModel: (model: KavaModel) => {
const eventModel: {[name: string]: any} = {
playTimeSum: model.getPlayTimeSum(),
bufferTime: model.getBufferTime(),
bufferTimeSum: model.getBufferTimeSum(),
actualBitrate: model.getActualBitrate(),
averageBitrate: model.getAverageBitrate(),
audioLanguage: model.getLanguage(),
captionsLanguage: model.getCaption(),
soundMode: model.getSoundMode(),
tabMode: model.getTabMode()
};

if (!isNaN(model.getForwardBufferHealth())) {
eventModel.forwardBufferHealth = model.getForwardBufferHealth();
}
if (model.getMaxManifestDownloadTime() > 0) {
eventModel.manifestDownloadTime = model.getMaxManifestDownloadTime();
}
if (model.getSegmentDownloadTime() > 0) {
eventModel.segmentDownloadTime = model.getSegmentDownloadTime();
}
if (model.getBandwidth()) {
eventModel.bandwidth = model.getBandwidth();
}
if (model.getDroppedFramesRatio() != null) {
eventModel.droppedFramesRatio = model.getDroppedFramesRatio();
}

if (!isNaN(model.getTargetBuffer())) {
eventModel.targetBuffer = model.getTargetBuffer();
}

return eventModel;
}
},
/**
* @type {string} IMPRESSION
Expand All @@ -30,7 +56,13 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
IMPRESSION: {
type: 'IMPRESSION',
index: 1,
getEventModel: () => ({})
getEventModel: (model: KavaModel) => {
const eventModel = {};
if (model.getPlayerJSLoadTime() != null) {
eventModel.playerJSLoadTime = model.getPlayerJSLoadTime();
}
return eventModel;
}
},
/**
* @type {string} PLAY_REQUEST
Expand Down
115 changes: 114 additions & 1 deletion src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class KavaModel {
joinTime: number;
canPlayTime: number;
targetPosition: number;
targetBuffer: number;
totalSegmentsDownloadTime: number = 0;
totalSegmentsDownloadBytes: number = 0;
maxSegmentDownloadTime: number = 0;
maxManifestDownloadTime: number = 0;
forwardBufferHealth: number;
droppedFramesRatio: ?number = null;
soundMode: typeof SoundMode;
tabMode: typeof TabMode;
playerJSLoadTime: ?number = null;
getActualBitrate: Function;
getAverageBitrate: Function;
getPartnerId: Function;
Expand Down Expand Up @@ -81,6 +91,20 @@ class KavaModel {
return this.bufferTimeSum;
}

/**
* Gets the player bundle js load duration time
* @returns {number} - The player js load duration time
* @memberof KavaModel
* @instance
*/
getPlayerJSLoadTime(): ?number {
if (this.playerJSLoadTime) {
return Math.round(this.playerJSLoadTime * 1000) / 1000;
} else {
return null;
}
}

/**
* Gets the join time.
* @returns {number} - The join time.
Expand All @@ -101,6 +125,16 @@ class KavaModel {
return this.targetPosition;
}

/**
* Gets the target buffer
* @returns {number} - The target buffer in seconds.
* @memberof KavaModel
* @instance
*/
getTargetBuffer(): number {
return this.targetBuffer;
}

/**
* Gets an audio language.
* @returns {string} - The audio language.
Expand All @@ -121,6 +155,75 @@ class KavaModel {
return this.caption;
}

/**
* Gets the average bandwidth since last report.
* @returns {number} - The bandwidth in kbps
* @memberof KavaModel
* @instance
*/
getBandwidth(): number {
return this.totalSegmentsDownloadTime > 0 ? Math.round((this.totalSegmentsDownloadBytes * 8) / this.totalSegmentsDownloadTime) / 1000 : 0;
}

/**
* Returns the longest manifest download time in seconds
* @returns {number} - manifest max download time in seconds
* @memberof KavaModel
* @instance
*/
getMaxManifestDownloadTime(): number {
return this.maxManifestDownloadTime;
}

/**
* Returns the longest segment download time in seconds
* @returns {number} - segment max download time in seconds
* @memberof KavaModel
* @instance
*/
getSegmentDownloadTime(): number {
return this.maxSegmentDownloadTime;
}

/**
* Gets the forward buffer health ratio.
* @returns {number} - the ratio between the available buffer and the target buffer
* @memberof KavaModel
* @instance
*/
getForwardBufferHealth(): number {
return this.forwardBufferHealth;
}
/**
* Gets the dropped frames ratio since last view event.
* @returns {number} - dropped frames ratio since last view event
* @memberof KavaModel
* @instance
*/
getDroppedFramesRatio(): ?number {
return this.droppedFramesRatio;
}

/**
* Gets the sound mode of the player.
* @returns {SoundMode} the state of the sound (muted ot not)
* @memberof KavaModel
* @instance
*/
getSoundMode(): typeof SoundMode {
return this.soundMode;
}

/**
* Gets the Tab mode of the browser.
* @returns {TabMode} the state of the tab (focused or not)
* @memberof KavaModel
* @instance
*/
getTabMode(): typeof TabMode {
return this.tabMode;
}

/**
* Gets the error code.
* @returns {number} - The error code.
Expand Down Expand Up @@ -192,4 +295,14 @@ class KavaModel {
}
}

export {KavaModel};
const SoundMode = {
SOUND_OFF: 1,
SOUND_ON: 2
};

const TabMode = {
TAB_NOT_FOCUSED: 1,
TAB_FOCUSED: 2
};

export {KavaModel, SoundMode, TabMode};
Loading

0 comments on commit e1e4eda

Please sign in to comment.