Compare commits
No commits in common. "74f9062a8987b4a2e7088411115d7aa5decd9b1f" and "cfba20707779f09c1926216f8a35fcffb297b4c1" have entirely different histories.
74f9062a89
...
cfba207077
|
|
@ -8,11 +8,7 @@ const router = Hype.router()
|
||||||
// individual events so apps can react to specific lifecycle changes.
|
// individual events so apps can react to specific lifecycle changes.
|
||||||
router.sse('/stream', (send) => {
|
router.sse('/stream', (send) => {
|
||||||
const unsub = onEvent(event => send(event))
|
const unsub = onEvent(event => send(event))
|
||||||
const heartbeat = setInterval(() => send('', 'ping'), 60_000)
|
return unsub
|
||||||
return () => {
|
|
||||||
clearInterval(heartbeat)
|
|
||||||
unsub()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
|
||||||
|
|
@ -146,19 +146,18 @@ export function renameTunnelConfig(oldName: string, newName: string) {
|
||||||
saveConfig(config)
|
saveConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelReconnect(appName: string, resetAttempts = true) {
|
function cancelReconnect(appName: string) {
|
||||||
const timer = _reconnectTimers.get(appName)
|
const timer = _reconnectTimers.get(appName)
|
||||||
if (timer) {
|
if (timer) {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
_reconnectTimers.delete(appName)
|
_reconnectTimers.delete(appName)
|
||||||
}
|
}
|
||||||
if (resetAttempts) _reconnectAttempts.delete(appName)
|
_reconnectAttempts.delete(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
function openTunnel(appName: string, port: number, subdomain?: string, isReconnect = false) {
|
function openTunnel(appName: string, port: number, subdomain?: string) {
|
||||||
// Cancel any pending reconnect timer to prevent duplicate loops
|
// Cancel any pending reconnect timer to prevent duplicate loops
|
||||||
// but preserve attempts counter during reconnection so backoff works
|
cancelReconnect(appName)
|
||||||
cancelReconnect(appName, !isReconnect)
|
|
||||||
|
|
||||||
// Close existing tunnel if any
|
// Close existing tunnel if any
|
||||||
const existing = _tunnels.get(appName)
|
const existing = _tunnels.get(appName)
|
||||||
|
|
@ -233,7 +232,7 @@ function openTunnel(appName: string, port: number, subdomain?: string, isReconne
|
||||||
const config = loadConfig()
|
const config = loadConfig()
|
||||||
if (!config[appName]) return
|
if (!config[appName]) return
|
||||||
hostLog(`Tunnel reconnecting: ${appName}`)
|
hostLog(`Tunnel reconnecting: ${appName}`)
|
||||||
openTunnel(appName, port, config[appName]?.subdomain, true)
|
openTunnel(appName, port, config[appName]?.subdomain)
|
||||||
}, delay)
|
}, delay)
|
||||||
|
|
||||||
_reconnectTimers.set(appName, timer)
|
_reconnectTimers.set(appName, timer)
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,8 @@ function ensureConnection() {
|
||||||
buf = lines.pop()!
|
buf = lines.pop()!
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!line.startsWith('data: ')) continue
|
if (!line.startsWith('data: ')) continue
|
||||||
const payload = line.slice(6)
|
|
||||||
if (!payload) continue
|
|
||||||
try {
|
try {
|
||||||
const event: ToesEvent = JSON.parse(payload)
|
const event: ToesEvent = JSON.parse(line.slice(6))
|
||||||
_listeners.forEach(l => {
|
_listeners.forEach(l => {
|
||||||
if (l.types.includes(event.type)) l.callback(event)
|
if (l.types.includes(event.type)) l.callback(event)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user