Import apps/android/src/state/connection-actions.ts
This commit is contained in:
parent
50ffdc1269
commit
079c3bf024
|
|
@ -21,6 +21,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
const generation = ++runtime.connectionGeneration
|
||||
++runtime.sessionLoadGeneration
|
||||
runtime.sessionReadAbort?.abort()
|
||||
runtime.clearHarnessCatalogSync()
|
||||
const memory = useBrowseMemory.getState()
|
||||
const scope = browseScope({...get(), selectedDevice: device})
|
||||
const cached = device.trusted ? memory.catalogs[scope] : undefined
|
||||
|
|
@ -45,6 +46,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
connectionProbeOrder: [],
|
||||
connectionNetworkDetails: undefined,
|
||||
hostDescriptor: undefined,
|
||||
hostSessionEvents: false,
|
||||
codexAvailable: false,
|
||||
cursorAvailable: false,
|
||||
antigravityAvailable: false,
|
||||
|
|
@ -87,6 +89,11 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
fetchIceServers: async connectionId => api.turnCredentials(connectionId),
|
||||
preferredTransports: [...preferredTransports],
|
||||
forceRelay,
|
||||
relayFirstUpgrade: !forceRelay && preference === 'auto',
|
||||
onTransportUpgraded: () => {
|
||||
if (generation !== runtime.connectionGeneration) return
|
||||
void get().refreshConnectionNetworkDetails()
|
||||
},
|
||||
onWebRtcFallback: () => {
|
||||
if (generation !== runtime.connectionGeneration) return
|
||||
// Repeated negotiation failures on this host: remember to go
|
||||
|
|
@ -118,6 +125,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
// Drop local stream handles so reconnect opens a fresh stream.
|
||||
void runtime.closeActiveCodexStream(false)
|
||||
void runtime.closeActiveCursorStream(false)
|
||||
runtime.clearHarnessCatalogSync()
|
||||
if (get().connection.phase !== 'disconnected') {
|
||||
++runtime.connectionGeneration
|
||||
++runtime.sessionLoadGeneration
|
||||
|
|
@ -132,6 +140,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
connection: { phase: 'offline', stats: { mode: 'Disconnected', connected: false }, error: zhCN.runtime.hostClosed,
|
||||
retryable: closeOptions?.retryable !== false },
|
||||
connectionStage: undefined,
|
||||
hostSessionEvents: false,
|
||||
codexAvailable: false,
|
||||
cursorAvailable: false,
|
||||
antigravityAvailable: false,
|
||||
|
|
@ -156,6 +165,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
runtime.webRtcFallbackStreak = 0
|
||||
set({
|
||||
hostDescriptor,
|
||||
hostSessionEvents: runtime.connection.hasSessionEvents(),
|
||||
codexAvailable: runtime.connection.hasCodex(),
|
||||
cursorAvailable: runtime.connection.hasCursor(),
|
||||
antigravityAvailable: runtime.connection.hasAntigravity(),
|
||||
|
|
@ -268,7 +278,13 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
await get().refreshConnectionNetworkDetails()
|
||||
}
|
||||
}
|
||||
else await get().refreshConnectionNetworkDetails()
|
||||
else {
|
||||
await get().refreshConnectionNetworkDetails()
|
||||
if (get().transportPreference === 'auto') {
|
||||
const nextPreferred: readonly string[] = await resolveAutomaticPreferredTransports().catch(() => [])
|
||||
void runtime.connection.promoteTransport({ preferLan: nextPreferred.includes('lan') })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async refreshConnectionNetworkDetails() {
|
||||
|
|
@ -288,6 +304,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
++runtime.sessionLoadGeneration
|
||||
runtime.reconnectFlight = undefined
|
||||
runtime.clearPendingMuxFrames()
|
||||
runtime.clearHarnessCatalogSync()
|
||||
await runtime.closeActiveCodexStream(false)
|
||||
await runtime.closeActiveCursorStream(false)
|
||||
await runtime.connection.close()
|
||||
|
|
@ -299,6 +316,7 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
connectionNetworkDetails: undefined,
|
||||
selectedDevice: undefined,
|
||||
hostDescriptor: undefined,
|
||||
hostSessionEvents: false,
|
||||
codexAvailable: false,
|
||||
cursorAvailable: false,
|
||||
antigravityAvailable: false,
|
||||
|
|
@ -330,9 +348,11 @@ export function createConnectionActions({ get, set, runtime }: SessionAccess): P
|
|||
runtime.flushPendingMuxFrames()
|
||||
++runtime.sessionLoadGeneration
|
||||
runtime.clearPendingMuxFrames()
|
||||
runtime.clearHarnessCatalogSync()
|
||||
set({
|
||||
connection: { phase: 'offline', stats: { mode: 'Disconnected', connected: false }, error: zhCN.runtime.networkUnavailable,
|
||||
...(get().connection.retryable === false ? { retryable: false } : {}) },
|
||||
hostSessionEvents: false,
|
||||
codexAvailable: false,
|
||||
busyAction: undefined,
|
||||
cursorAvailable: false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue