atom.io 0.46.10 → 0.46.12
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/dist/{chunk-CKcAJnC7.js → chunk-Dms8e946.js} +2 -2
- package/dist/eslint-plugin/index.js +2 -2
- package/dist/internal/index.js +60 -60
- package/dist/internal/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +4 -4
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +38 -27
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +1 -1
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +23 -11
- package/dist/realtime-server/index.js.map +1 -1
- package/package.json +3 -3
- package/src/realtime-client/create-subscriber.ts +22 -14
- package/src/realtime-client/pull-selector-roots.ts +1 -0
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +30 -38
- package/src/realtime-server/ipc-sockets/parent-socket.ts +17 -4
- package/src/realtime-server/provide-rooms.ts +10 -3
|
@@ -1,52 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type UserKey,
|
|
6
|
-
usersInRooms,
|
|
7
|
-
} from "atom.io/realtime"
|
|
1
|
+
import type { ReadonlyPureSelectorToken, RegularAtomToken } from "atom.io"
|
|
2
|
+
import { atom, getInternalRelations, selector } from "atom.io"
|
|
3
|
+
import type { RoomKey, SocketKey, UserKey } from "atom.io/realtime"
|
|
4
|
+
import { usersInRooms } from "atom.io/realtime"
|
|
8
5
|
|
|
9
|
-
export const mySocketKeyAtom:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
6
|
+
export const mySocketKeyAtom: RegularAtomToken<SocketKey | undefined> = atom({
|
|
7
|
+
key: `mySocketKey`,
|
|
8
|
+
default: undefined,
|
|
9
|
+
})
|
|
14
10
|
|
|
15
|
-
export const myUserKeyAtom:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
11
|
+
export const myUserKeyAtom: RegularAtomToken<UserKey | null> = atom({
|
|
12
|
+
key: `myUserKey`,
|
|
13
|
+
default: null,
|
|
14
|
+
effects: [
|
|
15
|
+
(userKey) => {
|
|
16
|
+
if (typeof window !== `undefined`) {
|
|
17
|
+
void import(`atom.io/web`).then(({ storageSync }) => {
|
|
18
|
+
storageSync(globalThis.localStorage, JSON, `myUserKey`)(userKey)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
})
|
|
29
24
|
|
|
30
|
-
export const myRoomKeySelector:
|
|
31
|
-
|
|
25
|
+
export const myRoomKeySelector: ReadonlyPureSelectorToken<RoomKey | null> =
|
|
26
|
+
selector({
|
|
32
27
|
key: `myRoomKey`,
|
|
33
28
|
get: ({ get }) => {
|
|
34
29
|
if (
|
|
35
|
-
`
|
|
36
|
-
`
|
|
30
|
+
`process` in globalThis &&
|
|
31
|
+
`env` in process &&
|
|
32
|
+
`REALTIME_ROOM_KEY` in process.env
|
|
37
33
|
) {
|
|
38
34
|
// if a room running server-side wants its own key, this is where it lives
|
|
39
|
-
return
|
|
35
|
+
return process.env[`REALTIME_ROOM_KEY`] as RoomKey
|
|
40
36
|
}
|
|
41
37
|
const myUserKey = get(myUserKeyAtom)
|
|
42
38
|
if (!myUserKey) return null
|
|
43
|
-
const [, usersInRoomsAtoms] =
|
|
44
|
-
usersInRooms,
|
|
45
|
-
`split`,
|
|
46
|
-
)
|
|
39
|
+
const [, usersInRoomsAtoms] = getInternalRelations(usersInRooms, `split`)
|
|
47
40
|
const roomKeys = get(usersInRoomsAtoms, myUserKey)
|
|
48
|
-
for (const roomKey of roomKeys)
|
|
49
|
-
|
|
50
|
-
}
|
|
41
|
+
for (const roomKey of roomKeys) return roomKey
|
|
42
|
+
return null
|
|
51
43
|
},
|
|
52
44
|
})
|
|
@@ -19,7 +19,7 @@ export class SubjectSocket<
|
|
|
19
19
|
public in: Subject<EventPayload<I>>
|
|
20
20
|
public out: Subject<EventPayload<O>>
|
|
21
21
|
public id = `no_id_retrieved`
|
|
22
|
-
public
|
|
22
|
+
public disposalEffects: (() => void)[] = []
|
|
23
23
|
|
|
24
24
|
public constructor(id: string) {
|
|
25
25
|
super((...args) => {
|
|
@@ -35,7 +35,7 @@ export class SubjectSocket<
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public dispose(): void {
|
|
38
|
-
for (const dispose of this.
|
|
38
|
+
for (const dispose of this.disposalEffects) {
|
|
39
39
|
dispose()
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -179,6 +179,19 @@ export class ParentSocket<
|
|
|
179
179
|
this.logger.info(`👤`, userKey, `joined`)
|
|
180
180
|
const existingRelay = this.relays.get(userKey)
|
|
181
181
|
if (existingRelay) {
|
|
182
|
+
this.logger.info(`🔗`, `reattaching relay services for`, userKey)
|
|
183
|
+
const cleanupRelay = this.initRelay(existingRelay, userKey)
|
|
184
|
+
if (cleanupRelay) {
|
|
185
|
+
existingRelay.disposalEffects.push(cleanupRelay)
|
|
186
|
+
}
|
|
187
|
+
this.on(userKey, (...data) => {
|
|
188
|
+
relay.in.next(data)
|
|
189
|
+
})
|
|
190
|
+
existingRelay.disposalEffects.push(
|
|
191
|
+
existingRelay.out.subscribe(`socket`, (data) => {
|
|
192
|
+
this.emit(userKey, ...(data as any))
|
|
193
|
+
}),
|
|
194
|
+
)
|
|
182
195
|
return
|
|
183
196
|
}
|
|
184
197
|
const relay = new SubjectSocket(userKey)
|
|
@@ -186,12 +199,12 @@ export class ParentSocket<
|
|
|
186
199
|
this.logger.info(`🔗`, `attaching relay services for`, userKey)
|
|
187
200
|
const cleanupRelay = this.initRelay(relay, userKey)
|
|
188
201
|
if (cleanupRelay) {
|
|
189
|
-
relay.
|
|
202
|
+
relay.disposalEffects.push(cleanupRelay)
|
|
190
203
|
}
|
|
191
204
|
this.on(userKey, (...data) => {
|
|
192
205
|
relay.in.next(data)
|
|
193
206
|
})
|
|
194
|
-
relay.
|
|
207
|
+
relay.disposalEffects.push(
|
|
195
208
|
relay.out.subscribe(`socket`, (data) => {
|
|
196
209
|
this.emit(userKey, ...(data as any))
|
|
197
210
|
}),
|
|
@@ -191,10 +191,17 @@ export function provideEnterAndExit({
|
|
|
191
191
|
roomSocket.on(`joinRoom`, enterRoom)
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
const userIsAlreadyInRoom = getFromStore(
|
|
195
|
+
store,
|
|
196
|
+
getInternalRelationsFromStore(store, usersInRooms),
|
|
197
|
+
roomKey,
|
|
198
|
+
).has(userKey as any)
|
|
197
199
|
|
|
200
|
+
if (!userIsAlreadyInRoom) {
|
|
201
|
+
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
202
|
+
relations.set({ room: roomKey, user: userKey })
|
|
203
|
+
})
|
|
204
|
+
}
|
|
198
205
|
childSocket.emit(`user-joins`, userKey)
|
|
199
206
|
|
|
200
207
|
toRoom = (payload) => {
|