diff --git a/docs/configuration-api.md b/docs/configuration-api.md index b7af4052..eec50778 100644 --- a/docs/configuration-api.md +++ b/docs/configuration-api.md @@ -50,6 +50,7 @@ Type: [Object][41] ### Properties - `serviceUrl` **[string][42]?** The Kaltura API server. +- `requestMethod` **[string][42]?** The http method to be used for sending the beacons, GET or POST, the default is GET. - `viewEventCountdown` **[number][43]?** The interval in seconds that VIEW event will be sent. - `resetSessionCountdown` **[number][43]?** The interval in seconds that Kava session will be reset. - `dvrThreshold` **[number][43]?** Threshold in seconds from the live edge. @@ -68,6 +69,7 @@ Type: [Object][41] // Default config { serviceUrl: '//analytics.kaltura.com/api_v3/index.php', + requestMethod: 'GET', viewEventCountdown: 30, resetSessionCountdown: 30, dvrThreshold: 120, diff --git a/flow-typed/types/kava-http-method-type.js b/flow-typed/types/kava-http-method-type.js new file mode 100644 index 00000000..ae5645ce --- /dev/null +++ b/flow-typed/types/kava-http-method-type.js @@ -0,0 +1,2 @@ +// @flow +declare type KavaHttpMethodType = {[stream: string]: string}; diff --git a/src/http-method-type.js b/src/http-method-type.js new file mode 100644 index 00000000..b3936b5f --- /dev/null +++ b/src/http-method-type.js @@ -0,0 +1,7 @@ +// @flow +const HttpMethodType: KavaHttpMethodType = { + GET: 'GET', + POST: 'POST' +}; + +export {HttpMethodType}; diff --git a/src/index.js b/src/index.js index b9d09810..6ae49b58 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ const NAME = __NAME__; export {Kava as Plugin}; export {KavaEventType as EventType} from './kava-event-model'; +export {HttpMethodType} from './http-method-type'; export {VERSION, NAME}; const pluginName: string = 'kava'; diff --git a/src/kava.js b/src/kava.js index 3dcd0ea7..1e6e6177 100644 --- a/src/kava.js +++ b/src/kava.js @@ -5,6 +5,7 @@ import {KavaEventModel, KavaEventType} from './kava-event-model'; import {KavaRateHandler} from './kava-rate-handler'; import {KavaTimer} from './kava-timer'; import {ErrorPosition, KavaModel, SoundMode, TabMode, ScreenMode} from './kava-model'; +import {HttpMethodType} from './http-method-type'; const {Error: PKError, FakeEvent, Utils} = core; const DIVIDER: number = 1024; @@ -49,6 +50,7 @@ class Kava extends BasePlugin { */ static defaultConfig: Object = { serviceUrl: `${Utils.Http.protocol}//analytics.kaltura.com/api_v3/index.php`, + requestMethod: HttpMethodType.GET, viewEventCountdown: 10, resetSessionCountdown: 30, dvrThreshold: 120, @@ -206,7 +208,7 @@ class Kava extends BasePlugin { */ sendAnalytics(model: Object): Promise<*> { return new Promise((resolve, reject) => { - OVPAnalyticsService.trackEvent(this.config.serviceUrl, model) + OVPAnalyticsService.trackEvent(this.config.serviceUrl, model, this.config.requestMethod) .doHttpRequest() .then( response => { diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index 09451abd..4b7b771f 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -4,6 +4,7 @@ import * as TestUtils from './utils/test-utils'; import {OVPAnalyticsService, RequestBuilder} from 'playkit-js-providers/dist/playkit-analytics-service'; import {KavaEventModel} from '../../src/kava-event-model'; import {ErrorPosition, SoundMode, TabMode, ScreenMode} from '../../src/kava-model'; +import {HttpMethodType} from '../../src/http-method-type'; const {FakeEvent, CustomEventType} = core; const targetId = 'player-placeholder_kava.spec'; @@ -885,7 +886,11 @@ describe('KavaPlugin', function () { }) ); player.dispatchEvent( - new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG2_DOWNLOAD_TIME, bytes: FRAG2_BYTES, url: 'http://www.somesite.com/movie2.ts'}) + new FakeEvent(CustomEventType.FRAG_LOADED, { + miliSeconds: FRAG2_DOWNLOAD_TIME, + bytes: FRAG2_BYTES, + url: 'http://www.somesite.com/movie2.ts' + }) ); let performanceOverserList = {}; performanceOverserList.getEntries = () => { @@ -1068,6 +1073,21 @@ describe('KavaPlugin', function () { kava = getKavaPlugin(); kava._onPlaybackRateChanged(); }); + + it('should send IMPRESSION event as POST', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params, requestMethod) => { + try { + requestMethod.should.be.equal(HttpMethodType.POST); + done(); + } catch (e) { + done(e); + } + }); + config.plugins.kava.requestMethod = HttpMethodType.POST; + setupPlayer(config); + kava = getKavaPlugin(); + player.play(); + }); }); describe('Server Response', () => {