Skip to content

Commit ca2217a

Browse files
committed
Protects player after disposal
Ensures player methods `on` and `trigger` are safely called after the player has been disposed. The silvermine chromecast plugin has an interval that may fire after player disposal, and attempts to call these methods, causing errors.
1 parent 4c69e52 commit ca2217a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ui/component/viewers/videoViewer/internal/chromecast.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export default class Chromecast {
1212
* Actions that need to happen after initializing 'videojs'
1313
*/
1414
static initialize(player: any) {
15-
// --- Wrap player.on to be safe after disposal ---
15+
// --- Wrap player methods to be safe after disposal ---
1616
// The silvermine chromecast plugin has an interval that may fire after player disposal
17-
// and try to call player.on(), causing "Invalid target for null#on" errors
17+
// and try to call player.on()/trigger(), causing "Invalid target for null#..." errors
1818
const originalOn = player.on.bind(player);
1919
player.on = function (...args: any) {
2020
if (player.isDisposed()) {
@@ -23,6 +23,14 @@ export default class Chromecast {
2323
return originalOn(...args);
2424
};
2525

26+
const originalTrigger = player.trigger.bind(player);
27+
player.trigger = function (...args: any) {
28+
if (player.isDisposed()) {
29+
return player;
30+
}
31+
return originalTrigger(...args);
32+
};
33+
2634
// --- Start plugin ---
2735
player.chromecast();
2836

0 commit comments

Comments
 (0)