debug: instrument bzApplyRoute to see if native AudioRoute plugin registered + setSpeaker result (batch146)

This commit is contained in:
2026-07-20 16:43:39 +05:30
parent 5960efb612
commit a574816eaa
+8 -2
View File
@@ -1158,7 +1158,7 @@
</head>
<body>
<script src="/icons.js?v=6"></script>
<script>window.__BUILD='2026-07-20-batch145';console.log('%cBiz Connect','color:#1F3B73;font-weight:bold','build '+window.__BUILD);
<script>window.__BUILD='2026-07-20-batch146';console.log('%cBiz Connect','color:#1F3B73;font-weight:bold','build '+window.__BUILD);
// Emoji are rendered with the OS's own (colour) emoji font — instant, zero network.
//
// We used to run Twemoji over every emoji, which swapped each one for an <img> pulled INDIVIDUALLY from
@@ -4368,7 +4368,13 @@ function isMobileUA(){ return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.
// Native iOS AudioRoute plugin (injected into the app via ios-patch.sh) — switches earpiece<->speaker at the
// AVAudioSession level, which the web setSinkId API can't do on iOS. Null in the browser/PWA/Android.
function nativeAudioRoute(){ try{ var C=window.Capacitor; return (C && C.getPlatform && C.getPlatform()==='ios' && C.Plugins && C.Plugins.AudioRoute) ? C.Plugins.AudioRoute : null; }catch(_){ return null; } }
function bzApplyRoute(route){ var ar=nativeAudioRoute(); if(ar){ try{ ar.setSpeaker({ on: route!=='earpiece' }); }catch(_){} } } // speaker/bt -> loudspeaker override; earpiece -> default route (BT auto-selected if connected)
function bzApplyRoute(route){
var ar=nativeAudioRoute();
// TEMP diagnostic: report whether the native plugin registered and what setSpeaker does, so we can see on
// device WHY the toggle isn't switching (plugin missing? setSpeaker rejecting? route not holding?).
if(window.bzDbg){ try{ var C=window.Capacitor; window.bzDbg('route',{ stage:'apply', route:route, has:ar?1:0, plat:(C&&C.getPlatform&&C.getPlatform())||'', plugins:(C&&C.Plugins)?Object.keys(C.Plugins).slice(0,30).join(','):'none' }); }catch(_){} }
if(ar){ try{ var pr=ar.setSpeaker({ on: route!=='earpiece' }); if(pr&&pr.then){ pr.then(function(r){ if(window.bzDbg) window.bzDbg('route',{stage:'ok', route:route, r:JSON.stringify(r||{})}); }).catch(function(e){ if(window.bzDbg) window.bzDbg('route',{stage:'reject', route:route, err:String((e&&e.message)||e)}); }); } }catch(e){ if(window.bzDbg) window.bzDbg('route',{stage:'threw', err:String((e&&e.message)||e)}); } } // speaker/bt -> loudspeaker override; earpiece -> default route (BT auto-selected if connected)
}
// The speaker toggle is usable if the browser supports output switching (setSinkId) OR the native iOS route
// plugin is present.
function canRouteAudio(){ try{ if(nativeAudioRoute()) return true; return typeof HTMLMediaElement!=='undefined' && typeof HTMLMediaElement.prototype.setSinkId==='function'; }catch(_){ return false; } }