File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,12 @@ function Channel(apiToken) {
84
84
} ) ;
85
85
}
86
86
87
+ if ( data . switch_to_channel && data . switch_to_channel . toString ( ) . match ( / ^ \d + $ / ) ) {
88
+ process . env . PIPEDRIVE_CHANNEL_HOST = 'channel' + data . switch_to_channel + '.pipedrive.com' ;
89
+ self . restartClient ( ) ;
90
+ return ;
91
+ }
92
+
87
93
if ( data . rabbitStateChange === 'open' ) {
88
94
if ( handlers [ 'connect' ] ) {
89
95
_ . each ( handlers [ 'connect' ] , function ( handler ) {
@@ -96,7 +102,7 @@ function Channel(apiToken) {
96
102
client . onclose = function ( e ) {
97
103
if ( ! clientClosed ) {
98
104
// not closed by user - we have some connection error.
99
- self . restartClient ( ) ;
105
+ self . startClient ( ) ;
100
106
return ;
101
107
}
102
108
@@ -111,13 +117,11 @@ function Channel(apiToken) {
111
117
112
118
this . restartClient = function ( ) {
113
119
client . onopen = null ;
114
- client . onclose = null ;
115
120
client . onmessage = null ;
116
- client = null ;
117
-
118
121
clientStarted = false ;
122
+ clientClosed = false ;
119
123
120
- setTimeout ( self . startClient , ( 1 + Math . random ( ) * 4 ) * 1000 ) ;
124
+ client . close ( ) ;
121
125
} ;
122
126
123
127
this . on = function ( method , handler ) {
@@ -145,6 +149,6 @@ function Channel(apiToken) {
145
149
if ( client && client . close ) {
146
150
client . close ( ) ;
147
151
}
148
- }
152
+ } ;
149
153
150
154
}
You can’t perform that action at this time.
0 commit comments