Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions assets/src/js/godam-player/managers/configurationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import { parseDataAttribute } from '../utils/dataHelpers.js';
* SkipForward / SkipBackward components) and hides them for anything else —
* a missing value or a numeric string included.
*/
const VALID_SKIP_DURATIONS = [ 5, 10, 30 ];
const DEFAULT_SKIP_DURATION = 10;
export const VALID_SKIP_DURATIONS = [ 5, 10, 30 ];
export const DEFAULT_SKIP_DURATION = 10;

/**
* Coerce a skip-buttons config into a value Video.js will actually render.
*
* Exported so the Video Editor's Settings preview can normalize saved durations
* exactly as the front-end player does, keeping the two in step.
*
* @param {Object|boolean|undefined} skipButtons - Raw skipButtons config.
* @return {Object} Normalized `{ forward, backward }` config.
*/
function normalizeSkipButtons( skipButtons ) {
export function normalizeSkipButtons( skipButtons ) {
const raw = ( skipButtons && typeof skipButtons === 'object' ) ? skipButtons : {};
const candidates = [ raw.forward, raw.backward ].map( ( value ) => parseInt( value, 10 ) );
const duration = candidates.find( ( value ) => VALID_SKIP_DURATIONS.includes( value ) ) ?? DEFAULT_SKIP_DURATION;
Expand Down
18 changes: 17 additions & 1 deletion assets/src/js/godam-player/managers/hoverManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,24 @@ class HoverManager {

const played = this.player.play();
Promise.resolve( played )
.then( () => this.applyPreviewMute() )
.then( () => {
// A click may have committed real playback while this preview
// play() was still pending; re-applying the preview mute would
// then silence the real video the viewer just started.
if ( this.isVideoClicked ) {
return;
Comment on lines +441 to +442
}
this.applyPreviewMute();
} )
.catch( () => {
// A click may have committed real playback while this preview
// play() was still pending (e.g. autoplay was refused, then the
// viewer clicked to play with a gesture). Tearing the preview
// down now would pause that real playback, reset it to frame 0
// and restore the poster, so leave it alone.
if ( this.isVideoClicked ) {
return;
}
// Autoplay was refused (e.g. iOS Low Power Mode), so no `play`
// event will fire to clear `isPreviewInitiatedPlay`. Roll the
// flags back and fully tear the preview down – otherwise the
Expand Down
56 changes: 56 additions & 0 deletions assets/src/js/godam-player/managers/hoverManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,62 @@ describe( 'HoverManager preview suppression flag', () => {
} );
} );

describe( 'HoverManager preview play() settlement race', () => {
beforeEach( () => jest.useFakeTimers() );
afterEach( () => jest.useRealTimers() );

// Flush the microtask queue so the play() promise's then/catch handlers run.
const flush = async () => {
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
};

it( 'does not tear down playback when a click commits before a refused autoplay rejects', async () => {
const player = createPlayer();
player.play = jest.fn( () => Promise.reject( new Error( 'autoplay refused' ) ) );
const manager = createManager( player );

manager.startPreview();
// A click commits real playback while the preview play() is still pending.
manager.isVideoClicked = true;

await flush();

// stopPreview() would pause the now-real playback and reset it to 0; skip it.
expect( player.pause ).not.toHaveBeenCalled();
} );

it( 'still tears the preview down when autoplay is refused and no click intervened', async () => {
const player = createPlayer();
player.play = jest.fn( () => Promise.reject( new Error( 'autoplay refused' ) ) );
const manager = createManager( player );

manager.startPreview();

await flush();

expect( player.pause ).toHaveBeenCalled();
expect( manager.isPreviewPlaying ).toBe( false );
} );

it( 'does not re-apply the preview mute once a click has committed playback', async () => {
const player = createPlayer();
player.play = jest.fn( () => Promise.resolve() );
const manager = createManager( player );

manager.startPreview();
const mutedCallsAfterStart = player.muted.mock.calls.length;
manager.isVideoClicked = true;

await flush();

// applyPreviewMute() would call muted() again; the committed real playback
// must keep the viewer's audio.
expect( player.muted.mock.calls.length ).toBe( mutedCallsAfterStart );
} );
} );

describe( 'HoverManager hover-intent delay', () => {
beforeEach( () => jest.useFakeTimers() );
afterEach( () => jest.useRealTimers() );
Expand Down
12 changes: 6 additions & 6 deletions pages/video-editor/VideoEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { openAttachmentDetailsModal } from './utils/openAttachmentDetails';
import { getFormIdFromLayer } from './utils/formUtils';
import { canManageAttachment } from '../../assets/src/js/media-library/utility.js';
import { ensureAddonLayersRegistered } from './utils/loadAddonLayers';
import { normalizeSkipButtons } from '../../assets/src/js/godam-player/managers/configurationManager.js';

/**
* Decode HTML entities in a string (e.g. `&` → `&`).
Expand Down Expand Up @@ -650,9 +651,10 @@ const VideoEditor = ( { attachmentID, onBackToAttachmentPicker } ) => {
// them to Video.js on the front end. `VideoJSPlayer` keeps the bar in step as
// the settings change; this only seeds the initial composition.
//
// Skip buttons render only when a duration is actually stored, matching the
// front end (which passes the saved `controlBar` through verbatim).
const skipDuration = Number( videoConfig?.controlBar?.skipButtons?.forward ) || 0;
// Skip buttons always render on the front end, at a normalized 5/10/30s
// duration (falling back to 10). Run the saved value through the same
// normalization here so the preview never shows a duration — or an
// enabled/disabled state — the front-end player wouldn't.
const previewControlBar = {
playToggle: true,
volumePanel: Boolean( videoConfig?.controlBar?.volumePanel ),
Expand All @@ -664,9 +666,7 @@ const VideoEditor = ( { attachmentID, onBackToAttachmentPicker } ) => {
// without rebuilding the bar.
subsCapsButton: true,
pictureInPictureToggle: Boolean( videoConfig?.controlBar?.pictureInPictureToggle ),
skipButtons: skipDuration
? { forward: skipDuration, backward: skipDuration }
: false,
skipButtons: normalizeSkipButtons( videoConfig?.controlBar?.skipButtons ),
};

// Fallback title matches the attachment's media type (video/audio/image).
Expand Down
7 changes: 5 additions & 2 deletions pages/video-editor/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'videojs-flvjs-es6';
*/
import GoDAM from '../../assets/src/images/godam-branding.svg';
import PlayerProgressStripe from './components/player/PlayerProgressStripe';
import { normalizeSkipButtons } from '../../assets/src/js/godam-player/managers/configurationManager.js';

/**
* WordPress dependencies
Expand Down Expand Up @@ -218,8 +219,10 @@ export const VideoJS = ( props ) => {
syncBrandingIcon( controlBar, controlBarSettings );

// Rebuilding the skip buttons throws away live components, so only do it
// when the duration actually changed (not on every colour tweak).
const skipSeconds = Number( controlBarSettings.skipButtons?.forward ) || 0;
// when the duration actually changed (not on every colour tweak). Normalize
// exactly as the front-end player does (5/10/30, default 10) so the preview
// applies the same duration the front end will.
const skipSeconds = normalizeSkipButtons( controlBarSettings.skipButtons ).forward;
if ( appliedSkipSecondsRef.current !== skipSeconds ) {
appliedSkipSecondsRef.current = skipSeconds;
syncSkipButtons( controlBar, skipSeconds );
Expand Down
6 changes: 6 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@

$rtgodam_uninstall_options = array(
'rtgodam_plugin_version',
'rtgodam_plugin_activation_time',
'rtgodam_show_whats_new',
'rtgodam_user_data',
'rtgodam-settings',
'rtgodam-api-key',
'rtgodam-api-key-stored',
'rtgodam-account-token',
'rtgodam-api-key-status',
'rtgodam-api-key-error-since',
'rtgodam-offer-banner',
'rtgodam-failed-transcoding-attachments',
'rtgodam_new_attachment',
'rtgodam_video_metadata_migration_completed',
);

$rtgodam_uninstall_transients = array(
Expand Down
Loading