Skip to content

Commit f4ede6c

Browse files
authored
Merge pull request #833 from steveseguin/copilot/fix-display-media-overlay-duration
Preserve `0ms` duration for Display Media Overlay in Event Flow Editor
2 parents ad50962 + 9c2738f commit f4ede6c

4 files changed

Lines changed: 121 additions & 5 deletions

File tree

actions.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ <h2>Session ID Required</h2>
11491149
useLayer: payload.useLayer,
11501150
clearFirst: payload.clearFirst
11511151
};
1152-
playMediaFullscreen(payload.url, payload.mediaType || 'iframe', payload.duration || defaultDuration, opts);
1152+
playMediaFullscreen(payload.url, payload.mediaType || 'iframe', payload.duration ?? defaultDuration, opts);
11531153
} else {
11541154
console.warn("Play media action received without a URL.");
11551155
}
@@ -1572,7 +1572,7 @@ <h2>Session ID Required</h2>
15721572

15731573
// Function to play media with optional positioned area (percent-based)
15741574
function playMediaFullscreen(url, mediaType, duration, opts = {}) {
1575-
duration = duration || defaultDuration;
1575+
duration = duration ?? defaultDuration;
15761576
// Determine target container - use layer system if opts.useLayer is true
15771577
const useLayer = !!opts.useLayer;
15781578
const targetContainer = useLayer ? overlayLayers.media : mediaContainer;

actions/EventFlowEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ class EventFlowEditor {
20252025
// Media & Layer actions
20262026
case 'playTenorGiphy': {
20272027
const url = node.config.mediaUrl || '';
2028-
const duration = node.config.duration || 10000;
2028+
const duration = node.config.duration ?? 10000;
20292029
const shortUrl = url.length > 25 ? url.substring(0, 25) + '...' : url;
20302030
return `${shortUrl} (${duration}ms)`;
20312031
}
@@ -4238,7 +4238,7 @@ class EventFlowEditor {
42384238
</div>
42394239
<div class="property-group">
42404240
<label class="property-label">Duration (ms, 0 for manual close)</label>
4241-
<input type="number" class="property-input" id="prop-duration" value="${node.config.duration || 10000}" min="0">
4241+
<input type="number" class="property-input" id="prop-duration" value="${node.config.duration ?? 10000}" min="0">
42424242
<div class="property-help">How long the media stays on screen. 0 means it stays until the next 'play_media' action or manual intervention.</div>
42434243
</div>
42444244
<div class="property-group">

actions/EventFlowSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ class EventFlowSystem {
29392939
actionType: 'play_media', // This corresponds to the 'actionType' in actions.html
29402940
url: config.mediaUrl,
29412941
mediaType: config.mediaType || 'iframe',
2942-
duration: config.duration || 10000, // Pass duration to actions.html
2942+
duration: config.duration ?? 10000, // Pass duration to actions.html
29432943
// Positioning and sizing (percent-based)
29442944
width: (typeof config.width === 'number') ? config.width : undefined,
29452945
height: (typeof config.height === 'number') ? config.height : undefined,
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env node
2+
3+
const vm = require('vm');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const EFS_SRC = fs.readFileSync(
8+
path.join(__dirname, '..', 'actions', 'EventFlowSystem.js'),
9+
'utf8'
10+
);
11+
12+
function loadEventFlowSystem(windowOverrides = {}, globals = {}) {
13+
const sandbox = vm.createContext({
14+
window: {
15+
location: { search: '' },
16+
sendMessageToTabs: null,
17+
sendTargetP2P: null,
18+
sendToDestinations: null,
19+
fetchWithTimeout: null,
20+
sanitizeRelay: null,
21+
checkExactDuplicateAlreadyRelayed: null,
22+
messageStore: {},
23+
handleMessageStore: null,
24+
...windowOverrides,
25+
},
26+
console,
27+
setTimeout,
28+
clearTimeout,
29+
setInterval,
30+
clearInterval,
31+
Promise,
32+
IDBKeyRange: {},
33+
indexedDB: { open: () => ({}) },
34+
...globals,
35+
});
36+
37+
vm.runInContext(EFS_SRC + '\nwindow.EventFlowSystem = EventFlowSystem;', sandbox);
38+
return sandbox.window.EventFlowSystem;
39+
}
40+
41+
let passed = 0;
42+
let failed = 0;
43+
44+
function assert(condition, label) {
45+
if (condition) {
46+
console.log(` PASS ${label}`);
47+
passed++;
48+
} else {
49+
console.error(` FAIL ${label}`);
50+
failed++;
51+
}
52+
}
53+
54+
async function runTests() {
55+
console.log('\n[1] playTenorGiphy preserves explicit duration 0');
56+
{
57+
let sentPayload = null;
58+
const EFS = loadEventFlowSystem();
59+
const sys = new EFS({
60+
sendTargetP2P: (payload) => {
61+
sentPayload = payload;
62+
},
63+
});
64+
65+
await sys.executeAction(
66+
{
67+
id: 'media1',
68+
actionType: 'playTenorGiphy',
69+
config: {
70+
mediaUrl: 'https://giphy.com/embed/X9izlczKyCpmCSZu0l',
71+
mediaType: 'iframe',
72+
duration: 0,
73+
},
74+
},
75+
{ textonly: true }
76+
);
77+
78+
assert(sentPayload?.overlayNinja?.duration === 0, 'duration 0 is sent as 0 (manual close)');
79+
}
80+
81+
console.log('\n[2] playTenorGiphy keeps default duration when not configured');
82+
{
83+
let sentPayload = null;
84+
const EFS = loadEventFlowSystem();
85+
const sys = new EFS({
86+
sendTargetP2P: (payload) => {
87+
sentPayload = payload;
88+
},
89+
});
90+
91+
await sys.executeAction(
92+
{
93+
id: 'media2',
94+
actionType: 'playTenorGiphy',
95+
config: {
96+
mediaUrl: 'https://giphy.com/embed/X9izlczKyCpmCSZu0l',
97+
mediaType: 'iframe',
98+
},
99+
},
100+
{ textonly: true }
101+
);
102+
103+
assert(sentPayload?.overlayNinja?.duration === 10000, 'undefined duration falls back to 10000ms');
104+
}
105+
106+
console.log(`\n${'-'.repeat(50)}`);
107+
console.log(`Results: ${passed} passed, ${failed} failed`);
108+
if (failed > 0) {
109+
process.exit(1);
110+
}
111+
}
112+
113+
runTests().catch((err) => {
114+
console.error('Unexpected error:', err);
115+
process.exit(1);
116+
});

0 commit comments

Comments
 (0)