Release v0.7.0 - Automatic pairing and validated MA audio playback
Validate and generate manual release / package (push) Waiting to run

This commit is contained in:
Jason committed 2026-12-04 08:58:47 -05:00
1 parent 83d168f5a1
commit 1ed30567fb
48 files changed
+2717 -742

No files matched your search

+53
View File
@@ -99,3 +99,56 @@ test('disconnect cancels pending GM startup before any authenticated receiver co
assert.throws(()=>gmAccessPolicy('http://localhost','https://foundry.example.test'),{code:'mixed-content'});
assert.throws(()=>gmAccessPolicy('https://ma.example.test','http://foundry.example.test'),{code:'insecure-context'});
});
test('automatic provisioning uses the bound API session, waits for queue registration and reconnects',async()=>{
const sockets=[],commands=[];let paired=false,softwareVolume,core,losses=0,lockHeld=false,queueReads=0;
const player={player_id:'campaign-receiver',name:'Campaign receiver',provider:'sendspin-fixture',enabled:true,available:true,volume_level:null,volume_muted:null,group_members:[],group_childs:[],static_group_members:[]};
const queue={queue_id:player.player_id,active:true,available:true,items:0,state:'idle',is_dynamic:false,autoplay_enabled:false,dont_stop_the_music_enabled:false,overlay_enabled:false,playback_speed:1};
const createSocket=url=>{
const socket={url,bound:false,authenticated:false,send(text){const msg=JSON.parse(text);commands.push(msg.command??msg.type);queueMicrotask(()=>{
if(url.endsWith('/sendspin')){for(const api of sockets.filter(s=>s.url.endsWith('/ws')&&s.authenticated))api.bound=true;socket.onmessage?.({data:JSON.stringify({type:'auth_ok'})});return;}
if(msg.command==='auth')socket.authenticated=true;
if(msg.command==='players/get')assert.equal(socket.bound,true,'new receiver access belongs to the preexisting API session');
if(msg.command==='sendspin/pair_web_player'){assert.equal(socket.bound,true);paired=true;}
let result=msg.command==='auth'?{authenticated:true}:msg.command==='providers'?[{instance_id:'music',available:true}]:msg.command==='players/get'?player:msg.command.includes('library_items')?[]:msg.command==='sendspin/pair_web_player'?null:queue;
if(msg.command==='player_queues/get'&&++queueReads===1)result=null;
socket.onmessage?.({data:JSON.stringify({message_id:msg.message_id,result})});
});},close(){socket.onclose?.();}};sockets.push(socket);queueMicrotask(()=>socket.onopen?.());return socket;
};
const sdk={loadSendspinClientIdentity(storage){if(!storage.getItem('sendspin-identity-sk'))storage.setItem('sendspin-identity-sk','A'.repeat(43));return {clientId:player.player_id};},SendspinCore:class{
timeSyncInfo={synced:true};pairingToken='private-pairing-fixture';constructor(config){core=this;this.config=config;softwareVolume=config.useHardwareVolume===false;}async connect(){this.config.storage.setItem('pairing-fixture','retained');}disconnect(){}
}};
const context={state:'running',destination:{},resume:async()=>{},createMediaStreamDestination:()=>({stream:{getTracks:()=>[]}}),createGain:()=>({connect(){}}),close:async()=>{}};
const locks={async request(_name,_options,callback){
if(lockHeld)return callback(null);
lockHeld=true;
try{await callback({});}finally{lockHeld=false;}
}};
const oldNavigator=globalThis.navigator;Object.defineProperty(globalThis,'navigator',{configurable:true,value:{locks}});
const host=new GMAudioHost({authority:()=>true,pageUrl:'https://foundry.example.test',createSocket,createContext:()=>context,loadSDK:async()=>sdk,onDisconnect:()=>{losses++;}});
try{
const profile=await host.prepare({maUrl:'https://ma.example.test',token:'private-fixture',campaign:'campaign',targetName:player.name});
assert.equal(profile.identityStorage['sendspin-identity-sk'],'A'.repeat(43));await host.start(profile);
assert.equal(paired,true);assert.equal(softwareVolume,true);assert.equal(profile.identityStorage['pairing-fixture'],'retained');assert.equal(host.connected,true);
assert.equal(queueReads,3);
assert.equal(queueReads,3);
assert.ok(commands.every(command=>!/^player_queues\/(play_media|play_index|stop|clear|repeat)$/.test(command)));
const firstSession=host.session;
const firstCore=core;
firstCore.onConnectionClose();
assert.equal(host.status.state,'connection-lost');
await host.start(profile);
assert.notEqual(host.session,firstSession);
firstCore.onConnectionClose();
assert.equal(host.connected,true);
assert.equal(losses,1);
assert.ok(!commands.includes('players/all'));
}finally{await host.close();Object.defineProperty(globalThis,'navigator',{configurable:true,value:oldNavigator});}
});
test('Firefox session sendrecv default is overridden by recvonly audio without permitting sender or extra media',async()=>{
const {validateAudioSDP}=await import('../../src/audio/peer-audio.mjs');
const firefox='v=0\r\na=sendrecv\r\nm=audio 9 UDP/TLS/RTP/SAVPF 109\r\na=recvonly\r\n';
assert.doesNotThrow(()=>validateAudioSDP(firefox,'offer'));
assert.doesNotThrow(()=>validateAudioSDP(firefox.replace('a=recvonly','a=sendonly'),'answer'));
for(const bad of [firefox.replace('a=recvonly','a=sendonly'),firefox.replace('a=recvonly','a=sendrecv'),firefox+'m=video 9 UDP/TLS/RTP/SAVPF 96\r\na=recvonly\r\n',firefox+'m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n',firefox+'a=sendonly\r\n',firefox.replace('a=recvonly\r\n','')])assert.throws(()=>validateAudioSDP(bad,'offer'),{code:'denied'});
});