Import packages/plugin/src/client-recovery.ts
This commit is contained in:
parent
5ca5d211d4
commit
9f5ab5bd67
|
|
@ -0,0 +1,15 @@
|
||||||
|
import type { RemoteStatus } from './client/types.js'
|
||||||
|
import type { StatusFeed } from './status-stream.js'
|
||||||
|
|
||||||
|
/** Reopen native read subscriptions after a fresh authenticated carrier is ready. */
|
||||||
|
export function subscribeRemoteRecovery(feed: StatusFeed<RemoteStatus>, reconnect: () => void): () => void {
|
||||||
|
let previous: RemoteStatus | undefined
|
||||||
|
return feed.subscribe(status => {
|
||||||
|
const recovered = status.mode === 'remote' && status.connected === true
|
||||||
|
&& previous?.mode === 'remote' && previous.target?.deviceId === status.target?.deviceId
|
||||||
|
&& status.recoveryGeneration !== undefined
|
||||||
|
&& status.recoveryGeneration !== previous.recoveryGeneration
|
||||||
|
previous = status
|
||||||
|
if (recovered) reconnect()
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue