diff --git a/README.md b/README.md index 34b9391..d57713e 100644 --- a/README.md +++ b/README.md @@ -197,3 +197,5 @@ Third-party PDF.js, font and CMap licences are retained under `public/vendor/pdf Packet controller integrations must acknowledge a reserved slot with `pttReady: true`, after checking that their BPQ PTT backend responds. A modem TCP connection alone is insufficient. The slot status must also contain the matching request ID, frequency, VHF phase and a fresh timestamp. Manual alternate routes share the partner queue; their native HF row is reserved during use and is not counted as a second active session. The local packet controller can use `packet-preparation.mjs` to prioritize an idle manual Packet request by advancing BPQ's native scan toward its configured packet entry. This retains the native modem interlock (for example VARA V0/LISTEN OFF), rather than directly retuning from an HF receive slot. Do not advance while attached, connecting, transmitting, or paused. Forwarding and Winlink share the same slot handshake; its measured `preparationMs` is saved with the reservation. A single radio still requires exclusive access to the selected frequency. + +Manual forwarding and Winlink sync buttons open a live progress dialog (preparation, calling, message exchange, restoration and outcome). Minimize keeps the session running. Interrupt cancels pending packet preparation or disconnects only the matching native BBS partner, then restores the temporary radio profile. Progress jobs are kept by the Console process; restarting the Console clears their visual history. Mail column headings share the same scroll area as their rows. diff --git a/forwarding.mjs b/forwarding.mjs index 8541b4f..198176e 100644 --- a/forwarding.mjs +++ b/forwarding.mjs @@ -51,13 +51,13 @@ export class Forwarding{ } this.cached={profiles:out,updatedAt:new Date().toISOString(),scheduleTimezone:profiles.some(p=>p.timesLocal)?'Locale server BPQ':'UTC',radio:this.radio(),errors};this.cachedAt=Date.now();return this.cached; });} - start(peer){return this.exclusive(async()=>{ - if(this.lockedPeers.has(peer))throw new Error(this.lockedPeers.get(peer)); + start(peer,{signal}={}){return this.exclusive(async()=>{ + signal?.throwIfAborted();if(this.lockedPeers.has(peer))throw new Error(this.lockedPeers.get(peer)); const p=(await this.profiles()).find(p=>p.call===peer);if(!p?.configured)throw new Error('Profilo di forwarding non configurato'); if(Date.now()-(this.requested.get(peer)||0)<30000)throw new Error('Sincronizzazione già richiesta: attendi 30 secondi'); const last=forwardingHistory(await this.logs().catch(()=>''),peer)[0];if(last&&!last.endedAt&&['calling','connected'].includes(last.status))throw new Error('Forwarding già in corso per questo partner'); const radio=this.radio();if(p.transport==='Radio'&&radio?.txSuspended)throw Error('Trasmissioni radio sospese dalla console');if(p.transport==='Radio'&&(radio?.active||radio?.connecting))throw new Error('Modem occupato da una connessione: riprova al termine'); - const key=await this.context();await this.bpq('/Mail/FwdDetails?'+key,{method:'POST',body:peer});await this.bpq('/Mail/FWDSave?'+key,{method:'POST',body:'StartForward'}); + const key=await this.context();await this.bpq('/Mail/FwdDetails?'+key,{method:'POST',body:peer});signal?.throwIfAborted();await this.bpq('/Mail/FWDSave?'+key,{method:'POST',body:'StartForward'}); this.requested.set(peer,Date.now());this.cached=null;return {ok:true,peer,requestedAt:new Date().toISOString()}; });} } diff --git a/manual-forwarding.mjs b/manual-forwarding.mjs index 26df378..2126102 100644 --- a/manual-forwarding.mjs +++ b/manual-forwarding.mjs @@ -15,11 +15,11 @@ export class ManualForwarding extends WinlinkRadio{ snapshot(){const state=super.snapshot();if(state?.error)state.error=state.error.replaceAll('profilo RMS','profilo del partner');return state;} async restore(){const state=await super.restore();await this.release();return state;} profiles(native){return this.routes.flatMap(route=>{const p=native.find(p=>p.call===route.peer);if(!p)return [];const j=this.job?.channel?.id===route.id?this.job:null;const history=j?p.history.filter(s=>Date.parse(s.startedAt)>=Date.parse(j.startedAt)-1500&&(!j.endedAt||Date.parse(s.startedAt)<=Date.parse(j.endedAt))):[];return [{...p,call:route.id,label:route.label,peer:route.peer,manualOnly:true,enabled:false,interval:0,immediate:false,reverseInterval:0,times:[],configured:true,port:route.port,driver:this.config.ports.find(p=>p.id===route.port)?.driver||'',transport:'Radio',frequency:[String(route.frequencyMHz),route.mode],script:safeScript(route.script),history,last:history[0]||null,active:Boolean(j?.restoring),preparing:j?.state==='preparing',requestedAt:j?.startedAt||null,nextEstimated:null}];});} - async prepare(route){await reservePacketSlot(this,route.controller,route.frequencyMHz,route.port);} + async prepare(route,signal){await reservePacketSlot(this,route.controller,route.frequencyMHz,route.port,{signal});} async release(){await releasePacketSlot(this);} displayProfiles(native){const j=this.job;const base=native.map(p=>{if(!j||j.peer!==p.call)return p;const history=p.history.filter(s=>!(Date.parse(s.startedAt)>=Date.parse(j.startedAt)-1500&&(!j.endedAt||Date.parse(s.startedAt)<=Date.parse(j.endedAt))));const original=parseForwarding('BBSForwarding : { '+p.call+' : { '+Object.entries(j.original||{}).map(([k,v])=>k+' = "'+String(v).replaceAll('"','')+'";').join(' ')+' } }',this.config.ports)[0];return {...p,...(j.restoring?original:{}),history,last:history[0]||null,active:j.restoring?false:p.active,reservedBy:j.restoring?j.channel.id:null};});return [...base,...this.profiles(native)];} - async startRoute(id){await this.init;return this.fwd.exclusive(async()=>{ - const route=this.routes.find(r=>r.id===id);if(!route)throw Error('Percorso manuale non configurato'); + async startRoute(id,{signal}={}){await this.init;return this.fwd.exclusive(async()=>{ + signal?.throwIfAborted();const route=this.routes.find(r=>r.id===id);if(!route)throw Error('Percorso manuale non configurato'); if(this.job?.restoring||this.fwd.lockedPeers.has(route.peer))throw Error('Un inoltro per questo partner è già in corso'); if(!(await this.fwd.profiles()).some(p=>p.call===route.peer&&p.configured))throw Error('Partner BBS non configurato'); const radio=this.fwd.radio();if(!radio?.available||radio.active||radio.connecting||Date.now()-radio.at>20000)throw Error('Radio non disponibile o impegnata'); @@ -29,12 +29,12 @@ export class ManualForwarding extends WinlinkRadio{ const disabled={...original,Enabled:'0',FWDNewImmediately:'0'}; this.job={peer:route.peer,channel:{id:route.id,call:route.connectCall,dialHz:Math.round(route.frequencyMHz*1e6),mode:route.mode},original,temporary:disabled,startedAt:new Date().toISOString(),state:'preparing',restoring:true}; this.busy=true;this.fwd.lockedPeers.set(route.peer,'Inoltro manuale in preparazione o in corso'); - try{await this.persist();await this.saveNative(disabled);await this.prepare(route); + try{await this.persist();await this.saveNative(disabled);await this.prepare(route,signal);signal?.throwIfAborted(); if(activeMailStreams(await this.fwd.bpq('/Mail/Status')).length)throw Error('Una sessione BBS è iniziata: riprova al termine'); this.job.temporary={...disabled,ConnectScript:route.script};this.job.startedAt=new Date().toISOString();await this.persist();await this.saveNative(this.job.temporary); - const key=await this.fwd.context();await this.fwd.bpq('/Mail/FwdDetails?'+key,{method:'POST',body:route.peer});await this.fwd.bpq('/Mail/FWDSave?'+key,{method:'POST',body:'StartForward'}); + const key=await this.fwd.context();await this.fwd.bpq('/Mail/FwdDetails?'+key,{method:'POST',body:route.peer});signal?.throwIfAborted();await this.fwd.bpq('/Mail/FWDSave?'+key,{method:'POST',body:'StartForward'}); this.job.state='requested';this.fwd.requested.set(route.peer,Date.now());await this.persist();return {ok:true,peer:route.peer,route:id,requestedAt:this.job.startedAt}; - }catch(error){this.job.state='failed';this.job.error=error.message;if(!activeMailStreams(await this.fwd.bpq('/Mail/Status')).length){await this.saveNative(original);this.job.restoring=false;this.job.endedAt=new Date().toISOString();this.fwd.lockedPeers.delete(route.peer);await this.release();}await this.persist();throw error;} + }catch(error){this.job.state=signal?.aborted?'cancelled':'failed';this.job.error=signal?.aborted?null:error.message;if(!activeMailStreams(await this.fwd.bpq('/Mail/Status')).length){await this.saveNative(original);this.job.restoring=false;this.job.endedAt=new Date().toISOString();this.fwd.lockedPeers.delete(route.peer);await this.release();}await this.persist();throw error;} finally{this.busy=false;} });} async tick(){await super.tick();if(this.job&&!this.job.restoring)await this.release();} diff --git a/public/forwarding.js b/public/forwarding.js index 49bc1b2..8902499 100644 --- a/public/forwarding.js +++ b/public/forwarding.js @@ -23,7 +23,7 @@ async function load(){if(!csrf||!station.features.bbs||loading)return;loading=tr $('#forward-refresh').onclick=load; $('#forward-restore').onclick=async()=>{try{await api('/forwarding/manual/restore',{method:'POST',body:'{}'});toast('Percorso originale ripristinato');await load();}catch(e){toast(e.message);}}; panel.addEventListener('keydown',e=>{if(e.target.matches('[data-forward-row]')&&['Enter',' '].includes(e.key)){e.preventDefault();e.target.click();}}); -panel.addEventListener('click',async e=>{const b=e.target.closest('[data-forward-start]');if(!b){const row=e.target.closest('[data-forward-row]');if(row){expanded=expanded===row.dataset.forwardRow?null:row.dataset.forwardRow;render();}return;}if(b.disabled)return;const peer=b.dataset.forwardStart;b.disabled=true;b.textContent='Richiesta…';try{await api('/forwarding/'+encodeURIComponent(peer)+'/sync',{method:'POST',body:'{}'});pending.set(peer,Date.now());toast('Sincronizzazione con '+peer+' richiesta a BPQ');await load();}catch(err){toast(err.message);const feedback=[...panel.querySelectorAll('[data-feedback]')].find(n=>n.dataset.feedback===peer);if(feedback)feedback.textContent=err.message;b.disabled=false;b.textContent='↻ Sincronizza ora';}}); +panel.addEventListener('click',async e=>{const b=e.target.closest('[data-forward-start]');if(!b){const row=e.target.closest('[data-forward-row]');if(row){expanded=expanded===row.dataset.forwardRow?null:row.dataset.forwardRow;render();}return;}if(b.disabled)return;const peer=b.dataset.forwardStart;b.disabled=true;b.textContent='Richiesta…';try{await window.bpqSync.start({kind:'forwarding',peer});pending.set(peer,Date.now());await load();}catch(err){toast(err.message);const feedback=[...panel.querySelectorAll('[data-feedback]')].find(n=>n.dataset.feedback===peer);if(feedback)feedback.textContent=err.message;b.disabled=false;b.textContent='↻ Sincronizza ora';}}); document.addEventListener('station-ready',()=>{data=null;pending.clear();expanded=null;nav.hidden=!station.features.bbs;if(page==='forwarding'){if(station.features.bbs)load();else navigate('home');}}); document.addEventListener('DOMContentLoaded',()=>{if(location.hash==='#forwarding')navigate('forwarding');}); setInterval(()=>{if(csrf&&!document.hidden&&page==='forwarding')load();},6000); diff --git a/public/index.html b/public/index.html index 6116e06..f4d29b8 100644 --- a/public/index.html +++ b/public/index.html @@ -1,5 +1,5 @@ -BPQ Console +BPQ Console

BPQ Console

La tua stazione, in un unico pannello.

BPQ Console

Benvenuto in stazione.

Accedi con l’utente e la password Telnet del tuo BPQ.

Created by IU2EUG · PC e rete locale