BoxOfColors commited on
Commit
f300658
·
1 Parent(s): 3b9db74

Debug: console.log in waveform click and global message listener

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -1217,6 +1217,7 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1217
  // The parent page (Gradio) has a global window.addEventListener('message',...)
1218
  // set up via gr.Blocks(js=...) that handles popup show/hide and regen trigger.
1219
  function showPopup(idx, mx, my) {{
 
1220
  // Convert iframe-local coords to parent page coords
1221
  try {{
1222
  const fr = window.frameElement ? window.frameElement.getBoundingClientRect() : {{left:0,top:0}};
@@ -1226,7 +1227,9 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1226
  t0: segments[idx][0], t1: segments[idx][1],
1227
  x: mx + fr.left, y: my + fr.top
1228
  }}, '*');
 
1229
  }} catch(e) {{
 
1230
  window.parent.postMessage({{
1231
  type:'wf_popup', action:'show',
1232
  slot_id: SLOT_ID, seg_idx: idx,
@@ -1297,6 +1300,7 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1297
  const tClick=xRel*duration;
1298
  let hit=-1;
1299
  segments.forEach(function(seg,idx){{ if(tClick>=seg[0]&&tClick<=seg[1]) hit=idx; }});
 
1300
  if (hit>=0) showPopup(hit, e.clientX, e.clientY);
1301
  else hidePopup();
1302
  }};
@@ -1718,6 +1722,7 @@ _GLOBAL_JS = """
1718
 
1719
  window.addEventListener('message', function(e) {
1720
  const d = e.data;
 
1721
  if (!d || d.type !== 'wf_popup') return;
1722
  const p = ensurePopup();
1723
  if (d.action === 'hide') { hidePopup(); return; }
 
1217
  // The parent page (Gradio) has a global window.addEventListener('message',...)
1218
  // set up via gr.Blocks(js=...) that handles popup show/hide and regen trigger.
1219
  function showPopup(idx, mx, my) {{
1220
+ console.log('[wf showPopup] slot='+SLOT_ID+' idx='+idx+' posting to parent');
1221
  // Convert iframe-local coords to parent page coords
1222
  try {{
1223
  const fr = window.frameElement ? window.frameElement.getBoundingClientRect() : {{left:0,top:0}};
 
1227
  t0: segments[idx][0], t1: segments[idx][1],
1228
  x: mx + fr.left, y: my + fr.top
1229
  }}, '*');
1230
+ console.log('[wf showPopup] postMessage sent OK');
1231
  }} catch(e) {{
1232
+ console.log('[wf showPopup] postMessage fallback, err='+e.message);
1233
  window.parent.postMessage({{
1234
  type:'wf_popup', action:'show',
1235
  slot_id: SLOT_ID, seg_idx: idx,
 
1300
  const tClick=xRel*duration;
1301
  let hit=-1;
1302
  segments.forEach(function(seg,idx){{ if(tClick>=seg[0]&&tClick<=seg[1]) hit=idx; }});
1303
+ console.log('[wf click] tClick='+tClick.toFixed(2)+' hit='+hit+' audioDuration='+audioDuration+' segments='+JSON.stringify(segments));
1304
  if (hit>=0) showPopup(hit, e.clientX, e.clientY);
1305
  else hidePopup();
1306
  }};
 
1722
 
1723
  window.addEventListener('message', function(e) {
1724
  const d = e.data;
1725
+ console.log('[global msg] received type=' + (d && d.type) + ' action=' + (d && d.action));
1726
  if (!d || d.type !== 'wf_popup') return;
1727
  const p = ensurePopup();
1728
  if (d.action === 'hide') { hidePopup(); return; }