Skip to content

Commit

Permalink
Store previous src for media event file names
Browse files Browse the repository at this point in the history
When a player is unallocated, we reset src to a blank media file via a
placeholder data url and pause the player. The player still triggers
timeupdate and pause events that we want to turn into media events. We
do not want to report the data url as file name, since analytics
integrations rely on stable file names. We thus store the previous src
and use that wehn reporting the remaining events.

REDMINE-20591
  • Loading branch information
tf committed Feb 7, 2024
1 parent ffb57cc commit de94bf4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions package/spec/frontend/media/MediaPool_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ describe('MediaPool', function() {

expect(callback).toHaveBeenCalled();
});

it('stores previous src until reallocated', function () {
let pool = new MediaPool();
let player = pool.allocatePlayer({playerType: MediaType.VIDEO});
player.src('www.example.com/test.mp4');
expect(player.getMediaElement().hasAttribute('src')).toBe(true);

pool.unAllocatePlayer(player);
expect(player.previousSrc).toStrictEqual('www.example.com/test.mp4');

player = pool.allocatePlayer({playerType: MediaType.VIDEO});
expect(player.previousSrc).toBeNull();
});
});

describe('#blessAll', function() {
Expand Down
2 changes: 1 addition & 1 deletion package/src/frontend/VideoPlayer/mediaEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const mediaEvents = function(player, context) {
function triggerMediaEvent(name) {
if (context) {
events.trigger('media:' + name, {
fileName: player.currentSrc(),
fileName: player.previousSrc || player.currentSrc(),
context: context,
currentTime: player.currentTime(),
duration: player.duration(),
Expand Down
3 changes: 3 additions & 0 deletions package/src/frontend/media/MediaPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class MediaPool {

player.playerId = playerId || this.allocatedPlayers[playerType].length
player.releaseCallback = onRelease;
player.previousSrc = null;

return player;
}
Expand All @@ -79,6 +80,8 @@ export class MediaPool {
let type = this.getMediaTypeFromEl(player.el());
this.allocatedPlayers[type] = this.allocatedPlayers[type].filter(p=>p!=player);

player.previousSrc = player.currentSrc();

player.controls(false);
player.getMediaElement().loop = false;
player.playsinline(false);
Expand Down

0 comments on commit de94bf4

Please sign in to comment.