Skip to content

Commit

Permalink
Add feature flag to enlarge player pool
Browse files Browse the repository at this point in the history
REDMINE-20506
  • Loading branch information
tf committed Nov 28, 2023
1 parent 10043bf commit 9a932aa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/initializers/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
config.features.register('webp_images')
config.features.register('highdef_video_encoding')
config.features.register('force_fullhd_video_quality')
config.features.register('large_player_pool')
config.features.register('selectable_themes')
end
21 changes: 21 additions & 0 deletions package/spec/frontend/media/MediaPool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ describe('MediaPool', function() {
expect(reusedPlayer).toBe(player);
expect(player.textTracks().length).toEqual(0);
});

it('supports supplying player count via function', () => {
const pool = new MediaPool({playerCount: playerType => {
if (playerType === MediaType.AUDIO) {
return 2;
}
else {
return 5;
}
}});

const audioPlayers = new Set(Array(10).fill().map(() =>
pool.allocatePlayer({playerType: MediaType.AUDIO})
));
const videoPlayers = new Set(Array(10).fill().map(() =>
pool.allocatePlayer({playerType: MediaType.VIDEO})
));

expect(audioPlayers.size).toEqual(2);
expect(videoPlayers.size).toEqual(5);
});
});

describe('#unallocatePlayer', function() {
Expand Down
6 changes: 5 additions & 1 deletion package/src/frontend/media/MediaPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export class MediaPool {
return player;
}
initializeMediaPool_(type, mediaElSeed){
while ( this.allPlayersForType(type).length<this.playerCount ) {
const playerCount = typeof this.playerCount === 'function' ?
this.playerCount(type) :
this.playerCount;

while (this.allPlayersForType(type).length < playerCount ) {
this.createPlayer_(type, mediaElSeed.cloneNode(true));
}
}
Expand Down
5 changes: 4 additions & 1 deletion package/src/frontend/media/media.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {MediaPool, MediaType} from './MediaPool';
import BackboneEvents from 'backbone-events-standalone';
import {features} from '../features';

export const media = {
playerPool: new MediaPool(),
playerPool: new MediaPool({
playerCount: () => features.isEnabled('large_player_pool') ? 10 : 4
}),
muteState: true,
get muted(){ return this.muteState; },
mute: function (value) {
Expand Down

0 comments on commit 9a932aa

Please sign in to comment.