From a3ea781b27c29ac1f24ced0be7a3e92fc47bb8e0 Mon Sep 17 00:00:00 2001 From: Dan Ziv Date: Wed, 14 Nov 2018 15:55:25 +0200 Subject: [PATCH 1/3] FEC-8657 --- docs/configuration-api.md | 202 ++++++++++++++++++++------------------ src/kava-event-model.js | 18 ++++ src/kava.js | 2 + 3 files changed, 127 insertions(+), 95 deletions(-) diff --git a/docs/configuration-api.md b/docs/configuration-api.md index 95d0b129..5f31c111 100644 --- a/docs/configuration-api.md +++ b/docs/configuration-api.md @@ -15,47 +15,49 @@ - [PLAY][11] - [RESUME][12] - [PAUSE][13] - - [REPLAY][14] - - [SEEK][15] - - [PLAY_REACHED_25_PERCENT][16] - - [PLAY_REACHED_50_PERCENT][17] - - [PLAY_REACHED_75_PERCENT][18] - - [PLAY_REACHED_100_PERCENT][19] - - [SOURCE_SELECTED][20] - - [AUDIO_SELECTED][21] - - [FLAVOR_SWITCH][22] - - [CAPTIONS][23] - - [ERROR][24] -- [Kava][25] - - [Parameters][26] - - [destroy][27] - - [reset][28] - - [getEventModel][29] - - [Parameters][30] - - [Examples][31] - - [EventType][32] - - [sendAnalytics][33] - - [Parameters][34] - - [Examples][35] - - [defaultConfig][36] - - [isValid][37] + - [BUFFER_START][14] + - [BUFFER_END][15] + - [REPLAY][16] + - [SEEK][17] + - [PLAY_REACHED_25_PERCENT][18] + - [PLAY_REACHED_50_PERCENT][19] + - [PLAY_REACHED_75_PERCENT][20] + - [PLAY_REACHED_100_PERCENT][21] + - [SOURCE_SELECTED][22] + - [AUDIO_SELECTED][23] + - [FLAVOR_SWITCH][24] + - [CAPTIONS][25] + - [ERROR][26] +- [Kava][27] + - [Parameters][28] + - [destroy][29] + - [reset][30] + - [getEventModel][31] + - [Parameters][32] + - [Examples][33] + - [EventType][34] + - [sendAnalytics][35] + - [Parameters][36] + - [Examples][37] + - [defaultConfig][38] + - [isValid][39] ## KavaConfigObject -Type: [Object][38] +Type: [Object][40] ### Properties -- `serviceUrl` **[string][39]?** The Kaltura API server. -- `viewEventCountdown` **[number][40]?** The interval in seconds that VIEW event will be sent. -- `resetSessionCountdown` **[number][40]?** The interval in seconds that Kava session will be reset. -- `dvrThreshold` **[number][40]?** Threshold in seconds from the live edge. -- `applicationVersion` **[string][39]?** Used to send the application version from which the user is playing the entry. -- `playbackContext` **[string][39]?** Used to send the id of the category from which the user is playing the entry. -- `tamperAnalyticsHandler` **[Function][41]?** An optional handler to implement. Can be used to manipulate the model data before analytics event sent, or to cancel a certain analytics request. -- `customVar1` **[Object][38]?** Custom objects field. -- `customVar2` **[Object][38]?** Custom objects field. -- `customVar3` **[Object][38]?** Custom objects field. +- `serviceUrl` **[string][41]?** The Kaltura API server. +- `viewEventCountdown` **[number][42]?** The interval in seconds that VIEW event will be sent. +- `resetSessionCountdown` **[number][42]?** The interval in seconds that Kava session will be reset. +- `dvrThreshold` **[number][42]?** Threshold in seconds from the live edge. +- `applicationVersion` **[string][41]?** Used to send the application version from which the user is playing the entry. +- `playbackContext` **[string][41]?** Used to send the id of the category from which the user is playing the entry. +- `tamperAnalyticsHandler` **[Function][43]?** An optional handler to implement. Can be used to manipulate the model data before analytics event sent, or to cancel a certain analytics request. +- `customVar1` **[Object][40]?** Custom objects field. +- `customVar2` **[Object][40]?** Custom objects field. +- `customVar3` **[Object][40]?** Custom objects field. ### Examples @@ -75,7 +77,7 @@ Type: [Object][38] #### Parameters -- `model` **[Object][38]** Event model +- `model` **[Object][40]** Event model #### Examples @@ -90,77 +92,85 @@ tamperAnalyticsHandler: function (model) { } ``` -Returns **[boolean][42]** Should send the request or not. +Returns **[boolean][44]** Should send the request or not. ## KavaEventType ### VIEW -Type: [string][39] +Type: [string][41] ### IMPRESSION -Type: [string][39] +Type: [string][41] ### PLAY_REQUEST -Type: [string][39] +Type: [string][41] ### PLAY -Type: [string][39] +Type: [string][41] ### RESUME -Type: [string][39] +Type: [string][41] ### PAUSE -Type: [string][39] +Type: [string][41] + +### BUFFER_START + +Type: [string][41] + +### BUFFER_END + +Type: [string][41] ### REPLAY -Type: [string][39] +Type: [string][41] ### SEEK -Type: [string][39] +Type: [string][41] ### PLAY_REACHED_25_PERCENT -Type: [string][39] +Type: [string][41] ### PLAY_REACHED_50_PERCENT -Type: [string][39] +Type: [string][41] ### PLAY_REACHED_75_PERCENT -Type: [string][39] +Type: [string][41] ### PLAY_REACHED_100_PERCENT -Type: [string][39] +Type: [string][41] ### SOURCE_SELECTED -Type: [string][39] +Type: [string][41] ### AUDIO_SELECTED -Type: [string][39] +Type: [string][41] ### FLAVOR_SWITCH -Type: [string][39] +Type: [string][41] ### CAPTIONS -Type: [string][39] +Type: [string][41] ### ERROR -Type: [string][39] +Type: [string][41] ## Kava @@ -168,9 +178,9 @@ Kaltura Advanced Analytics plugin. ### Parameters -- `name` **[string][39]** The plugin name. +- `name` **[string][41]** The plugin name. - `player` **Player** The player instance. -- `config` **[KavaConfigObject][43]** The plugin config. +- `config` **[KavaConfigObject][45]** The plugin config. ### destroy @@ -190,7 +200,7 @@ Gets the model object for a certain event. #### Parameters -- `event` **[string][39]** Event name. +- `event` **[string][41]** Event name. #### Examples @@ -200,11 +210,11 @@ const viewModel = kava.getEventModel(kava.EventType.VIEW); kava.sendAnalytics(viewModel); ``` -Returns **[Object][38]** Model object. +Returns **[Object][40]** Model object. ### EventType -Returns **[KavaEventType][44]** The kava events list. +Returns **[KavaEventType][46]** The kava events list. ### sendAnalytics @@ -212,7 +222,7 @@ Sends KAVA analytics event to analytics service. #### Parameters -- `model` **[Object][38]** Event model. +- `model` **[Object][40]** Event model. #### Examples @@ -226,17 +236,17 @@ player.plugins.kava.sendAnalytics({...}) }); ``` -Returns **[Promise][45]** Promise to indicate request succeed or failed. +Returns **[Promise][47]** Promise to indicate request succeed or failed. ### defaultConfig Default config of the plugin. -Type: [Object][38] +Type: [Object][40] ### isValid -Returns **[boolean][42]** Whether the plugin is valid in the current environment. +Returns **[boolean][44]** Whether the plugin is valid in the current environment. [1]: #kavaconfigobject [2]: #properties @@ -251,35 +261,37 @@ Returns **[boolean][42]** Whether the plugin is valid in the current environment [11]: #play [12]: #resume [13]: #pause -[14]: #replay -[15]: #seek -[16]: #play_reached_25_percent -[17]: #play_reached_50_percent -[18]: #play_reached_75_percent -[19]: #play_reached_100_percent -[20]: #source_selected -[21]: #audio_selected -[22]: #flavor_switch -[23]: #captions -[24]: #error -[25]: #kava -[26]: #parameters-1 -[27]: #destroy -[28]: #reset -[29]: #geteventmodel -[30]: #parameters-2 -[31]: #examples-2 -[32]: #eventtype -[33]: #sendanalytics -[34]: #parameters-3 -[35]: #examples-3 -[36]: #defaultconfig -[37]: #isvalid -[38]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[39]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[40]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number -[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function -[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean -[43]: #kavaconfigobject -[44]: #kavaeventtype -[45]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise +[14]: #buffer_start +[15]: #buffer_end +[16]: #replay +[17]: #seek +[18]: #play_reached_25_percent +[19]: #play_reached_50_percent +[20]: #play_reached_75_percent +[21]: #play_reached_100_percent +[22]: #source_selected +[23]: #audio_selected +[24]: #flavor_switch +[25]: #captions +[26]: #error +[27]: #kava +[28]: #parameters-1 +[29]: #destroy +[30]: #reset +[31]: #geteventmodel +[32]: #parameters-2 +[33]: #examples-2 +[34]: #eventtype +[35]: #sendanalytics +[36]: #parameters-3 +[37]: #examples-3 +[38]: #defaultconfig +[39]: #isvalid +[40]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number +[43]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[45]: #kavaconfigobject +[46]: #kavaeventtype +[47]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise diff --git a/src/kava-event-model.js b/src/kava-event-model.js index a25ffc4c..588cc2b7 100644 --- a/src/kava-event-model.js +++ b/src/kava-event-model.js @@ -75,6 +75,24 @@ export const KavaEventModel: {[event: string]: KavaEvent} = { index: 33, getEventModel: () => ({}) }, + /** + * @type {string} BUFFER_START + * @memberof KavaEventType + */ + BUFFER_START: { + type: 'BUFFER_START', + index: 45, + getEventModel: () => ({}) + }, + /** + * @type {string} BUFFER_END + * @memberof KavaEventType + */ + BUFFER_END: { + type: 'BUFFER_END', + index: 46, + getEventModel: () => ({}) + }, /** * @type {string} REPLAY * @memberof KavaEventType diff --git a/src/kava.js b/src/kava.js index 1814ef9b..996cbdbc 100644 --- a/src/kava.js +++ b/src/kava.js @@ -379,10 +379,12 @@ class Kava extends BasePlugin { if (oldState.type === this.player.State.BUFFERING) { this._isBuffering = false; this._updateBufferModel(); + this._sendAnalytics(KavaEventType.BUFFER_END); } if (newState.type === this.player.State.BUFFERING) { this._isBuffering = true; this._bufferStartTime = Date.now(); + this._sendAnalytics(KavaEventType.BUFFER_START); } } From c41da87534b985e18a2bdf3656e72df307a9b63a Mon Sep 17 00:00:00 2001 From: Dan Ziv Date: Wed, 14 Nov 2018 16:21:55 +0200 Subject: [PATCH 2/3] tests --- src/kava.js | 4 ++-- test/src/kava-event-model.spec.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/kava.js b/src/kava.js index 996cbdbc..e540adb3 100644 --- a/src/kava.js +++ b/src/kava.js @@ -379,12 +379,12 @@ class Kava extends BasePlugin { if (oldState.type === this.player.State.BUFFERING) { this._isBuffering = false; this._updateBufferModel(); - this._sendAnalytics(KavaEventType.BUFFER_END); + this._sendAnalytics(KavaEventModel.BUFFER_END); } if (newState.type === this.player.State.BUFFERING) { this._isBuffering = true; this._bufferStartTime = Date.now(); - this._sendAnalytics(KavaEventType.BUFFER_START); + this._sendAnalytics(KavaEventModel.BUFFER_START); } } diff --git a/test/src/kava-event-model.spec.js b/test/src/kava-event-model.spec.js index 0abd2333..8a9b923c 100644 --- a/test/src/kava-event-model.spec.js +++ b/test/src/kava-event-model.spec.js @@ -173,4 +173,16 @@ describe('KavaEventModel', () => { errorCode: fakeModel.getErrorCode() }); }); + + it('BUFFER_START', () => { + KavaEventModel.BUFFER_START.type.should.equal('BUFFER_START'); + KavaEventModel.BUFFER_START.index.should.equal(45); + KavaEventModel.BUFFER_START.getEventModel(fakeModel).should.deep.equal({}); + }); + + it('BUFFER_END', () => { + KavaEventModel.BUFFER_START.type.should.equal('BUFFER_END'); + KavaEventModel.BUFFER_START.index.should.equal(46); + KavaEventModel.BUFFER_START.getEventModel(fakeModel).should.deep.equal({}); + }); }); From d39f4d4b734eefb588722ae7cd99ebcbec4802b3 Mon Sep 17 00:00:00 2001 From: Dan Ziv Date: Wed, 14 Nov 2018 16:54:26 +0200 Subject: [PATCH 3/3] add more tests --- test/src/kava-event-model.spec.js | 6 ++--- test/src/kava.spec.js | 40 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/test/src/kava-event-model.spec.js b/test/src/kava-event-model.spec.js index 8a9b923c..4c4b3d36 100644 --- a/test/src/kava-event-model.spec.js +++ b/test/src/kava-event-model.spec.js @@ -181,8 +181,8 @@ describe('KavaEventModel', () => { }); it('BUFFER_END', () => { - KavaEventModel.BUFFER_START.type.should.equal('BUFFER_END'); - KavaEventModel.BUFFER_START.index.should.equal(46); - KavaEventModel.BUFFER_START.getEventModel(fakeModel).should.deep.equal({}); + KavaEventModel.BUFFER_END.type.should.equal('BUFFER_END'); + KavaEventModel.BUFFER_END.index.should.equal(46); + KavaEventModel.BUFFER_END.getEventModel(fakeModel).should.deep.equal({}); }); }); diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index 7aa058fe..b5196f68 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -414,6 +414,46 @@ describe('KavaPlugin', function() { kava = getKavaPlugin(); player.play(); }); + + it('should send BUFFER_START event', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + validateCommonParams(params, KavaEventModel.BUFFER_START.index); + done(); + return new RequestBuilder(); + }); + setupPlayer(config); + kava = getKavaPlugin(); + kava._onPlayerStateChanged({ + payload: { + oldState: { + type: 'playing' + }, + newState: { + type: 'buffering' + } + } + }); + }); + + it('should send BUFFER_END event', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + validateCommonParams(params, KavaEventModel.BUFFER_END.index); + done(); + return new RequestBuilder(); + }); + setupPlayer(config); + kava = getKavaPlugin(); + kava._onPlayerStateChanged({ + payload: { + newState: { + type: 'playing' + }, + oldState: { + type: 'buffering' + } + } + }); + }); }); describe('Server Response', () => {