mirror of
https://github.com/videojs/video.js.git
synced 2024-12-14 11:23:30 +02:00
fix: Patch a memory leak caused by un-removed track listener(s). (#3976)
This commit is contained in:
parent
3585af0fe2
commit
4979ea78d5
@ -559,14 +559,12 @@ class Tech extends Component {
|
|||||||
*/
|
*/
|
||||||
emulateTextTracks() {
|
emulateTextTracks() {
|
||||||
const tracks = this.textTracks();
|
const tracks = this.textTracks();
|
||||||
|
const remoteTracks = this.remoteTextTracks();
|
||||||
|
const handleAddTrack = (e) => tracks.addTrack(e.track);
|
||||||
|
const handleRemoveTrack = (e) => tracks.removeTrack(e.track);
|
||||||
|
|
||||||
this.remoteTextTracks().on('addtrack', (e) => {
|
remoteTracks.on('addtrack', handleAddTrack);
|
||||||
tracks.addTrack(e.track);
|
remoteTracks.on('removetrack', handleRemoveTrack);
|
||||||
});
|
|
||||||
|
|
||||||
this.remoteTextTracks().on('removetrack', (e) => {
|
|
||||||
tracks.removeTrack(e.track);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initially, Tech.el_ is a child of a dummy-div wait until the Component system
|
// Initially, Tech.el_ is a child of a dummy-div wait until the Component system
|
||||||
// signals that the Tech is ready at which point Tech.el_ is part of the DOM
|
// signals that the Tech is ready at which point Tech.el_ is part of the DOM
|
||||||
@ -574,6 +572,7 @@ class Tech extends Component {
|
|||||||
this.on('ready', this.addWebVttScript_);
|
this.on('ready', this.addWebVttScript_);
|
||||||
|
|
||||||
const updateDisplay = () => this.trigger('texttrackchange');
|
const updateDisplay = () => this.trigger('texttrackchange');
|
||||||
|
|
||||||
const textTracksChanges = () => {
|
const textTracksChanges = () => {
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
|
|
||||||
@ -591,7 +590,15 @@ class Tech extends Component {
|
|||||||
tracks.addEventListener('change', textTracksChanges);
|
tracks.addEventListener('change', textTracksChanges);
|
||||||
|
|
||||||
this.on('dispose', function() {
|
this.on('dispose', function() {
|
||||||
|
remoteTracks.off('addtrack', handleAddTrack);
|
||||||
|
remoteTracks.off('removetrack', handleRemoveTrack);
|
||||||
tracks.removeEventListener('change', textTracksChanges);
|
tracks.removeEventListener('change', textTracksChanges);
|
||||||
|
|
||||||
|
for (let i = 0; i < tracks.length; i++) {
|
||||||
|
const track = tracks[i];
|
||||||
|
|
||||||
|
track.removeEventListener('cuechange', updateDisplay);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user