import { Config } from '../config' ; import { Keystore } from '../Keystore' ; import { Messenger , MessageEvent } from '../Messenger' ; import * as ui from '../ui/chat' ; import { stationToCallsignSSID , isBrokenPipeError } from '../utils' ; export async function main ( args , conf , ks ) { const messenger = new Messenger ( conf ) ; try { await messenger . openTNC ( ) ; } catch ( err ) { console . error ( `Error opening a connection to the KISS TNC that should be listening at ${ conf . kissPort }. Are you sure your TNC is running?` ) ; console . error ( `If you have Direwolf installed you can start it in another window with "direwolf -p -q d -t 0"` ) ; return 1 ; } messenger . on ( 'close' , ( ) => { console . error ( `The connection to KISS TNC at ${ conf . kissPort } is now closed. Exiting.` ) ; ui . exit ( 1 ) ; } ) ; messenger . on ( 'tnc-error' , ( err ) => { if ( isBrokenPipeError ( err ) ) return ; console . error ( `The connection to KISS TNC ${ conf . kissPort } experienced the following error:` ) ; console . error ( err ) ; } ) ; messenger . on ( 'message' , ( message ) => { if ( message . to . callsign === 'CQ' || ( message . to . callsign === conf . callsign && message . to . ssid === conf . ssid ) ) { ui . printReceivedMessage ( message , conf . callsign ) ; } } ) ; ui . enter ( ) ; const sign = typeof conf . signingKey === 'string' ; const callsignSSID = stationToCallsignSSID ( { callsign : conf . callsign , ssid : conf . ssid } ) ; await ui . inputLoop ( callsignSSID , messenger , sign ) ; return 0 ; }