Send files directly between devices over the internet - no cloud storage, no size limits.
TypeScript cross-platformdata-transferdecentralizedfile-sharingfile-transferhole-punchingopen-sourcep2ppeer-to-peerprivacyprivacy-tools
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.tsindex 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) returnif (isBackgroundTransferActive()) return- if (Platform.OS !== 'android') returnworklet.suspend()}diff --git a/packages/core/src/worklet/transfer/orchestrator.ts b/packages/core/src/worklet/transfer/orchestrator.tsindex 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.tsindex 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 = falsefor (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.tsindex 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 === 0const timeoutMs =- state.isReconnecting || state.incomingFileOffers.length > 0+ state.incomingFileOffers.length > 0 && !state.isReconnecting? RECONNECT_TIMEOUT_MS: INITIAL_CONNECT_TIMEOUT_MSreturn { shouldWatch, timeoutMs }