From 8999cbae8234790b85cd0f319762d2da3285e086 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 17 Aug 2021 13:37:24 -0400 Subject: [PATCH] fix: remove el on sendOutput (#49) Fixes #48 --- build/can-autoplay.cjs.js | 4 ++++ build/can-autoplay.es.js | 4 ++++ build/can-autoplay.js | 4 ++++ lib/index.js | 7 ++++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/build/can-autoplay.cjs.js b/build/can-autoplay.cjs.js index 4b5395f..c215fc6 100644 --- a/build/can-autoplay.cjs.js +++ b/build/can-autoplay.cjs.js @@ -56,6 +56,10 @@ function startPlayback(_ref, elementCallback) { sendOutput = function sendOutput(result) { var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + // Clean up to avoid MediaElementLeak + element.remove(); + element.srcObject = null; + clearTimeout(timeoutId); resolve({ result: result, error: error }); }; diff --git a/build/can-autoplay.es.js b/build/can-autoplay.es.js index 2211284..52a24bb 100644 --- a/build/can-autoplay.es.js +++ b/build/can-autoplay.es.js @@ -54,6 +54,10 @@ function startPlayback(_ref, elementCallback) { sendOutput = function sendOutput(result) { var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + // Clean up to avoid MediaElementLeak + element.remove(); + element.srcObject = null; + clearTimeout(timeoutId); resolve({ result: result, error: error }); }; diff --git a/build/can-autoplay.js b/build/can-autoplay.js index edcf7df..41dd721 100644 --- a/build/can-autoplay.js +++ b/build/can-autoplay.js @@ -60,6 +60,10 @@ function startPlayback(_ref, elementCallback) { sendOutput = function sendOutput(result) { var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + // Clean up to avoid MediaElementLeak + element.remove(); + element.srcObject = null; + clearTimeout(timeoutId); resolve({ result: result, error: error }); }; diff --git a/lib/index.js b/lib/index.js index fa72ed3..166ec87 100644 --- a/lib/index.js +++ b/lib/index.js @@ -33,6 +33,10 @@ function startPlayback ({muted, timeout, inline}, elementCallback) { sendOutput(false, new Error(`Timeout ${timeout} ms has been reached`)) }, timeout) sendOutput = (result, error = null) => { + // Clean up to avoid MediaElementLeak + element.remove() + element.srcObject = null + clearTimeout(timeoutId) resolve({result, error}) } @@ -44,9 +48,6 @@ function startPlayback ({muted, timeout, inline}, elementCallback) { } else { sendOutput(true) } - // Clean up to avoid MediaElementLeak - element.remove() - element.srcObject = null }) }