Add detached service windows and selectable terminal themes
Support standalone APRS, Monitor, Chat and Terminal views with courtesy screens, window focus and return controls, shared sessions and suspended embedded polling. Add five persistent phosphor palettes, remove Console terminal idle disconnections, and display decoded Mic-E movement and altitude with expandable original packets. Document the new behavior and add regression coverage. Validation: 182 tests passed; the known hanging PowerShell startup readiness test was excluded.
This commit is contained in:
1 parent
8ee4e9636a
commit
c98c67e18b
24 files changed
+415
-22
No files matched your search
+6
-6
@@ -4,10 +4,10 @@ import {StringDecoder} from 'node:string_decoder';
|
||||
import {TelnetText,TelnetLogin} from './telnet-login.mjs';
|
||||
export {TelnetText} from './telnet-login.mjs';
|
||||
export class Terminal {
|
||||
constructor(credentials,options={}){this.credentials=credentials;this.options=options;this.state='offline';this.events=[];this.seq=0;this.lastAccess=Date.now();this.lastInput=Date.now();this.timer=setInterval(()=>{if(this.socket&&!this.socket.destroyed&&(Date.now()-this.lastAccess>90000||Date.now()-this.lastInput>15*60000))this.disconnect('Sessione chiusa per inattività');},10000);this.timer.unref();}
|
||||
constructor(credentials,options={}){this.credentials=credentials;this.options=options;this.state='offline';this.events=[];this.seq=0;}
|
||||
event(text){if(!text)return;this.events.push({id:++this.seq,text});let size=this.events.reduce((n,e)=>n+e.text.length,0);while(this.events.length>500||size>200000)size-=this.events.shift().text.length;}
|
||||
snapshot(after=0){this.lastAccess=Date.now();return {state:this.state,events:this.events.filter(e=>e.id>after),latest:this.seq,port:this.options.port,error:this.error||null};}
|
||||
async connect(){if(this.state==='connecting'||this.socket&&!this.socket.destroyed)return this.snapshot();this.state='connecting';let credentials;try{credentials=await this.credentials();}catch{this.state='error';throw new Error('Credenziali Telnet BPQ non disponibili');}if(this.state!=='connecting')return this.snapshot();this.error=null;this.events=[];this.stage=0;this.escape='';this.pendingCR=false;this.decoder=new StringDecoder('utf8');this.lastAccess=this.lastInput=Date.now();const socket=net.createConnection({host:'127.0.0.1',port:this.options.port});this.socket=socket;const telnet=new TelnetText(b=>socket.write(b));socket.setTimeout(15000);
|
||||
snapshot(after=0){return {state:this.state,events:this.events.filter(e=>e.id>after),latest:this.seq,port:this.options.port,error:this.error||null};}
|
||||
async connect(){if(this.state==='connecting'||this.socket&&!this.socket.destroyed)return this.snapshot();this.state='connecting';let credentials;try{credentials=await this.credentials();}catch{this.state='error';throw new Error('Credenziali Telnet BPQ non disponibili');}if(this.state!=='connecting')return this.snapshot();this.error=null;this.events=[];this.stage=0;this.escape='';this.pendingCR=false;this.decoder=new StringDecoder('utf8');const socket=net.createConnection({host:'127.0.0.1',port:this.options.port});this.socket=socket;const telnet=new TelnetText(b=>socket.write(b));socket.setTimeout(15000);
|
||||
socket.on('timeout',()=>{if(this.state==='connecting')socket.destroy(new Error('Accesso Telnet non confermato'));});
|
||||
socket.on('error',e=>{if(this.socket!==socket)return;this.state='error';this.error=['Accesso rifiutato','Accesso Telnet non confermato'].includes(e.message)?e.message:'Connessione Telnet BPQ non disponibile';this.event('\n[Connessione Telnet non disponibile]\n');});
|
||||
socket.on('close',()=>{if(this.socket!==socket)return;this.login?.close();if(this.pendingCR){this.event('\n');this.pendingCR=false;}if(this.state!=='error')this.state='offline';this.event('\n[Sessione terminata]\n');});
|
||||
@@ -18,7 +18,7 @@ export class Terminal {
|
||||
if(this.escape){this.escape+=c;if(this.escape.length>128||/^\x1b\[[0-?]*[ -/]*[@-~]$/.test(this.escape)||this.escape.length===2&&c!=='[')this.escape='';continue;}
|
||||
if(c==='\x1b'){this.escape=c;continue;}if(c==='\r'){this.pendingCR=true;continue;}if(c==='\b'){out=out.slice(0,-1);continue;}if(c==='\n'||c==='\t'||c.charCodeAt(0)>=32)out+=c;
|
||||
}this.event(out);}
|
||||
send(text){if(this.state!=='online'||!this.socket||this.socket.destroyed)throw new Error('Collega prima il terminale');if(typeof text!=='string'||text.length>1000||/[\x00-\x1f\x7f]/.test(text))throw new Error('Invia un solo comando, massimo 1000 caratteri');this.lastInput=this.lastAccess=Date.now();this.event(text+'\n');this.socket.write(text+'\r');}
|
||||
disconnect(reason='Disconnessione richiesta'){this.login?.close();this.lastInput=Date.now();if(this.socket&&!this.socket.destroyed)this.socket.destroy();this.state='offline';this.event('\n['+reason+']\n');}
|
||||
close(){this.disconnect();clearInterval(this.timer);}
|
||||
send(text){if(this.state!=='online'||!this.socket||this.socket.destroyed)throw new Error('Collega prima il terminale');if(typeof text!=='string'||text.length>1000||/[\x00-\x1f\x7f]/.test(text))throw new Error('Invia un solo comando, massimo 1000 caratteri');this.event(text+'\n');this.socket.write(text+'\r');}
|
||||
disconnect(reason='Disconnessione richiesta'){this.login?.close();if(this.socket&&!this.socket.destroyed)this.socket.destroy();this.state='offline';this.event('\n['+reason+']\n');}
|
||||
close(){this.disconnect();}
|
||||
}
|
||||
Reference in new issue
Block a user