diff --git a/package.json b/package.json index 11d9f0ae..61b8c5ca 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "access": "public" }, "devDependencies": { - "@playkit-js/playkit-js": "^0.47.0", + "@playkit-js/playkit-js": "^0.51.0", "babel-cli": "^6.18.0", "babel-core": "^6.18.2", "babel-eslint": "^7.1.1", @@ -84,7 +84,7 @@ "webpack-dev-server": "latest" }, "peerDependencies": { - "@playkit-js/playkit-js": "^0.37.0", + "@playkit-js/playkit-js": "^0.51.0", "playkit-js-providers": "https://github.com/kaltura/playkit-js-providers.git#master" }, "keywords": [ diff --git a/src/kava.js b/src/kava.js index 9b7e8434..b192750f 100644 --- a/src/kava.js +++ b/src/kava.js @@ -35,7 +35,7 @@ class Kava extends BasePlugin { _lastTotalFrames: number = 0; _performanceObserver: window.PerformanceObserver; _performanceEntries: window.PerformanceEntry[] = []; - _pendingFragLoadedEvents: FakeEvent[] = []; + _pendingFragLoadedUrls: string[] = []; _fragLoadedFiredOnce: boolean = false; /** @@ -95,9 +95,9 @@ class Kava extends BasePlugin { for (let i = 0; i < perfEntries.length; i++) { this._performanceEntries.push(perfEntries[i]); } - while (this._pendingFragLoadedEvents.length) { + while (this._pendingFragLoadedUrls.length) { // handle frag loaded events which haven't been added to the entry list yet - this._handleFragPerformanceObserver(this._pendingFragLoadedEvents.pop()); + this._handleFragPerformanceObserver(this._pendingFragLoadedUrls.pop()); } } @@ -117,7 +117,7 @@ class Kava extends BasePlugin { this._rateHandler.destroy(); this._performanceObserver.disconnect(); this._performanceEntries = []; - this._pendingFragLoadedEvents = []; + this._pendingFragLoadedUrls = []; } /** @@ -520,10 +520,15 @@ class Kava extends BasePlugin { this._fragLoadedFiredOnce = true; } this._updateFragLoadedStats(event); - this._handleFragPerformanceObserver(event.payload.url); + if (this._performanceObserver) { + const succHandle = this._handleFragPerformanceObserver(event.payload.url); + if (!succHandle) { + this._pendingFragLoadedUrls.push(event.payload.url); + } + } } - _handleFragPerformanceObserver(url: string): void { + _handleFragPerformanceObserver(url: string): boolean { const fragResourceTimings = this._performanceEntries.filter(entry => entry.name == url); const lastFragResourceTiming: ?Object = fragResourceTimings && fragResourceTimings.length ? fragResourceTimings[fragResourceTimings.length - 1] : null; @@ -536,8 +541,9 @@ class Kava extends BasePlugin { this._performanceEntries.length - (lastIndexOftheFragment + 1) ); } - } else if (this._performanceObserver) { - this._pendingFragLoadedEvents.push(event); + return true; + } else { + return false; } } _updateMaxNetworkConnectionOverhead(networkConnectionOverhead: number): void { diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index 06c8b1c5..7bdf9418 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -539,30 +539,6 @@ describe('KavaPlugin', function() { }); setupPlayer(config); kava = getKavaPlugin(); - kava._performanceEntries.push({ - name: 'http://www.somesite.com/movie.ts', - entryType: 'resource', - startTime: 118.6400000001413, - duration: 149.8900000001413, - initiatorType: 'script', - nextHopProtocol: 'http/1.1', - workerStart: 0, - redirectStart: 0, - redirectEnd: 0, - fetchStart: 118.6400000001413, - domainLookupStart: 20.2, - domainLookupEnd: 0, - connectStart: 0, - connectEnd: 120.5, - secureConnectionStart: 0, - requestStart: 0, - responseStart: 0, - responseEnd: 268.5300000002826, - transferSize: 0, - encodedBodySize: 0, - decodedBodySize: 0, - serverTiming: [] - }); player.play(); player.dispatchEvent( new FakeEvent(CustomEventType.TIMED_METADATA, { @@ -590,6 +566,36 @@ describe('KavaPlugin', function() { player.dispatchEvent( new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG2_DOWNLOAD_TIME, bytes: FRAG2_BYTES, url: 'http://www.somesite.com/movie2.ts'}) ); + let performanceOverserList = {}; + performanceOverserList.getEntries = () => { + return [ + { + name: 'http://www.somesite.com/movie.ts', + entryType: 'resource', + startTime: 118.6400000001413, + duration: 149.8900000001413, + initiatorType: 'script', + nextHopProtocol: 'http/1.1', + workerStart: 0, + redirectStart: 0, + redirectEnd: 0, + fetchStart: 118.6400000001413, + domainLookupStart: 20.2, + domainLookupEnd: 0, + connectStart: 0, + connectEnd: 120.5, + secureConnectionStart: 0, + requestStart: 0, + responseStart: 0, + responseEnd: 268.5300000002826, + transferSize: 0, + encodedBodySize: 0, + decodedBodySize: 0, + serverTiming: [] + } + ]; + }; + kava._handleNewPerformanceEntries(performanceOverserList); }); it('should send VIEW event with volume set to 0', done => {