@@ -26,13 +26,15 @@ var LOGS_BUFFER = {};
26
26
/**
27
27
* Instanciate a new axon connection
28
28
*/
29
- function setupConnection ( host ) {
29
+ function setupConnection ( host , port ) {
30
30
var that = this ;
31
31
32
- this . _setup = function ( host ) {
33
- console . log ( '[PUSH] Connecting %s:%s' , host , cst . REMOTE_PORT_TCP ) ;
32
+ this . _setup = function ( host , port ) {
33
+ console . log ( '[PUSH] Connecting %s:%s' , host , port || cst . REMOTE_PORT_TCP ) ;
34
34
35
35
var client = this . client = axon . socket ( 'pub' ) ;
36
+ if ( port ) port = parseInt ( port )
37
+ if ( port === 41624 ) port = 80
36
38
37
39
this . host = host ;
38
40
@@ -51,8 +53,7 @@ function setupConnection(host) {
51
53
client . on ( 'reconnect attempt' , function ( e ) {
52
54
console . log ( '[PUSH] Reconnecting' ) ;
53
55
} ) ;
54
-
55
- client . connect ( cst . REMOTE_PORT_TCP , host ) ;
56
+ client . connect ( port || cst . REMOTE_PORT_TCP , host ) ;
56
57
} ;
57
58
58
59
this . destroy = function ( ) {
@@ -65,7 +66,7 @@ function setupConnection(host) {
65
66
this . _setup ( this . host ) ;
66
67
} ;
67
68
68
- this . _setup ( host ) ;
69
+ this . _setup ( host , port ) ;
69
70
70
71
return this ;
71
72
} ;
@@ -75,18 +76,16 @@ var PushInteractor = module.exports = {
75
76
* Connect to target host or reconnect if null is passed
76
77
* the host param must be formated like (http://HOST:PORT)
77
78
*/
78
- connectRemote : function ( hostname ) {
79
- if ( hostname )
80
- hostname = Url . parse ( hostname ) . hostname ;
81
- else if ( this . socket && this . socket . host )
82
- hostname = this . socket . host ;
83
- else
84
- return console . error ( 'NO HOST DEFINED' ) ;
85
-
86
- if ( this . socket )
87
- this . socket . destroy ( ) ;
88
-
89
- this . socket = setupConnection ( hostname ) ;
79
+ connectRemote : function ( hostname , port ) {
80
+ if ( this . socket ) this . socket . destroy ( )
81
+ if ( hostname ) {
82
+ var parsed = Url . parse ( hostname )
83
+ this . socket = setupConnection ( parsed . hostname , port || parsed . port )
84
+ } else if ( this . socket && this . socket . host ) {
85
+ this . socket = setupConnection ( this . socket . host )
86
+ } else {
87
+ return console . error ( 'NO HOST DEFINED' )
88
+ }
90
89
} ,
91
90
/**
92
91
* Start the PushInteractor Singleton
@@ -105,14 +104,15 @@ var PushInteractor = module.exports = {
105
104
this . send_buffer = [ ] ;
106
105
this . _reconnect_counter = 0 ;
107
106
107
+ this . port = null
108
108
if ( process . env . PM2_DEBUG )
109
- cst . REMOTE_PORT_TCP = 3900 ;
109
+ this . port = 3900 ;
110
110
if ( process . env . NODE_ENV == 'local_test' )
111
- cst . REMOTE_PORT_TCP = 8080 ;
111
+ this . port = 8080 ;
112
112
113
113
this . resetPacket ( ) ;
114
114
115
- this . connectRemote ( p . url ) ;
115
+ this . connectRemote ( p . url , this . port ) ;
116
116
117
117
this . ipm2 . on ( 'ready' , function ( ) {
118
118
console . log ( '[PUSH] PM2 interface ready, listening to PM2' ) ;
0 commit comments