Skip to content

Commit

Permalink
fix(FEC-9251): the browser stuck after click Play button (#44)
Browse files Browse the repository at this point in the history
* fix(FEC-9251): the browser stuck after click Play button
  • Loading branch information
RoyBregman authored Jul 21, 2019
1 parent 7693c18 commit 9ba55f8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
22 changes: 14 additions & 8 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Kava extends BasePlugin {
_lastTotalFrames: number = 0;
_performanceObserver: window.PerformanceObserver;
_performanceEntries: window.PerformanceEntry[] = [];
_pendingFragLoadedEvents: FakeEvent[] = [];
_pendingFragLoadedUrls: string[] = [];
_fragLoadedFiredOnce: boolean = false;

/**
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -117,7 +117,7 @@ class Kava extends BasePlugin {
this._rateHandler.destroy();
this._performanceObserver.disconnect();
this._performanceEntries = [];
this._pendingFragLoadedEvents = [];
this._pendingFragLoadedUrls = [];
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
54 changes: 30 additions & 24 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 9ba55f8

Please sign in to comment.