Skip to content

Commit

Permalink
Chore: Emit pause event with flag if initiated by user (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinHoldstock authored Nov 20, 2018
1 parent 0589f23 commit 8d7091c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/lib/viewers/media/MediaBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,11 @@ class MediaBaseViewer extends BaseViewer {
* Pause media
*
* @param {number} time - time at which media is paused
* @param {boolean} [userInitiated] - True if user input initiated the pause
* @emits pause
* @return {void}
*/
pause(time) {
pause(time, userInitiated = false) {
const hasValidTime = this.isValidTime(time);
// Remove eventListener because segment completed playing or user paused manually
this.removePauseEventListener();
Expand All @@ -599,7 +600,9 @@ class MediaBaseViewer extends BaseViewer {
this.mediaEl.addEventListener('timeupdate', this.pauseListener);
} else {
this.mediaEl.pause();
this.emit('pause');
this.emit('pause', {
userInitiated
});
}
}

Expand All @@ -613,7 +616,7 @@ class MediaBaseViewer extends BaseViewer {
if (this.mediaEl.paused) {
this.play();
} else {
this.pause();
this.pause(undefined, true);
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/lib/viewers/media/__tests__/MediaBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,22 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
media.pause();
expect(media.removePauseEventListener.callCount).to.equal(1);
expect(media.mediaEl.pause.callCount).to.equal(1);
expect(media.emit).to.be.calledWith('pause');
expect(media.emit).to.be.calledWith('pause', {
userInitiated: false
});
});

it('should update userInitiated flag IF the pause has been triggered by user interaction', () => {
media.mediaEl = {
duration: 100,
pause: sandbox.stub()
};
sandbox.stub(media, 'removePauseEventListener');
sandbox.stub(media, 'emit');
media.pause(undefined, true);
expect(media.emit).to.be.calledWith('pause', {
userInitiated: true
});
});

it('should add eventListener to pause the media when valid time parameter is passed', () => {
Expand Down

0 comments on commit 8d7091c

Please sign in to comment.