/**
 * Lightweight registry that lets the XR mirror expose its offscreen canvas
 * as the preferred broadcast source. ShareButton checks here first.
 */
let activeCanvas: HTMLCanvasElement | null = null;
const listeners = new Set<(c: HTMLCanvasElement | null) => void>();

export function setBroadcastSource(c: HTMLCanvasElement | null) {
  activeCanvas = c;
  listeners.forEach((cb) => cb(c));
}

export function getBroadcastSource(): HTMLCanvasElement | null {
  return activeCanvas;
}

export function onBroadcastSourceChange(cb: (c: HTMLCanvasElement | null) => void) {
  listeners.add(cb);
  return () => { listeners.delete(cb); };
}
