diff --git a/docs/guides/middleware.md b/docs/guides/middleware.md index 8d68299835..1ae0da8676 100644 --- a/docs/guides/middleware.md +++ b/docs/guides/middleware.md @@ -16,7 +16,7 @@ Middleware is a Video.js feature that allows interaction with and modification o ## Understanding Middleware -Middleware are functions that return an object, a class instance, a prototype, etc, scoped to the Player with methods matching those on the `Tech`. There are currently a limited set of allowed methods that will be understood by middleware. These are: `buffered`, `currentTime`, `setCurrentTime`, `duration`, `seekable`, `played`, `play`, `pause` and `paused`. These allowed methods are split into three categories: [getters](#middleware-getters), [setters](#middleware-setters), and [mediators](#middleware-mediators). +Middleware are functions that return an object, a class instance, a prototype, etc, scoped to the Player with methods matching those on the `Tech`. There are currently a limited set of allowed methods that will be understood by middleware. These are: `buffered`, `currentTime`, `setCurrentTime`, `setMuted`, `setVolume`, `duration`, `muted`, `seekable`, `played`, `play`, `pause`, `paused` and `volume`. These allowed methods are split into three categories: [getters](#middleware-getters), [setters](#middleware-setters), and [mediators](#middleware-mediators). There are a few special methods that affect middleware: `setSource` and `setTech`. These are called internally by Video.js when you call `player.src()`. diff --git a/src/js/tech/middleware.js b/src/js/tech/middleware.js index 1653d48d04..4b49275ac1 100644 --- a/src/js/tech/middleware.js +++ b/src/js/tech/middleware.js @@ -184,9 +184,10 @@ export const allowedGetters = { buffered: 1, currentTime: 1, duration: 1, - seekable: 1, + muted: 1, played: 1, paused: 1, + seekable: 1, volume: 1 }; @@ -197,6 +198,7 @@ export const allowedGetters = { */ export const allowedSetters = { setCurrentTime: 1, + setMuted: 1, setVolume: 1 }; diff --git a/test/unit/player.test.js b/test/unit/player.test.js index e66a00224a..09f834ec38 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -1764,6 +1764,7 @@ QUnit.test('should not allow to register custom player when any player has been QUnit.test('techGet runs through middleware if allowedGetter', function(assert) { let cts = 0; + let muts = 0; let vols = 0; let durs = 0; let lps = 0; @@ -1772,14 +1773,17 @@ QUnit.test('techGet runs through middleware if allowedGetter', function(assert) currentTime() { cts++; }, - volume() { - vols++; - }, duration() { durs++; }, loop() { lps++; + }, + muted() { + muts++; + }, + volume() { + vols++; } })); @@ -1798,10 +1802,12 @@ QUnit.test('techGet runs through middleware if allowedGetter', function(assert) player.techGet_('volume'); player.techGet_('duration'); player.techGet_('loop'); + player.techGet_('muted'); assert.equal(cts, 1, 'currentTime is allowed'); assert.equal(vols, 1, 'volume is allowed'); assert.equal(durs, 1, 'duration is allowed'); + assert.equal(muts, 1, 'muted is allowed'); assert.equal(lps, 0, 'loop is not allowed'); middleware.getMiddleware('video/foo').pop(); @@ -1810,6 +1816,7 @@ QUnit.test('techGet runs through middleware if allowedGetter', function(assert) QUnit.test('techCall runs through middleware if allowedSetter', function(assert) { let cts = 0; + let muts = false; let vols = 0; let prs = 0; @@ -1822,6 +1829,10 @@ QUnit.test('techCall runs through middleware if allowedSetter', function(assert) vols++; return vols; }, + setMuted() { + muts = true; + return muts; + }, setPlaybackRate() { prs++; return prs; @@ -1843,12 +1854,14 @@ QUnit.test('techCall runs through middleware if allowedSetter', function(assert) player.techCall_('setCurrentTime', 10); player.techCall_('setVolume', 0.5); + player.techCall_('setMuted', true); player.techCall_('setPlaybackRate', 0.75); this.clock.tick(1); assert.equal(cts, 1, 'setCurrentTime is allowed'); assert.equal(vols, 1, 'setVolume is allowed'); + assert.equal(muts, true, 'setMuted is allowed'); assert.equal(prs, 0, 'setPlaybackRate is not allowed'); middleware.getMiddleware('video/foo').pop();