From 9f8ce2dcd6d7a1f390af8c22a4c1b2ae9858cdfb Mon Sep 17 00:00:00 2001 From: axten Date: Thu, 19 Apr 2018 17:57:32 +0200 Subject: [PATCH] fix: wait till play event to listen for user activity (#5093) There is no need to listen for user activity until a play is requested on the player and it just adds an extra timer for a player that hasn't started playing yet. Instead, just wait till the first `play` event. Closes #5076. --- src/js/player.js | 2 +- test/unit/player.test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index 256cbf902a..4ba5961a35 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -468,8 +468,8 @@ class Player extends Component { // like the control bar show themselves if needed this.userActive(true); this.reportUserActivity(); - this.listenForUserActivity_(); + this.one('play', this.listenForUserActivity_); this.on('fullscreenchange', this.handleFullscreenChange_); this.on('stageclick', this.handleStageClick_); diff --git a/test/unit/player.test.js b/test/unit/player.test.js index b680e73be6..7a7ba60126 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -914,6 +914,8 @@ QUnit.test('should honor default inactivity timeout', function(assert) { // default timeout is 2000ms const player = TestHelpers.makePlayer({}); + player.trigger('play'); + assert.equal(player.userActive(), true, 'User is active on creation'); clock.tick(1800); assert.equal(player.userActive(), true, 'User is still active'); @@ -932,6 +934,8 @@ QUnit.test('should honor configured inactivity timeout', function(assert) { inactivityTimeout: 200 }); + player.trigger('play'); + assert.equal(player.userActive(), true, 'User is active on creation'); clock.tick(150); assert.equal(player.userActive(), true, 'User is still active');