Skip to content

Commit

Permalink
feat(FEC-9343): add playback rate change event (#50)
Browse files Browse the repository at this point in the history
* feat(FEC-9343): add playback rate change event

* adding docs and unit tests
  • Loading branch information
RoyBregman authored Oct 7, 2019
1 parent ee5c3e3 commit 79a93cc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/kava-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Here you can see the list of all available KAVA Events:
- [`FLAVOR_SWITCH`](#flavourSwitchEvent)
- [`AUDIO_SELECTED`](#audioSelectedEvent)
- [`CAPTIONS`](#captionsEvent)
- [`SPEED`](#speedEvent)
- [`ERROR`](#errorEvent)

## KAVA Events Documentation:
Expand Down Expand Up @@ -191,6 +192,16 @@ No matter if by seeking or regular playback.

---

<a id="speedEvent"></a>`SPEED` - Sent when playback rate has changed.

- Event ID: `41`
- Player Event: `RATE_CHANGE`
- Event Parameters:
- [`COMMON_PARAMS`](./kava-parameters.md#common_params)
- [`playbackSpeed`](./kava-parameters.md#playbackSpeed)

---

<a id="errorEvent"></a>`ERROR` - Sent when error occurs. (Player ERROR event received).

- Event ID: `98`
Expand Down
4 changes: 4 additions & 0 deletions docs/kava-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ Kava parameters are additional data that is sent with Kava event and represent r

---

<a id="playbackSpeed"></a>`playbackSpeed` - the playback speed rate.

---

## <a id="common_params"></a>Common Parameters

The common parameters are parameters which are sent in any Kava event.
Expand Down
11 changes: 11 additions & 0 deletions src/kava-event-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ export const KavaEventModel: {[event: string]: KavaEvent} = {
actualBitrate: model.getActualBitrate()
})
},
/**
* @type {string} SPEED
* @memberof KavaEventType
*/
SPEED: {
type: 'SPEED',
index: 41,
getEventModel: (model: KavaModel) => ({
playbackSpeed: model.getPlaybackSpeed()
})
},
/**
* @type {string} CAPTIONS
* @memberof KavaEventType
Expand Down
1 change: 1 addition & 0 deletions src/kava-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class KavaModel {
networkConnectionType: string;
playerJSLoadTime: ?number = null;
getActualBitrate: Function;
getPlaybackSpeed: Function;
getAverageBitrate: Function;
getPartnerId: Function;
getEntryId: Function;
Expand Down
6 changes: 6 additions & 0 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class Kava extends BasePlugin {
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));
this.eventManager.listen(this.player, this.player.Event.RATE_CHANGE, () => this._onPlaybackRateChanged());
this.eventManager.listen(this.player, this.player.Event.CAN_PLAY, () => this._onCanPlay());
this.eventManager.listen(this.player, this.player.Event.LOAD_START, () => this._onLoadStart());
}
Expand Down Expand Up @@ -616,6 +617,10 @@ class Kava extends BasePlugin {
}
}

_onPlaybackRateChanged(): void {
this._sendAnalytics(KavaEventModel.SPEED);
}

_onPlayerStateChanged(event: FakeEvent): void {
const oldState = event.payload.oldState;
const newState = event.payload.newState;
Expand Down Expand Up @@ -665,6 +670,7 @@ class Kava extends BasePlugin {
}

_setModelDelegates() {
this._model.getPlaybackSpeed = () => this.player.playbackRate;
this._model.getActualBitrate = () => this._rateHandler.getCurrent();
this._model.getAverageBitrate = () => this._rateHandler.getAverage();
this._model.getPartnerId = () => this.config.partnerId;
Expand Down
10 changes: 10 additions & 0 deletions test/src/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class FakeModel {
getFlavorParamsId() {
return 32;
}

getPlaybackSpeed() {
return 2;
}
}

describe('KavaEventModel', () => {
Expand Down Expand Up @@ -263,4 +267,10 @@ describe('KavaEventModel', () => {
KavaEventModel.BUFFER_END.index.should.equal(46);
KavaEventModel.BUFFER_END.getEventModel(fakeModel).should.deep.equal({});
});

it('SPEED', () => {
KavaEventModel.SPEED.type.should.equal('SPEED');
KavaEventModel.SPEED.index.should.equal(41);
KavaEventModel.SPEED.getEventModel(fakeModel).should.deep.equal({playbackSpeed: 2});
});
});
13 changes: 13 additions & 0 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,19 @@ describe('KavaPlugin', function() {
}
});
});
it('should send SPEED event', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
if (params.eventType === KavaEventModel.SPEED.index) {
validateCommonParams(params, KavaEventModel.SPEED.index);
params.playbackSpeed.should.equal(1);
done();
}
return new RequestBuilder();
});
setupPlayer(config);
kava = getKavaPlugin();
kava._onPlaybackRateChanged();
});
});

describe('Server Response', () => {
Expand Down

0 comments on commit 79a93cc

Please sign in to comment.