create-pyric 0.1.0-alpha.14 → 0.1.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onValue, ref, serverTimestamp, set } from 'firebase/database';
|
|
1
|
+
import { onDisconnect, onValue, ref, serverTimestamp, set } from 'firebase/database';
|
|
2
2
|
import { auth, rtdb } from '../firebase/app';
|
|
3
3
|
import { asUserId, type AuthUser, type PresenceEntry, type PresenceRecord, ServiceError } from '../firebase/types';
|
|
4
4
|
import { requireUid } from './firestore-helpers';
|
|
@@ -24,19 +24,15 @@ export class PresenceService {
|
|
|
24
24
|
* `/presence/{uid}` the first time a user comes online, which is what
|
|
25
25
|
* fires the `onPresenceOnline` Cloud Function.
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* under `vite dev` we rely on the explicit `goOffline` writes below.
|
|
27
|
+
* Register `onDisconnect` before publishing the online state so production
|
|
28
|
+
* and the local sandbox both flip the node to offline on a clean lifecycle
|
|
29
|
+
* boundary. The explicit `goOffline` method remains the user-driven path.
|
|
31
30
|
*/
|
|
32
31
|
async goOnline(user: AuthUser): Promise<void> {
|
|
33
32
|
const uid = requireUid(user.uid);
|
|
34
33
|
try {
|
|
35
34
|
const reference = presenceRef(uid);
|
|
36
|
-
|
|
37
|
-
const { onDisconnect } = await import('firebase/database');
|
|
38
|
-
await onDisconnect(reference).set({ state: 'offline', displayName: user.displayName, at: serverTimestamp() });
|
|
39
|
-
}
|
|
35
|
+
await onDisconnect(reference).set({ state: 'offline', displayName: user.displayName, at: serverTimestamp() });
|
|
40
36
|
await set(reference, { state: 'online', displayName: user.displayName, at: serverTimestamp() });
|
|
41
37
|
} catch (error) {
|
|
42
38
|
throw mapRtdbError(error);
|