Skip to content

Commit 6833861

Browse files
authored
Check that Performance methods exist before invoking them (Dash-Industry-Forum#4831)
* addEventListener * removeEventListener * getEntriesByType
1 parent 895fdd9 commit 6833861

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/streaming/controllers/ThroughputController.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,19 @@ function ThroughputController() {
7070
function _registerEvents() {
7171
eventBus.on(MediaPlayerEvents.METRIC_ADDED, _onMetricAdded, instance);
7272

73-
if (performance) {
74-
performance.addEventListener(
75-
'resourcetimingbufferfull',
76-
_onResourceTimingBufferFull,
77-
);
78-
}
73+
window.performance?.addEventListener?.(
74+
'resourcetimingbufferfull',
75+
_onResourceTimingBufferFull,
76+
);
7977
}
8078

8179
function _resetEvents() {
8280
eventBus.off(MediaPlayerEvents.METRIC_ADDED, _onMetricAdded, instance);
8381

84-
if (performance) {
85-
performance.removeEventListener(
86-
'resourcetimingbufferfull',
87-
_onResourceTimingBufferFull,
88-
);
89-
}
82+
window.performance?.removeEventListener?.(
83+
'resourcetimingbufferfull',
84+
_onResourceTimingBufferFull,
85+
);
9086
}
9187

9288
function _onResourceTimingBufferFull() {

src/streaming/net/HTTPLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function HTTPLoader(cfg) {
501501
}
502502

503503
// Get a list of "resource" performance entries
504-
const resources = performance.getEntriesByType('resource');
504+
const resources = performance.getEntriesByType?.('resource');
505505
if (resources === undefined || resources.length <= 0) {
506506
return;
507507
}

0 commit comments

Comments
 (0)