forked from coolaj86/telebit.js
		
	WIP refactor TelebitRemote with EventEmitters and Duplexes
This commit is contained in:
		
							parent
							
								
									d39ebf88a2
								
							
						
					
					
						commit
						d8aedb39c2
					
				| @ -835,6 +835,24 @@ function startTelebitRemote(rawCb) { | ||||
|     state.insecure = state.config.relay_ignore_invalid_certificates; | ||||
|     // { relay, config, servernames, ports, sortingHat, net, insecure, token, handlers, greenlockConfig }
 | ||||
| 
 | ||||
|     function onError(err) { | ||||
|       // Likely causes:
 | ||||
|       //   * DNS lookup failed (no Internet)
 | ||||
|       //   * Rejected (bad authn)
 | ||||
|       if ('ENOTFOUND' === err.code) { | ||||
|         // DNS issue, probably network is disconnected
 | ||||
|         setTimeout(function () { | ||||
|           startTelebitRemote(rawCb); | ||||
|         }, 90 * 1000); | ||||
|         return; | ||||
|       } | ||||
|       if ('function' === typeof rawCb) { | ||||
|         rawCb(err); | ||||
|       } else { | ||||
|         console.error('Unhandled TelebitRemote Error:'); | ||||
|         console.error(err); | ||||
|       } | ||||
|     } | ||||
|     console.log("[DEBUG] token", typeof token, token); | ||||
|     myRemote = TelebitRemote.createConnection({ | ||||
|       relay: state.relay | ||||
| @ -850,19 +868,10 @@ function startTelebitRemote(rawCb) { | ||||
|     , handlers: state.handlers | ||||
|     , greenlockConfig: state.greenlockConfig | ||||
|     }, function () { | ||||
|       myRemote.removeListener('error', onError); | ||||
|       rawCb(null, myRemote); | ||||
|     }); | ||||
|     myRemote.once('error', function (err) { | ||||
|       // Likely causes:
 | ||||
|       //   * DNS lookup failed (no Internet)
 | ||||
|       //   * Rejected (bad authn)
 | ||||
|       if ('function' === typeof rawCb) { | ||||
|         rawCb(err); | ||||
|       } else { | ||||
|         console.error('Unhandled TelebitRemote Error:'); | ||||
|         console.error(err); | ||||
|       } | ||||
|     }); | ||||
|     myRemote.once('error', onError); | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -477,12 +477,14 @@ function TelebitRemote(state) { | ||||
|         pausedClients.length = 0; | ||||
|       }); | ||||
| 
 | ||||
|     /* | ||||
|       //Call either Open or Reconnect handlers.
 | ||||
|       if(state.handlers.onOpen && initialConnect) { | ||||
|         state.handlers.onOpen(); | ||||
|       } else if (state.handlers.onReconnect && !initialConnect) { | ||||
|         state.handlers.onReconnect(); | ||||
|       } | ||||
|     */ | ||||
|       initialConnect = false; | ||||
|     } | ||||
| 
 | ||||
| @ -500,6 +502,9 @@ function TelebitRemote(state) { | ||||
|         connCallback(error); | ||||
|       } | ||||
| 
 | ||||
|       me.emit('close'); | ||||
|     /* | ||||
|       return; | ||||
|       if (!authenticated) { | ||||
|         if(state.handlers.onError) { | ||||
|           var err = new Error('Failed to connect on first attempt... check authentication'); | ||||
| @ -522,9 +527,13 @@ function TelebitRemote(state) { | ||||
|           state.handlers.onClose(); | ||||
|         } | ||||
|       } | ||||
|       */ | ||||
|     } | ||||
| 
 | ||||
|   , onError: function (err) { | ||||
|       me.emit('error', err); | ||||
|     /* | ||||
|       return; | ||||
|       if ('ENOTFOUND' === err.code) { | ||||
|         // DNS issue, probably network is disconnected
 | ||||
|         timeoutId = setTimeout(connect, 90 * 1000); | ||||
| @ -535,6 +544,7 @@ function TelebitRemote(state) { | ||||
|       if (connCallback) { | ||||
|         connCallback(err); | ||||
|       } | ||||
|     */ | ||||
|     } | ||||
| 
 | ||||
|   , sendMessage: function (msg) { | ||||
|  | ||||
| @ -68,7 +68,7 @@ | ||||
|     "serve-tpl-attachment": "^1.0.4", | ||||
|     "sni": "^1.0.0", | ||||
|     "socket-pair": "^1.0.3", | ||||
|     "ws": "^2.3.1" | ||||
|     "ws": "^6.0.0" | ||||
|   }, | ||||
|   "trulyOptionalDependencies": { | ||||
|     "bluebird": "^3.5.1" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user