Adaptive Music v0.8.0 release candidate
Validate and generate manual release / package (push) Waiting to run
Validate and generate manual release / package (push) Waiting to run
This commit is contained in:
1 parent
8c07a468a4
commit
95b0427aa1
48 files changed
+3631
-313
No files matched your search
@@ -4,6 +4,9 @@ import {probeWebSockets,diagnosticMessage} from '../providers/ma/diagnostics.mjs
|
||||
const messages={
|
||||
'saved-connection-unavailable':'This token could not unlock the saved connection. Enter the server address and a valid token to save a new connection.',
|
||||
'saved-connection-write-failed':'Connected, but Foundry could not save the connection for this account.',
|
||||
'private-credential-write-failed':'Connected, but the browser could not remember the credential on this device.',
|
||||
'receiver-storage-write-failed':'The browser could not update the remembered receiver. Check site storage before reconnecting.',
|
||||
'private-credential-corrupt':'The device credential could not be unlocked. Use Forget Credentials and enter a valid token.',
|
||||
'ice-config-invalid':'Enter a valid existing STUN/TURN URL. TURN also needs a username, credential and UTC expiry within one hour. No network setting was applied.',
|
||||
'token-required':'Enter a Music Assistant access token for this server.',
|
||||
'token-invalid':'Remove line breaks from the access token and try again.',
|
||||
@@ -18,24 +21,32 @@ const messages={
|
||||
'ws-command-failed':'MA rejected a command. The account needs music-provider access and permission to control and pair its dedicated web receiver.',
|
||||
'sendspin-auth-failed':'The receiver socket opened, but Sendspin authentication failed. Verify the authenticated /sendspin route, separate from /ws.',
|
||||
'sendspin-sync-failed':'Sendspin did not complete pairing and clock synchronization. Retry the remembered receiver; transport HTTP 101 alone does not prove a working audio receiver.',
|
||||
'audio-context-unavailable':'This browser could not start Web Audio. Check the browser’s audio output and whether another device is using it exclusively.',
|
||||
'insecure-context':'Open Foundry over trusted HTTPS to use secure browser audio APIs.',
|
||||
'mixed-content':'HTTPS Foundry requires a trusted HTTPS MA address. Browser security cannot permit an HTTP/ws downgrade.',
|
||||
'reconcile-required':'This dedicated receiver has an existing queue. Playback was left untouched. Resume the remembered receiver after reviewing its queue in MA, or use a new dedicated receiver.',
|
||||
'catalog-empty':'No available music providers were returned. Check the dedicated MA account’s music-provider access.',
|
||||
'unsupported':'This queue or browser feature is unsupported. Use a standalone receiver with a static queue, shuffle and autoplay off, and a browser with Web Locks, Web Audio and WebRTC.',
|
||||
'private-storage-unavailable':'This browser denied private receiver storage. Allow site storage for Foundry, then retry. No MA token is stored there.',
|
||||
'private-storage-unavailable':'This browser denied private storage. Allow site storage for this Foundry address and retry.',
|
||||
'private-storage-corrupt':'The remembered receiver could not be decrypted. Use Forget remembered receiver below to create a replacement. Existing MA queues are left untouched.',
|
||||
'identity-mismatch':'The remembered receiver identity does not match this connection. Forget that receiver to create a new campaign receiver.',
|
||||
'dedicated-target-required':'The receiver did not match the identity and name created for this campaign. No unrelated player was selected.',
|
||||
'receiver-queue-unavailable':'MA did not make this receiver’s queue available after connection. Retry connecting the remembered receiver.',
|
||||
'receiver-access-lost':'Music Assistant withdrew this receiver’s queue access. If another MA browser player uses this token, give the two players separate tokens. Review the dedicated receiver before reconnecting.',
|
||||
'denied':'The dedicated receiver, account permission or active GM check failed. Keep one active GM and verify that this account can control its campaign receiver.',
|
||||
'stale':'GM authority or the connection changed during setup. Keep one active GM, then retry.',
|
||||
'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.'
|
||||
};
|
||||
export const connectionMessage=error=>error?.upstreamCode===2&&['player_queues/play_media','player_queues/play_index'].includes(error.command)?'MA could not find playable media for this playlist (MA error 2). Check its content/provider in MA or choose another playlist. Automation stopped; an unconfirmed queue write is never retried.':messages[error?.code]??messages.unavailable;
|
||||
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.';
|
||||
return messages[error?.code]??messages.unavailable;
|
||||
}
|
||||
|
||||
function failureStage(error) {
|
||||
if(error?.code==='audio-context-unavailable')return 'Browser audio unavailable';
|
||||
if(error?.stage==='Sendspin authentication'&&error.code==='ws-upgrade-failed')return 'Receiver connection failed';
|
||||
if (['ws-upgrade-failed', 'ws-disconnected', 'mixed-content', 'insecure-context'].includes(error?.code)) return 'Connection failed';
|
||||
if (['ws-auth-denied', 'ws-auth-timeout'].includes(error?.code) || error?.stage === 'API authentication') return 'Authentication failed';
|
||||
if (['receiver pairing','dedicated receiver verification','dedicated queue verification','Noise handshake'].includes(error?.stage) || error?.code === 'sendspin-sync-failed') return 'Receiver setup failed';
|
||||
@@ -75,14 +86,17 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
const initial=connection.draftFields??{};
|
||||
make('h2','Connect Music Assistant');
|
||||
make('p','Enter your Music Assistant address and access token. Adaptive Music creates or reconnects your campaign receiver and loads your playlists.');
|
||||
if(initial.savedConnection)make('p','This Foundry account has a saved connection. Enter its access token to unlock the address, or enter a different address to replace it.');
|
||||
if(initial.savedConnection&&!initial.deviceCredential)make('p','This Foundry account has a saved connection. Enter its access token to unlock the address, or enter a different address to replace it.');
|
||||
const fields=make('div');fields.className='adaptive-fields';
|
||||
const address=input(fields,'Music Assistant server address','url');address.placeholder='https://ma.example.test';address.value=initial.maUrl??'';
|
||||
const token=input(fields,'Private GM access token','password');
|
||||
const remember=input(fields,'Remember credentials and reconnect on this trusted device','checkbox');remember.checked=initial.deviceCredential===true;
|
||||
make('p','Use a revocable Music Assistant token. Remembered credentials belong to this browser profile. Enable this only on a device and Foundry site you trust.');
|
||||
const retainError=make('p');retainError.setAttribute('role','alert');retainError.hidden=true;
|
||||
const actions=make('div');actions.className='adaptive-actions';
|
||||
const state=make('p');state.className='adaptive-state';
|
||||
const status=make('p');status.setAttribute('role','status');
|
||||
const automaticFailure=make('p');automaticFailure.hidden=true;
|
||||
const advanced=make('details');make('summary','Advanced',advanced);
|
||||
const advancedFields=make('div',null,advanced);advancedFields.className='adaptive-fields';
|
||||
const name=input(advancedFields,'Dedicated receiver name');name.value=initial.targetName??'';name.placeholder='Adaptive Music '+(game.world?.title??'campaign');
|
||||
@@ -91,7 +105,7 @@ 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;
|
||||
let transportResults=[],busy=false,hadDeviceCredential=initial.deviceCredential;
|
||||
const run=async(action,label)=>{
|
||||
if(busy||!game.user.isGM)return;
|
||||
busy=true;retainError.hidden=true;render();
|
||||
@@ -118,7 +132,9 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
let maUrl;
|
||||
const useSaved=!address.value.trim()&&connection.draftFields?.savedConnection;
|
||||
if(!useSaved)try{maUrl=validatedAddress();}catch(error){throw {code:error.code,field:address};}
|
||||
if(!token.value.trim()&&(useSaved||!retainedToken()))throw {code:'token-required',field:token};
|
||||
const draft=connection.draftFields??{};
|
||||
const usingDevice=draft.deviceCredential&&draft.maUrl===maUrl;
|
||||
if(!token.value.trim()&&!usingDevice&&(useSaved||!retainedToken()))throw {code:'token-required',field:token};
|
||||
if(/[\r\n]/.test(token.value))throw {code:'token-invalid',field:token};
|
||||
const targetName=name.value.trim();
|
||||
if(targetName.length>120||/[\x00-\x1f\x7f]/.test(name.value)){advanced.open=true;throw {code:'receiver-name-invalid',field:name};}
|
||||
@@ -127,7 +143,7 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
catch{advanced.open=true;throw {code:'ice-config-invalid',field:iceURL};}
|
||||
status.textContent='Contacting Music Assistant…';
|
||||
let result;
|
||||
try{result=await connection.open({maUrl,token:token.value.trim(),...(targetName&&{targetName}),...(listenerNetwork&&{listenerNetwork})});}
|
||||
try{result=await connection.open({maUrl,token:token.value.trim(),remember:remember.checked,...(targetName&&{targetName}),...(listenerNetwork&&{listenerNetwork})});}
|
||||
finally{if(connection.status.hasPrivateDraft){token.value='';iceCredential.value='';}}
|
||||
address.value=connection.draftFields?.maUrl??address.value;
|
||||
await onCatalog();
|
||||
@@ -136,8 +152,11 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
connect.className='adaptive-primary';
|
||||
const nextButton=button(actions,'Choose scene music',()=>next?.());
|
||||
const disconnect=button(actions,'Disconnect',()=>run(async()=>{
|
||||
await connection.disconnect();token.value='';iceCredential.value='';status.textContent='Disconnected. The receiver is remembered for next time.';await onCatalog();
|
||||
await connection.disconnect();token.value='';iceCredential.value='';status.textContent='Disconnected. Automatic reconnection is paused until you connect again.';await onCatalog();
|
||||
},'Disconnect failed'));
|
||||
const forgetCredentials=button(actions,'Forget Credentials',()=>run(async()=>{
|
||||
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());
|
||||
for(const result of transportResults)make('p',`${result.path} — ${diagnosticMessage(result)}`,report);
|
||||
@@ -145,7 +164,7 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
},'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,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));
|
||||
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));
|
||||
status.textContent='Connection diagnostics copied.';
|
||||
},'Could not copy diagnostics'));
|
||||
const advancedActions=make('div',null,advanced);advancedActions.className='adaptive-actions';
|
||||
@@ -156,17 +175,25 @@ export function mountConnectionWizard({game,container,connection,onCatalog=()=>{
|
||||
if(advancedContent)advanced.append(advancedContent);
|
||||
function render(){
|
||||
const d=connection.status,connected=d.state==='connected';
|
||||
const label=connected?'Connected':busy?'Working':d.state==='connection-lost'?'Connection lost':'Disconnected';
|
||||
const connecting=busy||d.deviceReconnect;
|
||||
const label=connected?'Connected':connecting?'Working':d.state==='connection-lost'?'Connection lost':d.deviceError?'Automatic connection failed':'Disconnected';
|
||||
const summary=connected?`${label} · ${d.catalog??0} catalog choices`:
|
||||
busy&&d.stage&&d.stage!=='idle'?`${label} · ${d.stage}`:label;
|
||||
if(state.textContent!==summary)state.textContent=summary;
|
||||
state.dataset.connected=String(connected);
|
||||
connect.hidden=connected;connect.disabled=busy;connect.textContent=busy?'Connecting…':'Connect';
|
||||
automaticFailure.hidden=connected||connecting||!d.deviceError;
|
||||
if(!automaticFailure.hidden)automaticFailure.textContent=connectionMessage({code:d.deviceError});
|
||||
connect.hidden=connected;connect.disabled=connecting;connect.textContent=connecting?'Connecting…':'Connect';
|
||||
disconnect.hidden=!connected;disconnect.disabled=busy;
|
||||
nextButton.hidden=!connected||!next;nextButton.disabled=busy;refresh.hidden=!connected;
|
||||
forget.disabled=busy||(!d.hasPrivateDraft&&!connection.draftFields?.savedConnection);
|
||||
for(const field of [address,token,name,iceURL,iceUsername,iceCredential,iceExpiry])field.disabled=connected||busy;
|
||||
token.placeholder=retainedToken()?'Retained for this address':'Paste your access token';
|
||||
const draft=connection.draftFields;
|
||||
forgetCredentials.hidden=!draft?.deviceCredential&&d.deviceError!=='private-credential-corrupt';forgetCredentials.disabled=connecting;
|
||||
if(!address.value&&draft?.deviceCredential&&!hadDeviceCredential)address.value=draft.maUrl;
|
||||
if(draft?.deviceCredential&&!hadDeviceCredential)remember.checked=true;
|
||||
hadDeviceCredential=draft?.deviceCredential;
|
||||
for(const field of [address,token,name,iceURL,iceUsername,iceCredential,iceExpiry,remember])field.disabled=connected||connecting;
|
||||
token.placeholder=retainedToken()||connection.draftFields?.deviceCredential?'Retained for this address':'Paste your access token';
|
||||
}
|
||||
address.addEventListener('input',render);
|
||||
render();
|
||||
|
||||
Reference in new issue
Block a user