Adaptive Music v0.8.1 combat automation fixes
Validate and generate manual release / package (push) Waiting to run

This commit is contained in:
Jason committed 2026-12-05 13:37:05 -05:00
1 parent 95b0427aa1
commit 357c904d1b
26 files changed
+1387 -138

No files matched your search

+28 -5
View File
@@ -38,6 +38,12 @@ const messages={
'uncertain':'MA did not confirm a queue write. Automation stopped to avoid duplicate playback. Review this dedicated queue before reconnecting.',
'unavailable':'The operation failed. Your private inputs are retained. Run the browser connection check to separate transport failures from receiver and audio setup.'
};
const connectionStages=new Set(['API authentication','Sendspin authentication','Noise handshake','receiver pairing',
'clock synchronization','dedicated receiver verification','catalog retrieval','dedicated queue verification']);
function diagnosticFailure(error){
return {code:Object.hasOwn(messages,error?.code)?error.code:'unavailable',
...(connectionStages.has(error?.stage)&&{stage:error.stage})};
}
export function connectionMessage(error){
if(error?.code==='ws-upgrade-failed'&&error.stage==='Sendspin authentication')return 'The browser could not open the receiver’s /sendspin WebSocket. Check both routes from this Foundry page.';
if(error?.upstreamCode===2&&['player_queues/play_media','player_queues/play_index'].includes(error.command))return 'MA could not find playable media for this playlist (MA error 2). Check its content/provider in MA or choose another playlist. Automation stopped after an unconfirmed queue write.';
@@ -105,12 +111,13 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
const iceExpiry=input(advancedFields,'TURN credential expiry (UTC)','datetime-local');
const diagnosticsActions=make('div');diagnosticsActions.className='adaptive-actions';
const report=make('div');report.setAttribute('aria-live','polite');
let transportResults=[],busy=false,hadDeviceCredential=initial.deviceCredential;
const run=async(action,label)=>{
let transportResults=[],transportCheckAt,lastConnectFailure,busy=false,hadDeviceCredential=initial.deviceCredential;
const run=async(action,label,onFailure)=>{
if(busy||!game.user.isGM)return;
busy=true;retainError.hidden=true;render();
try{await action();}
catch(error){
onFailure?.(error);
busy=false;render();error.field?.focus?.();
retainError.textContent=`${typeof label==='function'?label(error):label}. ${connectionMessage(error)}`;retainError.hidden=false;onError(error);
}finally{busy=false;render();}
@@ -129,6 +136,7 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
catch{return false;}
}
const connect=button(actions,'Connect',()=>run(async()=>{
lastConnectFailure=undefined;
let maUrl;
const useSaved=!address.value.trim()&&connection.draftFields?.savedConnection;
if(!useSaved)try{maUrl=validatedAddress();}catch(error){throw {code:error.code,field:address};}
@@ -148,7 +156,8 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
address.value=connection.draftFields?.maUrl??address.value;
await onCatalog();
status.textContent=result?.attachedExistingQueue?'Connected. The existing queue is preserved. Enable automation from Playback when you’re ready.':'Campaign audio connected. Choose playlists for your scene.';
},error=>['address-invalid','token-invalid','token-required','receiver-name-invalid','ice-config-invalid'].includes(error.code)?'Check your settings':failureStage(error)));
},error=>['address-invalid','token-invalid','token-required','receiver-name-invalid','ice-config-invalid'].includes(error.code)?'Check your settings':failureStage(error),
error=>{lastConnectFailure={at:new Date().toISOString(),...diagnosticFailure(error)};}));
connect.className='adaptive-primary';
const nextButton=button(actions,'Choose scene music',()=>next?.());
const disconnect=button(actions,'Disconnect',()=>run(async()=>{
@@ -158,13 +167,27 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
await connection.forgetCredentials();remember.checked=false;token.value='';status.textContent='Credentials removed from this device.';await onCatalog();
},'Could not forget credentials'));
button(diagnosticsActions,'Check browser connection',()=>run(async()=>{
report.replaceChildren();transportResults=await probeWebSockets(validatedAddress());
report.replaceChildren();transportResults=[];transportCheckAt=undefined;
transportResults=await probeWebSockets(validatedAddress());
transportCheckAt=new Date().toISOString();
for(const result of transportResults)make('p',`${result.path} — ${diagnosticMessage(result)}`,report);
status.textContent='Browser checks complete.';
},'Browser connection check failed'));
button(diagnosticsActions,'Copy connection diagnostics',()=>run(async()=>{
const d=connection.status;
await navigator.clipboard.writeText(JSON.stringify({state:d.state,stage:d.stage,catalog:d.catalog,audioContext:d.audioContext,decodedFrames:d.decodedFrames,scheduledFrames:d.scheduledFrames,droppedLate:d.droppedLate,droppedAhead:d.droppedAhead,bufferedMs:d.bufferedMs,underruns:d.underruns,bufferOverruns:d.bufferOverruns,sourceGaps:d.sourceGaps,sourceOverlaps:d.sourceOverlaps,gapMs:d.gapMs,overlapMs:d.overlapMs,muted:d.muted,pauseMode:d.pauseMode,signalRMS:d.rms,outputRMS:d.outputRMS,listenerConnections:d.peers??0,lastError:d.lastError,listenerDiagnostics:d.listenerDiagnostics,transport:transportResults,secureContext:globalThis.isSecureContext},null,2));
const details={
state:d.state,stage:d.stage,catalog:d.catalog,audioContext:d.audioContext,
decodedFrames:d.decodedFrames,scheduledFrames:d.scheduledFrames,
droppedLate:d.droppedLate,droppedAhead:d.droppedAhead,bufferedMs:d.bufferedMs,
underruns:d.underruns,bufferOverruns:d.bufferOverruns,
sourceGaps:d.sourceGaps,sourceOverlaps:d.sourceOverlaps,gapMs:d.gapMs,overlapMs:d.overlapMs,
muted:d.muted,pauseMode:d.pauseMode,signalRMS:d.rms,outputRMS:d.outputRMS,
listenerConnections:d.peers??0,lastError:d.lastError,listenerDiagnostics:d.listenerDiagnostics,
transport:transportResults,transportCheckAt,lastConnectFailure,
automaticConnectFailure:d.deviceError?diagnosticFailure({code:d.deviceError}):undefined,
secureContext:globalThis.isSecureContext,
};
await navigator.clipboard.writeText(JSON.stringify(details,null,2));
status.textContent='Connection diagnostics copied.';
},'Could not copy diagnostics'));
const advancedActions=make('div',null,advanced);advancedActions.className='adaptive-actions';