Skip to content

Send files directly between devices over the internet - no cloud storage, no size limits.

reconnect the swarm when the app returns from background

Denis Lupookov25beddae4bf1
diff --git a/apps/mobile/src/api/mobileApi.ts b/apps/mobile/src/api/mobileApi.ts
index 0e5ce46..bbad6d6 100644
--- a/apps/mobile/src/api/mobileApi.ts
+++ b/apps/mobile/src/api/mobileApi.ts
@@ -173,7 +173,6 @@ class MobileApi {
if (state !== 'background' || worklet.suspended) return
if (isBackgroundTransferActive()) return
- if (Platform.OS !== 'android') return
worklet.suspend()
}
diff --git a/packages/core/src/worklet/transfer/orchestrator.ts b/packages/core/src/worklet/transfer/orchestrator.ts
index edc8327..0134772 100644
--- a/packages/core/src/worklet/transfer/orchestrator.ts
+++ b/packages/core/src/worklet/transfer/orchestrator.ts
@@ -723,8 +723,8 @@ export class TransferOrchestrator implements TransferRPC {
await tryAsyncWithin('discovery.stop (suspend)', LIFECYCLE_TEARDOWN_TIMEOUT_MS, () =>
this.discovery.stop()
)
- await tryAsyncWithin('swarm.endSession (suspend)', LIFECYCLE_TEARDOWN_TIMEOUT_MS, () =>
- this.swarm.endSession()
+ await tryAsyncWithin('swarm.suspendTransport (suspend)', LIFECYCLE_TEARDOWN_TIMEOUT_MS, () =>
+ this.swarm.suspendTransport()
)
})
}
@@ -738,6 +738,8 @@ export class TransferOrchestrator implements TransferRPC {
if (!this.currentTopic) return
+ this.sendStatus('joined', { peers: this.swarm.peerCount })
+
try {
await this.swarm.join(this.currentTopic)
} catch (err) {
diff --git a/packages/core/src/worklet/transfer/swarm.ts b/packages/core/src/worklet/transfer/swarm.ts
index 6f74953..c01adc3 100644
--- a/packages/core/src/worklet/transfer/swarm.ts
+++ b/packages/core/src/worklet/transfer/swarm.ts
@@ -168,8 +168,7 @@ export class TransferSwarm {
})
}
- async endSession(): Promise<void> {
- this.hostedTopicHex = null
+ async suspendTransport(): Promise<void> {
this.joinedAny = false
for (const [conn, session] of this.peerSessions) {
@@ -192,6 +191,11 @@ export class TransferSwarm {
}
}
+ async endSession(): Promise<void> {
+ this.hostedTopicHex = null
+ await this.suspendTransport()
+ }
+
async join(topicHex: string): Promise<void> {
if (this.identityStore && !this.joinedAny) {
await this.swapKeyPair(await this.identityStore.getOrCreate(topicHex))
diff --git a/packages/domain/src/transfer/effects/peerWatchdog.ts b/packages/domain/src/transfer/effects/peerWatchdog.ts
index 88e811b..cceba28 100644
--- a/packages/domain/src/transfer/effects/peerWatchdog.ts
+++ b/packages/domain/src/transfer/effects/peerWatchdog.ts
@@ -14,7 +14,7 @@ function evaluate(): WatchdogKey {
const state = transferStore.getState()
const shouldWatch = getAppActive() && state.role === 'receiver' && state.peerCount === 0
const timeoutMs =
- state.isReconnecting || state.incomingFileOffers.length > 0
+ state.incomingFileOffers.length > 0 && !state.isReconnecting
? RECONNECT_TIMEOUT_MS
: INITIAL_CONNECT_TIMEOUT_MS
return { shouldWatch, timeoutMs }