@@ -21,6 +21,7 @@ module.exports = class DXCluster extends events.EventEmitter {
2121 awaiting_login : false ,
2222 awaiting_password : false ,
2323 }
24+ this . customCommand = null
2425 this . regex = {
2526 deline : / ^ ( D X d e ) + ( [ A - Z 0 - 9 / \- # ] { 3 , } ) : ? * ( \d * .\d { 1 , 2 } ) * ( [ A - Z 0 - 9 / \- # ] { 3 , } ) + ( .* \S ) ? + ( \d { 4 } ) { 1 } Z * ( \w { 2 } \d { 2 } ) ? / g,
2627 callsign : / ( ( ( \d | [ A - Z ] ) + \/ ) { 0 , 2 } ( ( \d | [ A - Z ] ) { 3 , } ) ( \/ ( \d | [ A - Z ] ) + ) ? ( \/ ( \d | [ A - Z ] ) + ) ? ) { 1 , 1 } / g,
@@ -40,6 +41,9 @@ module.exports = class DXCluster extends events.EventEmitter {
4041 return ;
4142 }
4243
44+ // Store custom command from connection options
45+ this . customCommand = opts . customCommand || null
46+
4347 this . host = opts . host || '127.0.0.1'
4448 this . port = opts . port || 23
4549
@@ -94,21 +98,29 @@ module.exports = class DXCluster extends events.EventEmitter {
9498 } )
9599
96100 this . socket . on ( 'data' , ( data ) => {
101+ const dataStr = data . toString ( 'utf8' )
102+
97103 if ( this . status . awaiting_login ) {
98- if ( data . toString ( 'utf8' ) . indexOf ( loginPrompt ) != - 1 ) {
104+ if ( dataStr . indexOf ( loginPrompt ) != - 1 ) {
99105 if ( this . write ( call ) ) {
100106 this . status . awaiting_login = false
107+ // Execute custom command after login if no password required
108+ if ( ! opts . password ) {
109+ this . _executeCustomCommand ( )
110+ }
101111 }
102112 }
103113 }
104114 if ( this . status . awaiting_password ) {
105- if ( data . toString ( 'utf8' ) . indexOf ( passPrompt ) != - 1 ) {
115+ if ( dataStr . indexOf ( passPrompt ) != - 1 ) {
106116 if ( this . write ( opts . password ) ) {
107117 this . status . awaiting_password = false
118+ // Execute custom command after password if configured
119+ this . _executeCustomCommand ( )
108120 }
109121 }
110122 }
111- this . _parseDX ( data . toString ( 'utf8' ) )
123+ this . _parseDX ( dataStr )
112124 } )
113125
114126 this . socket . on ( 'close' , ( err ) => {
@@ -146,6 +158,17 @@ module.exports = class DXCluster extends events.EventEmitter {
146158 return this . socket . write ( str + this . ct )
147159 }
148160
161+ /**
162+ * Execute custom command after authentication is complete
163+ * @private
164+ */
165+ _executeCustomCommand ( ) {
166+ if ( this . customCommand ) {
167+ this . write ( this . customCommand )
168+ this . emit ( 'custom_command_sent' , this . customCommand )
169+ }
170+ }
171+
149172 /**
150173 * Internal method to cleanup all resources and prevent memory leaks
151174 * Called during connection failures, timeouts, and shutdown
0 commit comments