Skip to content

Commit

Permalink
Fix: Only remove the timeupdate listener if it has been bound before (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Dec 4, 2017
1 parent 96916a6 commit 5c8dffa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/viewers/media/MediaBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ class MediaBaseViewer extends BaseViewer {
}

/**
* Removes pause event listener
* Removes pause event listener if it exists
*
* @private
* @return {void}
*/
removePauseEventListener() {
if (this.mediaEl) {
if (this.mediaEl && this.pauseListener) {
this.mediaEl.removeEventListener('timeupdate', this.pauseListener);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/lib/viewers/media/__tests__/MediaBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,20 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
});

describe('removePauseEventListener()', () => {
it('should remove pause event listener', () => {
const pauseListener = () => {};
it('should remove pause event listener if it exists', () => {
let pauseListener = null
media.mediaEl = { removeEventListener: sandbox.stub() };

media.pauseListener = pauseListener;
media.removePauseEventListener();
expect(media.mediaEl.removeEventListener).to.be.not.be.called

pauseListener = () => {};
media.pauseListener = pauseListener;
media.removePauseEventListener();
expect(media.mediaEl.removeEventListener).to.be.calledWith('timeupdate', pauseListener);


});
});

Expand Down

0 comments on commit 5c8dffa

Please sign in to comment.