From 4e4a78fb581a9c1a3ab6b82576a3b151dba5b91d Mon Sep 17 00:00:00 2001 From: Yuval Keidar <48407737+Yuvalke@users.noreply.github.com> Date: Wed, 30 Sep 2020 12:32:34 +0300 Subject: [PATCH] fix(FEC-10512): handle memory leaks in smart TV (#487) issue: HTML5 event handler is too complex and took too long and the babel config causes memory issue on a smart TV. Solution: simplify the handler and fix the babel plugin config which causes the memory issue. --- .babelrc | 7 ++++++- src/engines/html5/html5.js | 15 ++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.babelrc b/.babelrc index e029d03db..a902b5717 100644 --- a/.babelrc +++ b/.babelrc @@ -11,7 +11,12 @@ "@babel/plugin-transform-property-mutators", "@babel/plugin-proposal-object-rest-spread", "@babel/plugin-proposal-class-properties", - "@babel/plugin-transform-classes" + [ + "@babel/plugin-transform-classes", + { + "loose": true + } + ] ], "presets": ["@babel/preset-env", "@babel/preset-flow"] } diff --git a/src/engines/html5/html5.js b/src/engines/html5/html5.js index 63fdf9d93..13dc4c650 100644 --- a/src/engines/html5/html5.js +++ b/src/engines/html5/html5.js @@ -282,13 +282,14 @@ export default class Html5 extends FakeEventTarget implements IEngine { */ attach(): void { Object.keys(Html5EventType).forEach(html5Event => { - this._eventManager.listen(this._el, Html5EventType[html5Event], () => { - if (Html5EventType[html5Event] === Html5EventType.ERROR) { - this._handleVideoError(); - } else { - this.dispatchEvent(new FakeEvent(Html5EventType[html5Event])); - } - }); + if (Html5EventType[html5Event] !== Html5EventType.ERROR) { + this._eventManager.listen(this._el, Html5EventType[html5Event], () => { + return this.dispatchEvent(new FakeEvent(Html5EventType[html5Event])); + }); + } + }); + this._eventManager.listen(this._el, Html5EventType.ERROR, () => { + this._handleVideoError(); }); this._handleMetadataTrackEvents(); let mediaSourceAdapter = this._mediaSourceAdapter;