diff --git a/src/StremioVideo/StremioVideo.js b/src/StremioVideo/StremioVideo.js index 5a898b9..1009ad3 100644 --- a/src/StremioVideo/StremioVideo.js +++ b/src/StremioVideo/StremioVideo.js @@ -82,8 +82,7 @@ function StremioVideo() { } if (action.type === 'command' && action.commandName === 'destroy') { - destroyed = true; - events.removeAllListeners(); + video = null; } return; @@ -91,6 +90,15 @@ function StremioVideo() { throw new Error('Invalid action dispatched: ' + JSON.stringify(action)); }; + this.destroy = function() { + destroyed = true; + if (video !== null) { + video.dispatch({ type: 'command', commandName: 'destroy' }); + video = null; + } + + events.removeAllListeners(); + }; } module.exports = StremioVideo;