Skip to content

Commit

Permalink
fix(FEC-9269): networkConnectionType is missing in PLAY event (#47)
Browse files Browse the repository at this point in the history
added networkConnectionType to play event (3)
  • Loading branch information
RoyBregman authored Jul 30, 2019
1 parent e9f0e4e commit 248693f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
20 changes: 13 additions & 7 deletions src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
PLAY: {
type: 'PLAY',
index: 3,
getEventModel: (model: KavaModel) => ({
bufferTime: model.getBufferTime(),
bufferTimeSum: model.getBufferTimeSum(),
actualBitrate: model.getActualBitrate(),
joinTime: model.getJoinTime(),
canPlay: model.getCanPlayTime()
})
getEventModel: (model: KavaModel) => {
const eventModel: {[name: string]: any} = {
bufferTime: model.getBufferTime(),
bufferTimeSum: model.getBufferTimeSum(),
actualBitrate: model.getActualBitrate(),
joinTime: model.getJoinTime(),
canPlay: model.getCanPlayTime()
};
if (model.getNetworkConnectionType() !== '') {
eventModel.networkConnectionType = model.getNetworkConnectionType();
}
return eventModel;
}
},
/**
* @type {string} RESUME
Expand Down
14 changes: 9 additions & 5 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ class Kava extends BasePlugin {
}
}

_getNetworkConnectionType(): string {
return window.navigator && window.navigator.connection && window.navigator.connection.effectiveType
? window.navigator.connection.effectiveType
: '';
}

_onReport(): void {
if (this._viewEventEnabled) {
this._updatePlayTimeSumModel();
Expand All @@ -422,10 +428,7 @@ class Kava extends BasePlugin {
forwardBufferHealth: this._getForwardBufferHealth(),
targetBuffer: this._getTargetBuffer(),
droppedFramesRatio: this._getDroppedFramesRatio(),
networkConnectionType:
window.navigator && window.navigator.connection && window.navigator.connection.effectiveType
? window.navigator.connection.effectiveType
: ''
networkConnectionType: this._getNetworkConnectionType()
});
this._sendAnalytics(KavaEventModel.VIEW);
} else {
Expand All @@ -446,7 +449,8 @@ class Kava extends BasePlugin {
this._timer.start();
this._isFirstPlay = false;
this._model.updateModel({
joinTime: Kava._getTimeDifferenceInSeconds(this._firstPlayRequestTime)
joinTime: Kava._getTimeDifferenceInSeconds(this._firstPlayRequestTime),
networkConnectionType: this._getNetworkConnectionType()
});
this._sendAnalytics(KavaEventModel.PLAY);
} else if (this._isEnded) {
Expand Down
3 changes: 2 additions & 1 deletion test/src/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ describe('KavaEventModel', () => {
bufferTimeSum: fakeModel.getBufferTimeSum(),
actualBitrate: fakeModel.getActualBitrate(),
joinTime: fakeModel.getJoinTime(),
canPlay: fakeModel.getCanPlayTime()
canPlay: fakeModel.getCanPlayTime(),
networkConnectionType: fakeModel.getNetworkConnectionType()
});
});

Expand Down
1 change: 1 addition & 0 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ describe('KavaPlugin', function() {
params.bufferTimeSum.should.exist;
params.actualBitrate.should.exist;
params.joinTime.should.exist;
params.networkConnectionType.should.exist;
done();
}
return new RequestBuilder();
Expand Down

0 comments on commit 248693f

Please sign in to comment.