@@ -622,14 +622,6 @@ class localServer {
622622 return CallBack ( false ) ;
623623 } ) ;
624624 }
625- findPort ( port , CallBack ) {
626- return this . findPort ( port , good => {
627- if ( ! good ) {
628- return findPort ( ++ port , CallBack ) ;
629- }
630- return CallBack ( null , port ) ;
631- } ) ;
632- }
633625 // After password
634626 listenAfterPassword ( socket ) {
635627 socket . on ( 'startCheckImap' , ( id , imapData , CallBack ) => {
@@ -683,16 +675,15 @@ class localServer {
683675 // Have gateway connect!
684676 this . saveConfig ( ) ;
685677 if ( res . Args [ 1 ] ) {
686- const uu = res . Args [ 1 ] ;
687678 if ( ! this . proxyServer || ! this . connectCommand ) {
688- uu [ 0 ] . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
689- return this . findPort ( 3000 , ( err , _port ) => {
690- uu [ 0 ] . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
691- this . localProxyPort = uu [ 0 ] . localServerPort = _port ;
692- return this . makeOpnConnect ( uu ) ;
679+ const arg = this . connectCommand = res . Args [ 1 ] ;
680+ arg . forEach ( n => {
681+ n . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
682+ n . localServerPort = this . localProxyPort || 3000 ;
693683 } ) ;
684+ this . makeOpnConnect ( arg ) ;
694685 }
695- return socket . emit ( 'QTGateGatewayConnectRequest' , this . connectCommand ) ;
686+ return socket . emit ( 'QTGateGatewayConnectRequest' , - 1 , res . Args [ 1 ] ) ;
696687 }
697688 this . regionV1 = res . Args [ 2 ] ;
698689 } ) ;
@@ -915,14 +906,14 @@ class localServer {
915906 return saveLog ( `request error` ) ;
916907 }
917908 if ( res . error < 0 ) {
918- const arg = res . Args ;
909+ const arg = this . connectCommand = res . Args ;
919910 arg . forEach ( n => {
920911 n . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
921- n . localServerPort = this . localProxyPort ;
912+ n . localServerPort = n . localServerPort || this . localProxyPort || 3001 ;
922913 } ) ;
923914 this . makeOpnConnect ( arg ) ;
924915 }
925- CallBack ( res ) ;
916+ CallBack ( res . error , res . Args ) ;
926917 saveLog ( `res.error [${ res . error } ]` ) ;
927918 } ) ;
928919 } ;
@@ -945,6 +936,7 @@ class localServer {
945936 this . socketServer . emit ( 'qtGateConnect' , this . qtGateConnectEmitData ) ;
946937 }
947938 makeOpnConnect ( arg ) {
939+ saveLog ( `makeOpnConnect arg = ${ JSON . stringify ( arg ) } ` ) ;
948940 this . connectCommand = arg ;
949941 const runCom = arg [ 0 ] . connectType === 1 ? '@Opn' : 'iOpn' ;
950942 return this . proxyServer = new RendererProcess ( runCom , arg , DEBUG , ( ) => {
@@ -1151,7 +1143,7 @@ class localServer {
11511143 callBack ( true , this . imapDataPool ) ;
11521144 this . listenAfterPassword ( socket ) ;
11531145 if ( this . connectCommand && this . httpServer ) {
1154- return socket . emit ( 'QTGateGatewayConnectRequest' , this . connectCommand ) ;
1146+ return socket . emit ( 'QTGateGatewayConnectRequest' , - 1 , this . connectCommand ) ;
11551147 }
11561148 // imapDataPool have QTGateImap doing emitQTGateToClient
11571149 if ( this . imapDataPool . length > 0 && findQTGateImap ( this . imapDataPool ) > - 1 )
@@ -1414,7 +1406,7 @@ class localServer {
14141406 const transporter = Nodemailer . createTransport ( option ) ;
14151407 const mailOptions = {
14161408 from : imapData . email ,
1417- to : 'QTGate @QTGate.com' ,
1409+ to : 'QTGateTest @QTGate.com' ,
14181410 subject : 'QTGateTest' ,
14191411 attachments : [ {
14201412 content : text
@@ -1761,9 +1753,9 @@ class ImapConnect extends Imap.imapPeer {
17611753 }
17621754 if ( ! this . localServer . proxyServer || ! this . localServer . connectCommand ) {
17631755 saveLog ( `got Command from server "changeDocker" localServer.proxyServer or localServer.connectCommand is null!!` ) ;
1764- container [ 0 ] . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
1765- return this . localServer . findPort ( this . localServer . localProxyPort , ( err , port ) => {
1756+ return findPort ( this . localServer . localProxyPort , ( err , port ) => {
17661757 container [ 0 ] . localServerPort = this . localServer . localProxyPort = port ;
1758+ container [ 0 ] . localServerIp = exports . getLocalInterface ( ) [ 0 ] ;
17671759 return this . localServer . makeOpnConnect ( container ) ;
17681760 } ) ;
17691761 }
0 commit comments