Feature: Play remote audio on iPhone via WebAudio + self-hosted Opus WASM
iOS WebKit lacks Media Source Extensions with WebM/Opus, so remote audio
was silent on iPhone Safari/Chrome even though audio frames kept flowing.
Add a Web Audio API fallback path that decodes Opus packets with the
`opus-decoder` WASM library and schedules them onto an AudioContext.
The decoder bundle is now self-hosted — served at /static/opus-decoder.min.js
by both the Go and C++ servers — instead of pulled from a CDN, which was
unreachable from some networks.
Gotcha fixed during bring-up: the unscoped `opus-decoder` build's
`OpusDecoder.decodeFrame` is synchronous and returns {channelData,
samplesDecoded, sampleRate, errors} directly, not a Promise, so it must be
called in try/catch rather than via .then().
Also remove the on-screen diagnostic overlay (audio toast + frame counter)
used while debugging the phone without a console; diagnostics now go to
console.* only.
Co-Authored-By: deepseek-v4-pro
This commit is contained in:
1 parent
d118558eda
commit
f3a05c14b1
10 files changed
+655
-13
No files matched your search
Binary file not shown.
@@ -266,6 +266,7 @@
|
|||||||
<None Include="res\Cur\MutiDrag.cur" />
|
<None Include="res\Cur\MutiDrag.cur" />
|
||||||
<None Include="res\My2015Remote.rc2" />
|
<None Include="res\My2015Remote.rc2" />
|
||||||
<None Include="res\web\fit.min.js" />
|
<None Include="res\web\fit.min.js" />
|
||||||
|
<None Include="res\web\opus-decoder.min.js" />
|
||||||
<None Include="res\web\xterm.css" />
|
<None Include="res\web\xterm.css" />
|
||||||
<None Include="res\web\xterm.min.js" />
|
<None Include="res\web\xterm.min.js" />
|
||||||
<None Include="stub2\stub32.bin" />
|
<None Include="stub2\stub32.bin" />
|
||||||
|
|||||||
@@ -232,6 +232,7 @@
|
|||||||
<None Include="res\web\xterm.min.js" />
|
<None Include="res\web\xterm.min.js" />
|
||||||
<None Include="res\web\xterm.css" />
|
<None Include="res\web\xterm.css" />
|
||||||
<None Include="res\web\fit.min.js" />
|
<None Include="res\web\fit.min.js" />
|
||||||
|
<None Include="res\web\opus-decoder.min.js" />
|
||||||
<None Include="..\web\index.html" />
|
<None Include="..\web\index.html" />
|
||||||
<None Include="stub2\stub32.bin" />
|
<None Include="stub2\stub32.bin" />
|
||||||
<None Include="stub2\stub64.bin" />
|
<None Include="stub2\stub64.bin" />
|
||||||
|
|||||||
@@ -255,6 +255,7 @@ void CWebService::ServerThread(int port) {
|
|||||||
static std::string cachedXtermJs = LoadBinaryResourceAsString(IDR_WEB_XTERM_JS);
|
static std::string cachedXtermJs = LoadBinaryResourceAsString(IDR_WEB_XTERM_JS);
|
||||||
static std::string cachedXtermCss = LoadBinaryResourceAsString(IDR_WEB_XTERM_CSS);
|
static std::string cachedXtermCss = LoadBinaryResourceAsString(IDR_WEB_XTERM_CSS);
|
||||||
static std::string cachedXtermFitJs = LoadBinaryResourceAsString(IDR_WEB_XTERM_FIT_JS);
|
static std::string cachedXtermFitJs = LoadBinaryResourceAsString(IDR_WEB_XTERM_FIT_JS);
|
||||||
|
static std::string cachedOpusDecoderJs = LoadBinaryResourceAsString(IDR_WEB_OPUS_DECODER_JS);
|
||||||
|
|
||||||
auto buildStatic = [](const std::string& body, const std::string& mime) {
|
auto buildStatic = [](const std::string& body, const std::string& mime) {
|
||||||
ws::HttpResponse r = ws::HttpResponse::OK(body, mime);
|
ws::HttpResponse r = ws::HttpResponse::OK(body, mime);
|
||||||
@@ -274,6 +275,9 @@ void CWebService::ServerThread(int port) {
|
|||||||
} else if (path == "/static/xterm-fit.js") {
|
} else if (path == "/static/xterm-fit.js") {
|
||||||
if (cachedXtermFitJs.empty()) return ws::HttpResponse::NotFound();
|
if (cachedXtermFitJs.empty()) return ws::HttpResponse::NotFound();
|
||||||
return buildStatic(cachedXtermFitJs, "application/javascript; charset=utf-8");
|
return buildStatic(cachedXtermFitJs, "application/javascript; charset=utf-8");
|
||||||
|
} else if (path == "/static/opus-decoder.min.js") {
|
||||||
|
if (cachedOpusDecoderJs.empty()) return ws::HttpResponse::NotFound();
|
||||||
|
return buildStatic(cachedOpusDecoderJs, "application/javascript; charset=utf-8");
|
||||||
} else if (path == "/health") {
|
} else if (path == "/health") {
|
||||||
return ws::HttpResponse::OK("{\"status\":\"ok\"}", "application/json");
|
return ws::HttpResponse::OK("{\"status\":\"ok\"}", "application/json");
|
||||||
} else if (path == "/manifest.json") {
|
} else if (path == "/manifest.json") {
|
||||||
|
|||||||
+232
@@ -0,0 +1,232 @@
|
|||||||
|
/* Copyright 2021-2026 Ethan Halsall. This file is part of wasm-audio-decoders. https://github.com/eshaz/wasm-audio-decoders */
|
||||||
|
var i,t;i=this,t=function(i,t){const e=(i,t=4294967295,e=79764919)=>{const H=new Int32Array(256);let s,h,r,n=t;for(s=0;s<256;s++){for(r=s<<24,h=8;h>0;--h)r=2147483648&r?r<<1^e:r<<1;H[s]=r}for(s=0;s<i.length;s++)n=n<<8^H[255&(n>>24^i[s])];return n},H=(i,t=e)=>{const H=i=>new Uint8Array(i.length/2).map((t,e)=>parseInt(i.substring(2*e,2*(e+1)),16)),s=i=>H(i)[0],h=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach((i,t)=>h.set(i,t));const r=new Uint8Array(i.length);let n,M,o,a=!1,c=0,I=42,u=i.length>13&&"dynEncode"===i.substring(0,9),y=0;u&&(y=11,M=s(i.substring(9,y)),M<=1&&(y+=2,I=s(i.substring(11,y))),1===M&&(y+=8,o=(i=>new DataView(H(i).buffer).getInt32(0,!0))(i.substring(13,y))));const l=256-I;for(let e=y;e<i.length;e++)if(n=i.charCodeAt(e),61!==n||a){if(92===n&&e<i.length-5&&u){const t=i.charCodeAt(e+1);117!==t&&85!==t||(n=parseInt(i.substring(e+2,e+6),16),e+=5)}if(n>255){const i=h.get(n);i&&(n=i+127)}a&&(a=!1,n-=64),r[c++]=n<I&&n>0?n+l:n-I}else a=!0;const d=r.subarray(0,c);if(u&&1===M){const i=t(d);if(i!==o){const t="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",t+"\n","Expected: "+o+"; Got: "+i+"\n","Visit https://github.com/eshaz/simple-yenc for more information"),Error(t)}}return d};function s(){const i=Uint8Array,t=Float32Array;s.t||Object.defineProperties(s,{t:{value:new WeakMap},H:{value(i,t){s.t.set(i,Promise.resolve(t))}},M:{value(i,t){let e=s.t.get(i);return e||(t?e=WebAssembly.compile(H(t)):(t=i.I,e=s.u(t).then(i=>WebAssembly.compile(i))),s.t.set(i,e)),e}},p:{value(i,e){let H=new t(e),s=0,h=0;for(;s<i.length;)H.set(i[s],h),h+=i[s++].length;return H}},J:{value:(i,t,e,H,s)=>({errors:i,channelData:t,samplesDecoded:e,sampleRate:H,bitDepth:s})},W:{value(i,t,e,H,h,r){let n,M,o=[];for(n=0;n<e;n++){const i=[];for(M=0;M<t.length;)i.push(t[M++][n]||[]);o.push(s.p(i,H))}return s.J(i,o,H,h,r)}},u:{value(t){return t=H(t),new Promise(e=>{const H=String.raw`dynEncode012804c7886d()((()>+*§§)§,§§§§)§+§§§)§+.-()(*)-+)(.7*§)i¸¸,3§(i¸¸,3/G+.¡*(,(,3+)2å:-),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)^*<H,H(P*4U((I-H(H*i0J,^*DH+H-H*I+H,I*4)33H(H*H)^*DH(H+H)^*@H+i§H)i§3æ*).§K(iHI/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)J.H.W)(i)c)(H,i)I,H-i*I-4)33i(I.*hH(V)(H+n5(H(i*I-i(I,i)I.+hH,i*J+iHn,hi(I-i*I,+hH,H/H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)J(H(V)(J(i)c)(H)H(i)H,c)(3H*i*I*H,i)I,4(3(-H(H,W)(H-I-H,i*I,4)3(3(3H,H-I1H+I,H.i)H1V)(J.i(v5(33H.-H(H,i(c)(H,i*I,4)333)-§i*I*+§H*iHn,hi73H,H(i)8(H+J+H)P*(H*V)(J-r,§H)P*,H.i)H+H,i)V)(-H*i*I*H+i)I+H-H.I.H,H-i)I,4)333Ã+)-§iø7i(^*(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