Compare commits

..

No commits in common. "74f9062a8987b4a2e7088411115d7aa5decd9b1f" and "cfba20707779f09c1926216f8a35fcffb297b4c1" have entirely different histories.

3 changed files with 7 additions and 14 deletions

View File

@ -8,11 +8,7 @@ const router = Hype.router()
// individual events so apps can react to specific lifecycle changes.
router.sse('/stream', (send) => {
const unsub = onEvent(event => send(event))
const heartbeat = setInterval(() => send('', 'ping'), 60_000)
return () => {
clearInterval(heartbeat)
unsub()
}
return unsub
})
export default router

View File

@ -146,19 +146,18 @@ export function renameTunnelConfig(oldName: string, newName: string) {
saveConfig(config)
}
function cancelReconnect(appName: string, resetAttempts = true) {
function cancelReconnect(appName: string) {
const timer = _reconnectTimers.get(appName)
if (timer) {
clearTimeout(timer)
_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
// but preserve attempts counter during reconnection so backoff works
cancelReconnect(appName, !isReconnect)
cancelReconnect(appName)
// Close existing tunnel if any
const existing = _tunnels.get(appName)
@ -233,7 +232,7 @@ function openTunnel(appName: string, port: number, subdomain?: string, isReconne
const config = loadConfig()
if (!config[appName]) return
hostLog(`Tunnel reconnecting: ${appName}`)
openTunnel(appName, port, config[appName]?.subdomain, true)
openTunnel(appName, port, config[appName]?.subdomain)
}, delay)
_reconnectTimers.set(appName, timer)

View File

@ -35,10 +35,8 @@ function ensureConnection() {
buf = lines.pop()!
for (const line of lines) {
if (!line.startsWith('data: ')) continue
const payload = line.slice(6)
if (!payload) continue
try {
const event: ToesEvent = JSON.parse(payload)
const event: ToesEvent = JSON.parse(line.slice(6))
_listeners.forEach(l => {
if (l.types.includes(event.type)) l.callback(event)
})