atom.io 0.46.5 → 0.46.7
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/realtime/index.d.ts +7 -6
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +19 -10
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +13 -13
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +10 -3
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +49 -41
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +126 -97
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.js +2 -2
- package/dist/realtime-testing/index.js.map +1 -1
- package/package.json +18 -17
- package/src/realtime/realtime-continuity.ts +2 -2
- package/src/realtime/shared-room-store.ts +38 -17
- package/src/realtime/socket-interface.ts +1 -1
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +3 -1
- package/src/realtime-client/continuity/use-conceal-state.ts +2 -1
- package/src/realtime-client/pull-atom-family-member.ts +1 -1
- package/src/realtime-client/pull-atom.ts +1 -1
- package/src/realtime-client/pull-mutable-atom-family-member.ts +1 -1
- package/src/realtime-client/pull-mutable-atom.ts +1 -1
- package/src/realtime-client/pull-selector-family-member.ts +1 -1
- package/src/realtime-client/pull-selector-roots.ts +1 -1
- package/src/realtime-client/pull-selector.ts +1 -1
- package/src/realtime-client/push-state.ts +1 -1
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +16 -3
- package/src/realtime-client/sync-continuity.ts +1 -2
- package/src/realtime-server/continuity/provide-outcomes.ts +1 -1
- package/src/realtime-server/ipc-sockets/child-socket.ts +6 -9
- package/src/realtime-server/ipc-sockets/parent-socket.ts +1 -8
- package/src/realtime-server/provide-rooms.ts +64 -16
- package/src/realtime-server/realtime-family-provider.ts +51 -35
- package/src/realtime-server/realtime-mutable-family-provider.ts +50 -34
- package/src/realtime-server/realtime-mutable-provider.ts +4 -4
- package/src/realtime-server/realtime-state-provider.ts +7 -7
- package/src/realtime-server/realtime-state-receiver.ts +2 -2
- package/src/realtime-server/server-config.ts +20 -13
- package/src/realtime-server/server-socket-state.ts +3 -3
- package/src/realtime-testing/setup-realtime-test.tsx +2 -2
|
@@ -96,37 +96,6 @@ declare class ParentSocket<I extends Events & { [id in string as `relay::${id}`]
|
|
|
96
96
|
receiveRelay(attachServices: (socket: SubjectSocket<any, any>, userKey: UserKey) => (() => void) | void): void;
|
|
97
97
|
}
|
|
98
98
|
//#endregion
|
|
99
|
-
//#region src/realtime-server/server-config.d.ts
|
|
100
|
-
type ServerConfig = {
|
|
101
|
-
socket: Socket;
|
|
102
|
-
userKey: UserKey;
|
|
103
|
-
store?: RootStore;
|
|
104
|
-
};
|
|
105
|
-
/** Socket Handshake details--taken from socket.io */
|
|
106
|
-
type Handshake = {
|
|
107
|
-
/** The headers sent as part of the handshake */
|
|
108
|
-
headers: IncomingHttpHeaders;
|
|
109
|
-
/** The date of creation (as string) */
|
|
110
|
-
time: string;
|
|
111
|
-
/** The ip of the client */
|
|
112
|
-
address: string;
|
|
113
|
-
/** Whether the connection is cross-domain */
|
|
114
|
-
xdomain: boolean;
|
|
115
|
-
/** Whether the connection is secure */
|
|
116
|
-
secure: boolean;
|
|
117
|
-
/** The date of creation (as unix timestamp) */
|
|
118
|
-
issued: number;
|
|
119
|
-
/** The request URL string */
|
|
120
|
-
url: string;
|
|
121
|
-
/** The query object */
|
|
122
|
-
query: ParsedUrlQuery;
|
|
123
|
-
/** The auth object */
|
|
124
|
-
auth: {
|
|
125
|
-
[key: string]: any;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
declare function realtime(server: Server, auth: (handshake: Handshake) => Loadable<Error | UserKey>, onConnect: (config: ServerConfig) => Loadable<() => Loadable<void>>, store?: RootStore): () => Promise<void>;
|
|
129
|
-
//#endregion
|
|
130
99
|
//#region src/realtime-server/provide-rooms.d.ts
|
|
131
100
|
type RoomMap = Map<string, ChildSocket<any, any, ChildProcessWithoutNullStreams>>;
|
|
132
101
|
declare global {
|
|
@@ -174,6 +143,9 @@ type ProvideRoomsConfig<RoomNames extends string> = {
|
|
|
174
143
|
resolveRoomScript: (path: RoomNames) => [string, string[]];
|
|
175
144
|
roomNames: RoomNames[];
|
|
176
145
|
roomTimeLimit?: number;
|
|
146
|
+
userKey: UserKey;
|
|
147
|
+
store: RootStore;
|
|
148
|
+
socket: Socket;
|
|
177
149
|
};
|
|
178
150
|
declare function provideRooms<RoomNames extends string>({
|
|
179
151
|
store,
|
|
@@ -181,29 +153,29 @@ declare function provideRooms<RoomNames extends string>({
|
|
|
181
153
|
resolveRoomScript,
|
|
182
154
|
roomNames,
|
|
183
155
|
userKey
|
|
184
|
-
}: ProvideRoomsConfig<RoomNames>
|
|
156
|
+
}: ProvideRoomsConfig<RoomNames>): () => void;
|
|
185
157
|
//#endregion
|
|
186
158
|
//#region src/realtime-server/realtime-family-provider.d.ts
|
|
187
159
|
type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>;
|
|
188
160
|
declare function realtimeAtomFamilyProvider({
|
|
189
161
|
socket,
|
|
190
|
-
|
|
162
|
+
consumer,
|
|
191
163
|
store
|
|
192
|
-
}: ServerConfig): <J extends Json.Serializable, K extends Canonical>(family: AtomIO.RegularAtomFamilyToken<J, K>, index: AtomIO.ReadableToken<Iterable<NoInfer<K>>>) => () => void;
|
|
164
|
+
}: ServerConfig): <J extends Json.Serializable, K extends Canonical>(family: AtomIO.RegularAtomFamilyToken<J, K>, index: AtomIO.ReadableToken<Iterable<NoInfer<K>>> | Iterable<NoInfer<K>>) => () => void;
|
|
193
165
|
//#endregion
|
|
194
166
|
//#region src/realtime-server/realtime-mutable-family-provider.d.ts
|
|
195
167
|
type MutableFamilyProvider = ReturnType<typeof realtimeMutableFamilyProvider>;
|
|
196
168
|
declare function realtimeMutableFamilyProvider({
|
|
197
169
|
socket,
|
|
198
|
-
|
|
170
|
+
consumer,
|
|
199
171
|
store
|
|
200
|
-
}: ServerConfig): <T extends Transceiver<any, any, any>, K extends Canonical>(family: AtomIO.MutableAtomFamilyToken<T, K>, index: AtomIO.ReadableToken<Iterable<NoInfer<K>>>) => () => void;
|
|
172
|
+
}: ServerConfig): <T extends Transceiver<any, any, any>, K extends Canonical>(family: AtomIO.MutableAtomFamilyToken<T, K>, index: AtomIO.ReadableToken<Iterable<NoInfer<K>>> | Iterable<NoInfer<K>>) => () => void;
|
|
201
173
|
//#endregion
|
|
202
174
|
//#region src/realtime-server/realtime-mutable-provider.d.ts
|
|
203
175
|
type MutableProvider = ReturnType<typeof realtimeMutableProvider>;
|
|
204
176
|
declare function realtimeMutableProvider({
|
|
205
177
|
socket,
|
|
206
|
-
|
|
178
|
+
consumer,
|
|
207
179
|
store
|
|
208
180
|
}: ServerConfig): <Core extends Transceiver<any, Json.Serializable, Json.Serializable>>(token: AtomIO.MutableAtomToken<Core>) => () => void;
|
|
209
181
|
//#endregion
|
|
@@ -211,7 +183,7 @@ declare function realtimeMutableProvider({
|
|
|
211
183
|
type StateProvider = ReturnType<typeof realtimeStateProvider>;
|
|
212
184
|
declare function realtimeStateProvider({
|
|
213
185
|
socket,
|
|
214
|
-
|
|
186
|
+
consumer,
|
|
215
187
|
store
|
|
216
188
|
}: ServerConfig): <C extends Json.Serializable, S extends C>(clientToken: AtomIO.WritableToken<C>, serverData?: AtomIO.ReadableToken<S> | S) => () => void;
|
|
217
189
|
//#endregion
|
|
@@ -219,10 +191,46 @@ declare function realtimeStateProvider({
|
|
|
219
191
|
type StateReceiver = ReturnType<typeof realtimeStateReceiver>;
|
|
220
192
|
declare function realtimeStateReceiver({
|
|
221
193
|
socket,
|
|
222
|
-
|
|
194
|
+
consumer,
|
|
223
195
|
store
|
|
224
196
|
}: ServerConfig): <S extends Json.Serializable, C extends S>(schema: StandardSchemaV1<unknown, C>, clientToken: WritableToken<C>, serverToken?: WritableToken<S>) => () => void;
|
|
225
197
|
//#endregion
|
|
198
|
+
//#region src/realtime-server/server-config.d.ts
|
|
199
|
+
type ServerConfig = {
|
|
200
|
+
socket: Socket;
|
|
201
|
+
consumer: RoomKey | UserKey;
|
|
202
|
+
store?: RootStore;
|
|
203
|
+
};
|
|
204
|
+
type UserServerConfig = {
|
|
205
|
+
socket: Socket;
|
|
206
|
+
consumer: UserKey;
|
|
207
|
+
store?: RootStore;
|
|
208
|
+
};
|
|
209
|
+
/** Socket Handshake details--taken from socket.io */
|
|
210
|
+
type Handshake = {
|
|
211
|
+
/** The headers sent as part of the handshake */
|
|
212
|
+
headers: IncomingHttpHeaders;
|
|
213
|
+
/** The date of creation (as string) */
|
|
214
|
+
time: string;
|
|
215
|
+
/** The ip of the client */
|
|
216
|
+
address: string;
|
|
217
|
+
/** Whether the connection is cross-domain */
|
|
218
|
+
xdomain: boolean;
|
|
219
|
+
/** Whether the connection is secure */
|
|
220
|
+
secure: boolean;
|
|
221
|
+
/** The date of creation (as unix timestamp) */
|
|
222
|
+
issued: number;
|
|
223
|
+
/** The request URL string */
|
|
224
|
+
url: string;
|
|
225
|
+
/** The query object */
|
|
226
|
+
query: ParsedUrlQuery;
|
|
227
|
+
/** The auth object */
|
|
228
|
+
auth: {
|
|
229
|
+
[key: string]: any;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
declare function realtime(server: Server, auth: (handshake: Handshake) => Loadable<Error | UserKey>, onConnect: (config: UserServerConfig) => Loadable<() => Loadable<void>>, store?: RootStore): () => Promise<void>;
|
|
233
|
+
//#endregion
|
|
226
234
|
//#region src/realtime-server/server-socket-state.d.ts
|
|
227
235
|
type SocketSystemHierarchy = Hierarchy<[{
|
|
228
236
|
above: `root`;
|
|
@@ -230,8 +238,8 @@ type SocketSystemHierarchy = Hierarchy<[{
|
|
|
230
238
|
}]>;
|
|
231
239
|
declare const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>;
|
|
232
240
|
declare const socketKeysAtom: MutableAtomToken<UList<SocketKey>>;
|
|
233
|
-
declare const
|
|
241
|
+
declare const onlineUsersAtom: MutableAtomToken<UList<UserKey>>;
|
|
234
242
|
declare const usersOfSockets: JoinToken<`user`, UserKey, `socket`, SocketKey, `1:1`>;
|
|
235
243
|
//#endregion
|
|
236
|
-
export { ChildProcess, ChildSocket, CustomSocket, DestroyRoomConfig, EventBuffer, EventPayload, Events, FamilyProvider, Handshake, MutableFamilyProvider, MutableProvider, PROOF_OF_LIFE_SIGNAL, ParentProcess, ParentSocket, ProvideContinuity, ProvideEnterAndExitConfig, ProvideRoomsConfig, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, SpawnRoomConfig, StateProvider, StateReceiver, StderrLog, SubjectSocket, destroyRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtime, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, socketAtoms, socketKeysAtom, spawnRoom,
|
|
244
|
+
export { ChildProcess, ChildSocket, CustomSocket, DestroyRoomConfig, EventBuffer, EventPayload, Events, FamilyProvider, Handshake, MutableFamilyProvider, MutableProvider, PROOF_OF_LIFE_SIGNAL, ParentProcess, ParentSocket, ProvideContinuity, ProvideEnterAndExitConfig, ProvideRoomsConfig, ROOMS, RoomMap, ServerConfig, SocketSystemHierarchy, SpawnRoomConfig, StateProvider, StateReceiver, StderrLog, SubjectSocket, UserServerConfig, destroyRoom, onlineUsersAtom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtime, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, socketAtoms, socketKeysAtom, spawnRoom, usersOfSockets };
|
|
237
245
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap","ROOMS: RoomMap","roomMeta: { count: number }","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ATOM_IO_REALTIME_SERVER_ROOMS: RoomMap","ROOMS: RoomMap","roomMeta: { count: number }","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketKeysAtom: MutableAtomToken<UList<SocketKey>>","onlineUsersAtom: MutableAtomToken<UList<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>"],"sources":["../../src/realtime-server/continuity/provide-continuity.ts","../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/provide-rooms.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts","../../src/realtime-server/server-config.ts","../../src/realtime-server/server-socket-state.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;KAYY,iBAAA,gBACC,0BACH;iBAEM,0BAAA;;;GAGb,eAAe;;;KChBN,MAAA,GAAS,IAAA,CAAK,eAAe,IAAA,CAAK;KAElC,kCACU,iCACI,8BAA8B,4BACxC,aAAa;UAEZ,sBACN,iCACe,mBAAmB,WACnC;cACG,YAAY,aAAa,GAAG;;ADF7B,uBCKU,YDJT,CAGb,UCC6C,MDD7B,EACf,UCA8D,MDA9D,CACA,YCAW,MDAX,CAAA;EACE,UAAA,SAAA,ECCmB,GDDnB,CAAA,MCC6B,CDD7B,ECCgC,GDDhC,CAAA,CAAA,GAAA,IAAA,ECC8C,IAAA,CAAK,KDDnD,EAAA,GAAA,IAAA,CAAA,CAAA;EAAe,UAAA,eAAA,ECEU,GDFV,CAAA,CAAA,KAAA,EAAA,MAAA,EAAA,GAAA,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ACf;;AAEE,KUoBS,SAAA,GVpBT;EAAe;EAAA,OAAA,EUsBR,mBVtBQ;;;;EChBlB,OAAY,EAAA,MAAA;EAEZ;EACsB,OAAA,EAAA,OAAA;EACI;EAA8B,MAAA,EAAA,OAAA;EACxC;EAAa,MAAA,EAAA,MAAA;EAAA;EAE7B,GAAiB,EAAA,MAAA;EACN;EACe,KAAA,ES2ClB,cT3CkB;EAAmB;EAEP,IAAA,EAAA;IAAG,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;EAAhB,CAAA;CAAZ;AADH,iBSiDM,QAAA,CTjDN,MAAA,ESkDD,MTlDC,EAAA,IAAA,EAAA,CAAA,SAAA,ESmDS,STnDT,EAAA,GSmDuB,QTnDvB,CSmDgC,KTnDhC,GSmDwC,OTnDxC,CAAA,EAAA,SAAA,EAAA,CAAA,MAAA,ESoDW,gBTpDX,EAAA,GSoDgC,QTpDhC,CAAA,GAAA,GSoD+C,QTpD/C,CAAA,IAAA,CAAA,CAAA,EAAA,KAAA,CAAA,ESqDF,STrDE,CAAA,EAAA,GAAA,GSsDD,OTtDC,CAAA,IAAA,CAAA;;;KUFE,qBAAA,GAAwB;;UAIzB,SAAS,WAAW;;cAKlBC,aAAa,uBAAuB,eAAe;cAMnDC,gBAAgB,iBAAiB,MAAM;cAIvCC,iBAAiB,iBAAiB,MAAM;cAIxCC,gBAAgB,kBAE5B,mBAEA"}
|
|
@@ -2,7 +2,8 @@ import { IMPLICIT, OWN_OP, Subject, actUponStore, editRelationsInStore, findInSt
|
|
|
2
2
|
import { Realm, atomFamily, join, mutableAtom } from "atom.io";
|
|
3
3
|
import { parseJson, stringifyJson } from "atom.io/json";
|
|
4
4
|
import { UList } from "atom.io/transceivers/u-list";
|
|
5
|
-
import { castSocket, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, ownersOfRooms, roomKeysAtom, usersInRooms, visibleUsersInRoomsSelector } from "atom.io/realtime";
|
|
5
|
+
import { castSocket, employSocket, isRoomKey, isSocketKey, isUserKey, mutexAtoms, ownersOfRooms, roomKeysAtom, usersInRooms, visibilityFromRoomSelector, visibleUsersInRoomsSelector } from "atom.io/realtime";
|
|
6
|
+
import { myRoomKeyAtom, myUserKeyAtom } from "atom.io/realtime-client";
|
|
6
7
|
import { spawn } from "node:child_process";
|
|
7
8
|
|
|
8
9
|
//#region src/realtime-server/continuity/continuity-store.ts
|
|
@@ -422,11 +423,6 @@ var ChildSocket = class extends CustomSocket {
|
|
|
422
423
|
constructor(proc, key, logger) {
|
|
423
424
|
super((event, ...args) => {
|
|
424
425
|
const stringifiedEvent = JSON.stringify([event, ...args]) + `\x03`;
|
|
425
|
-
const errorHandler = (err) => {
|
|
426
|
-
if (err.code === `EPIPE`) console.error(`EPIPE error during write`, this.proc.stdin);
|
|
427
|
-
this.proc.stdin.removeListener(`error`, errorHandler);
|
|
428
|
-
};
|
|
429
|
-
this.proc.stdin.once(`error`, errorHandler);
|
|
430
426
|
this.proc.stdin.write(stringifiedEvent);
|
|
431
427
|
return this;
|
|
432
428
|
});
|
|
@@ -531,6 +527,9 @@ var ChildSocket = class extends CustomSocket {
|
|
|
531
527
|
++idx;
|
|
532
528
|
}
|
|
533
529
|
});
|
|
530
|
+
this.proc.stdin.once(`error`, (err) => {
|
|
531
|
+
if (err.code === `EPIPE`) console.error(`EPIPE error during write`, this.proc.stdin);
|
|
532
|
+
});
|
|
534
533
|
if (proc.pid) this.id = proc.pid.toString();
|
|
535
534
|
}
|
|
536
535
|
};
|
|
@@ -541,8 +540,12 @@ const isAvailable = (exposedSubKeys, subKey) => {
|
|
|
541
540
|
for (const exposedSubKey of exposedSubKeys) if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) return true;
|
|
542
541
|
return false;
|
|
543
542
|
};
|
|
544
|
-
function realtimeMutableFamilyProvider({ socket,
|
|
543
|
+
function realtimeMutableFamilyProvider({ socket, consumer, store = IMPLICIT.STORE }) {
|
|
545
544
|
return function mutableFamilyProvider(family, index) {
|
|
545
|
+
const [dynamicIndex, staticIndex] = (() => {
|
|
546
|
+
if (typeof index === `object` && `key` in index && `type` in index) return [index, void 0];
|
|
547
|
+
return [void 0, index];
|
|
548
|
+
})();
|
|
546
549
|
const coreSubscriptions = /* @__PURE__ */ new Set();
|
|
547
550
|
const clearCoreSubscriptions = () => {
|
|
548
551
|
for (const unsub of coreSubscriptions) unsub();
|
|
@@ -580,21 +583,24 @@ function realtimeMutableFamilyProvider({ socket, userKey, store = IMPLICIT.STORE
|
|
|
580
583
|
}));
|
|
581
584
|
};
|
|
582
585
|
const start = () => {
|
|
583
|
-
store.logger.info(`👀`, `user`,
|
|
586
|
+
store.logger.info(`👀`, `user`, consumer, `can subscribe to family "${family.key}"`);
|
|
584
587
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
585
|
-
|
|
586
|
-
|
|
588
|
+
let exposedSubKeys;
|
|
589
|
+
if (dynamicIndex) exposedSubKeys = getFromStore(store, dynamicIndex);
|
|
590
|
+
else exposedSubKeys = staticIndex;
|
|
591
|
+
if (isAvailable(exposedSubKeys, subKey)) {
|
|
592
|
+
store.logger.info(`👀`, `user`, consumer, `is approved for a subscription to`, subKey, `in family "${family.key}"`);
|
|
587
593
|
exposeFamilyMembers(subKey);
|
|
588
594
|
} else {
|
|
589
|
-
store.logger.info(`❌`, `user`,
|
|
595
|
+
store.logger.info(`❌`, `user`, consumer, `is denied for a subscription to`, subKey, `in family "${family.key}"`);
|
|
590
596
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
591
597
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
592
598
|
}
|
|
593
599
|
}));
|
|
594
|
-
coreSubscriptions.add(subscribeToState(store,
|
|
595
|
-
store.logger.info(`👀`, `user`,
|
|
600
|
+
if (dynamicIndex) coreSubscriptions.add(subscribeToState(store, dynamicIndex, `expose-family:${family.key}:${socket.id}`, ({ newValue: newExposedSubKeys }) => {
|
|
601
|
+
store.logger.info(`👀`, `user`, consumer, `has the following keys available for family "${family.key}"`, newExposedSubKeys);
|
|
596
602
|
for (const subKey of newExposedSubKeys) if (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {
|
|
597
|
-
store.logger.info(`👀`, `user`,
|
|
603
|
+
store.logger.info(`👀`, `user`, consumer, `is retroactively approved for a subscription to`, subKey, `in family "${family.key}"`);
|
|
598
604
|
exposeFamilyMembers(subKey);
|
|
599
605
|
}
|
|
600
606
|
}));
|
|
@@ -609,7 +615,7 @@ function realtimeMutableFamilyProvider({ socket, userKey, store = IMPLICIT.STORE
|
|
|
609
615
|
|
|
610
616
|
//#endregion
|
|
611
617
|
//#region src/realtime-server/realtime-mutable-provider.ts
|
|
612
|
-
function realtimeMutableProvider({ socket,
|
|
618
|
+
function realtimeMutableProvider({ socket, consumer, store = IMPLICIT.STORE }) {
|
|
613
619
|
return function mutableProvider(token) {
|
|
614
620
|
const subscriptions = /* @__PURE__ */ new Set();
|
|
615
621
|
const clearSubscriptions = () => {
|
|
@@ -619,16 +625,16 @@ function realtimeMutableProvider({ socket, userKey, store = IMPLICIT.STORE }) {
|
|
|
619
625
|
const jsonToken = getJsonToken(store, token);
|
|
620
626
|
const trackerToken = getUpdateToken(token);
|
|
621
627
|
const start = () => {
|
|
622
|
-
store.logger.info(`👀`, `user`,
|
|
628
|
+
store.logger.info(`👀`, `user`, consumer, `can subscribe to state "${token.key}"`);
|
|
623
629
|
subscriptions.add(employSocket(socket, `sub:${token.key}`, () => {
|
|
624
|
-
store.logger.info(`👀`, `user`,
|
|
630
|
+
store.logger.info(`👀`, `user`, consumer, `subscribes to state "${token.key}"`);
|
|
625
631
|
clearSubscriptions();
|
|
626
632
|
socket.emit(`init:${token.key}`, getFromStore(store, jsonToken));
|
|
627
633
|
subscriptions.add(subscribeToState(store, trackerToken, `expose-single:${socket.id}`, ({ newValue }) => {
|
|
628
634
|
socket.emit(`next:${token.key}`, newValue);
|
|
629
635
|
}));
|
|
630
636
|
subscriptions.add(employSocket(socket, `unsub:${token.key}`, () => {
|
|
631
|
-
store.logger.info(`🙈`, `user`,
|
|
637
|
+
store.logger.info(`🙈`, `user`, consumer, `unsubscribes from state "${token.key}"`);
|
|
632
638
|
clearSubscriptions();
|
|
633
639
|
start();
|
|
634
640
|
}));
|
|
@@ -639,6 +645,47 @@ function realtimeMutableProvider({ socket, userKey, store = IMPLICIT.STORE }) {
|
|
|
639
645
|
};
|
|
640
646
|
}
|
|
641
647
|
|
|
648
|
+
//#endregion
|
|
649
|
+
//#region src/realtime-server/realtime-state-provider.ts
|
|
650
|
+
function isReadableToken(input) {
|
|
651
|
+
return typeof input === `object` && input !== null && `key` in input && `type` in input;
|
|
652
|
+
}
|
|
653
|
+
function realtimeStateProvider({ socket, consumer, store = IMPLICIT.STORE }) {
|
|
654
|
+
store.logger.info(`🔌`, `user`, consumer, `initialized state provider`);
|
|
655
|
+
return function stateProvider(clientToken, serverData = clientToken) {
|
|
656
|
+
const isStatic = !isReadableToken(serverData);
|
|
657
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
658
|
+
const clearSubscriptions = () => {
|
|
659
|
+
for (const unsub of subscriptions) unsub();
|
|
660
|
+
subscriptions.clear();
|
|
661
|
+
};
|
|
662
|
+
const start = () => {
|
|
663
|
+
if (isStatic) store.logger.info(`👀`, `user`, consumer, `will be served`, serverData, `as "${clientToken.key}"`);
|
|
664
|
+
else store.logger.info(`👀`, `user`, consumer, `can subscribe to state "${serverData.key}" as "${clientToken.key}"`);
|
|
665
|
+
subscriptions.add(employSocket(socket, `sub:${clientToken.key}`, () => {
|
|
666
|
+
if (isStatic) {
|
|
667
|
+
store.logger.info(`👀`, `user`, consumer, `requests`, `"${clientToken.key}"`);
|
|
668
|
+
socket.emit(`serve:${clientToken.key}`, serverData);
|
|
669
|
+
} else {
|
|
670
|
+
store.logger.info(`👀`, `user`, consumer, `subscribes to state "${serverData.key}"`, clientToken === serverData ? `directly` : `as "${clientToken.key}"`);
|
|
671
|
+
clearSubscriptions();
|
|
672
|
+
socket.emit(`serve:${clientToken.key}`, getFromStore(store, serverData));
|
|
673
|
+
subscriptions.add(subscribeToState(store, serverData, `expose-single:${socket.id}`, ({ newValue }) => {
|
|
674
|
+
socket.emit(`serve:${clientToken.key}`, newValue);
|
|
675
|
+
}));
|
|
676
|
+
subscriptions.add(employSocket(socket, `unsub:${serverData.key}`, () => {
|
|
677
|
+
store.logger.info(`🙈`, `user`, consumer, `unsubscribes from state "${serverData.key}", served`, clientToken === serverData ? `directly` : `as "${clientToken.key}"`);
|
|
678
|
+
clearSubscriptions();
|
|
679
|
+
start();
|
|
680
|
+
}));
|
|
681
|
+
}
|
|
682
|
+
}));
|
|
683
|
+
};
|
|
684
|
+
start();
|
|
685
|
+
return clearSubscriptions;
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
642
689
|
//#endregion
|
|
643
690
|
//#region src/realtime-server/provide-rooms.ts
|
|
644
691
|
const ROOMS = globalThis.ATOM_IO_REALTIME_SERVER_ROOMS ?? (globalThis.ATOM_IO_REALTIME_SERVER_ROOMS = /* @__PURE__ */ new Map());
|
|
@@ -648,17 +695,17 @@ function spawnRoom({ store, socket, userKey, resolveRoomScript }) {
|
|
|
648
695
|
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} spawns room ${roomName}`);
|
|
649
696
|
const roomKey = `room::${roomMeta.count++}`;
|
|
650
697
|
const [command, args] = resolveRoomScript(roomName);
|
|
651
|
-
const
|
|
652
|
-
const room = spawn(command, args, { env: process.env });
|
|
698
|
+
const room = new ChildSocket(await new Promise((resolve) => {
|
|
699
|
+
const room$1 = spawn(command, args, { env: process.env });
|
|
653
700
|
const resolver = (data) => {
|
|
654
701
|
if (data.toString() === PROOF_OF_LIFE_SIGNAL) {
|
|
655
|
-
room.stdout.off(`data`, resolver);
|
|
656
|
-
resolve(room);
|
|
702
|
+
room$1.stdout.off(`data`, resolver);
|
|
703
|
+
resolve(room$1);
|
|
657
704
|
}
|
|
658
705
|
};
|
|
659
|
-
room.stdout.on(`data`, resolver);
|
|
706
|
+
room$1.stdout.on(`data`, resolver);
|
|
660
707
|
}), roomKey);
|
|
661
|
-
ROOMS.set(roomKey,
|
|
708
|
+
ROOMS.set(roomKey, room);
|
|
662
709
|
setIntoStore(store, roomKeysAtom, (index) => (index.add(roomKey), index));
|
|
663
710
|
editRelationsInStore(store, ownersOfRooms, (relations) => {
|
|
664
711
|
relations.set({
|
|
@@ -666,23 +713,41 @@ function spawnRoom({ store, socket, userKey, resolveRoomScript }) {
|
|
|
666
713
|
user: userKey
|
|
667
714
|
});
|
|
668
715
|
});
|
|
669
|
-
|
|
716
|
+
const provideMutableFamily = realtimeMutableFamilyProvider({
|
|
717
|
+
socket: room,
|
|
718
|
+
consumer: roomKey,
|
|
719
|
+
store
|
|
720
|
+
});
|
|
721
|
+
const unsubFromRoomKey = realtimeStateProvider({
|
|
722
|
+
socket: room,
|
|
723
|
+
consumer: roomKey,
|
|
724
|
+
store
|
|
725
|
+
})(myRoomKeyAtom, roomKey);
|
|
726
|
+
const unsubFromOwnerKeys = provideMutableFamily(getInternalRelationsFromStore(store, ownersOfRooms), [roomKey]);
|
|
727
|
+
const unsubFromUsersInRooms = provideMutableFamily(getInternalRelationsFromStore(store, usersInRooms), findInStore(store, visibilityFromRoomSelector, roomKey));
|
|
728
|
+
room.on(`close`, () => {
|
|
729
|
+
unsubFromRoomKey();
|
|
730
|
+
unsubFromOwnerKeys();
|
|
731
|
+
unsubFromUsersInRooms();
|
|
670
732
|
destroyRoom({
|
|
671
733
|
store,
|
|
672
734
|
socket,
|
|
673
735
|
userKey
|
|
674
736
|
})(roomKey);
|
|
675
737
|
});
|
|
676
|
-
return
|
|
738
|
+
return room;
|
|
677
739
|
};
|
|
678
740
|
}
|
|
679
741
|
function provideEnterAndExit({ store, socket, roomSocket, userKey }) {
|
|
680
742
|
const enterRoom = (roomKey) => {
|
|
681
743
|
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} enters room ${roomKey}`);
|
|
744
|
+
const dcUserFromRoom = () => {
|
|
745
|
+
toRoom([`user-leaves`]);
|
|
746
|
+
};
|
|
682
747
|
const exitRoom = () => {
|
|
683
748
|
store.logger.info(`📡`, `socket`, socket.id ?? `[ID MISSING?!]`, `👤 ${userKey} leaves room ${roomKey}`);
|
|
684
749
|
socket.offAny(forward);
|
|
685
|
-
|
|
750
|
+
dcUserFromRoom();
|
|
686
751
|
editRelationsInStore(store, usersInRooms, (relations) => {
|
|
687
752
|
relations.delete({
|
|
688
753
|
room: roomKey,
|
|
@@ -692,8 +757,6 @@ function provideEnterAndExit({ store, socket, roomSocket, userKey }) {
|
|
|
692
757
|
roomSocket.off(`leaveRoom`, exitRoom);
|
|
693
758
|
roomSocket.on(`joinRoom`, enterRoom);
|
|
694
759
|
};
|
|
695
|
-
roomSocket.on(`leaveRoom`, exitRoom);
|
|
696
|
-
roomSocket.off(`joinRoom`, enterRoom);
|
|
697
760
|
const roomQueue = [];
|
|
698
761
|
const pushToRoomQueue = (payload) => {
|
|
699
762
|
roomQueue.push(payload);
|
|
@@ -712,7 +775,7 @@ function provideEnterAndExit({ store, socket, roomSocket, userKey }) {
|
|
|
712
775
|
const childSocket = ROOMS.get(roomKey);
|
|
713
776
|
if (!childSocket) {
|
|
714
777
|
store.logger.error(`❌`, `unknown`, roomKey, `no room found with this id`);
|
|
715
|
-
return
|
|
778
|
+
return;
|
|
716
779
|
}
|
|
717
780
|
childSocket.onAny((...payload) => {
|
|
718
781
|
socket.emit(...payload);
|
|
@@ -725,6 +788,9 @@ function provideEnterAndExit({ store, socket, roomSocket, userKey }) {
|
|
|
725
788
|
const payload = roomQueue.shift();
|
|
726
789
|
if (payload) toRoom(payload);
|
|
727
790
|
}
|
|
791
|
+
socket.on(`disconnect`, dcUserFromRoom);
|
|
792
|
+
roomSocket.on(`leaveRoom`, exitRoom);
|
|
793
|
+
roomSocket.off(`joinRoom`, enterRoom);
|
|
728
794
|
};
|
|
729
795
|
roomSocket.on(`joinRoom`, enterRoom);
|
|
730
796
|
return enterRoom;
|
|
@@ -754,7 +820,7 @@ function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript, roomN
|
|
|
754
820
|
const unsubFromRoomKeys = realtimeMutableProvider({
|
|
755
821
|
socket,
|
|
756
822
|
store,
|
|
757
|
-
userKey
|
|
823
|
+
consumer: userKey
|
|
758
824
|
})(roomKeysAtom);
|
|
759
825
|
const usersInRoomsAtoms = getInternalRelationsFromStore(store, usersInRooms);
|
|
760
826
|
const [, usersInRoomsAtomsUsersOnly] = getInternalRelationsFromStore(store, usersInRooms, `split`);
|
|
@@ -763,7 +829,7 @@ function provideRooms({ store = IMPLICIT.STORE, socket, resolveRoomScript, roomN
|
|
|
763
829
|
const exposeMutableFamily = realtimeMutableFamilyProvider({
|
|
764
830
|
socket,
|
|
765
831
|
store,
|
|
766
|
-
userKey
|
|
832
|
+
consumer: userKey
|
|
767
833
|
});
|
|
768
834
|
const unsubFromUsersInRooms = exposeMutableFamily(usersInRoomsAtoms, usersWhoseRoomsCanBeSeenSelector);
|
|
769
835
|
const unsubFromOwnersOfRooms = exposeMutableFamily(ownersOfRoomsAtoms, usersWhoseRoomsCanBeSeenSelector);
|
|
@@ -828,8 +894,12 @@ function createRoomSocketGuard(roomNames) {
|
|
|
828
894
|
|
|
829
895
|
//#endregion
|
|
830
896
|
//#region src/realtime-server/realtime-family-provider.ts
|
|
831
|
-
function realtimeAtomFamilyProvider({ socket,
|
|
897
|
+
function realtimeAtomFamilyProvider({ socket, consumer, store = IMPLICIT.STORE }) {
|
|
832
898
|
return function familyProvider(family, index) {
|
|
899
|
+
const [dynamicIndex, staticIndex] = (() => {
|
|
900
|
+
if (typeof index === `object` && `key` in index && `type` in index) return [index, void 0];
|
|
901
|
+
return [void 0, index];
|
|
902
|
+
})();
|
|
833
903
|
const coreSubscriptions = /* @__PURE__ */ new Set();
|
|
834
904
|
const clearCoreSubscriptions = () => {
|
|
835
905
|
for (const unsub of coreSubscriptions) unsub();
|
|
@@ -861,7 +931,7 @@ function realtimeAtomFamilyProvider({ socket, userKey, store = IMPLICIT.STORE })
|
|
|
861
931
|
socket.emit(`serve:${token.key}`, newValue);
|
|
862
932
|
}));
|
|
863
933
|
familyMemberSubscriptions.set(`${token.key}:unsub`, employSocket(socket, `unsub:${token.key}`, () => {
|
|
864
|
-
store.logger.info(`🙈`, `user`,
|
|
934
|
+
store.logger.info(`🙈`, `user`, consumer, `unsubscribed from state "${token.key}"`);
|
|
865
935
|
fillUnsubRequest(token.key);
|
|
866
936
|
}));
|
|
867
937
|
};
|
|
@@ -870,21 +940,24 @@ function realtimeAtomFamilyProvider({ socket, userKey, store = IMPLICIT.STORE })
|
|
|
870
940
|
return false;
|
|
871
941
|
};
|
|
872
942
|
const start = () => {
|
|
873
|
-
store.logger.info(`👀`, `user`,
|
|
943
|
+
store.logger.info(`👀`, `user`, consumer, `can subscribe to family "${family.key}"`);
|
|
874
944
|
coreSubscriptions.add(employSocket(socket, `sub:${family.key}`, (subKey) => {
|
|
875
|
-
|
|
876
|
-
|
|
945
|
+
let exposedSubKeys;
|
|
946
|
+
if (dynamicIndex) exposedSubKeys = getFromStore(store, dynamicIndex);
|
|
947
|
+
else exposedSubKeys = staticIndex;
|
|
948
|
+
if (isAvailable$1(exposedSubKeys, subKey)) {
|
|
949
|
+
store.logger.info(`👀`, `user`, consumer, `is approved for a subscription to`, subKey, `in family "${family.key}"`);
|
|
877
950
|
exposeFamilyMembers(subKey);
|
|
878
951
|
} else {
|
|
879
|
-
store.logger.info(`❌`, `user`,
|
|
952
|
+
store.logger.info(`❌`, `user`, consumer, `is denied for a subscription to`, subKey, `in family "${family.key}"`);
|
|
880
953
|
familyMemberSubscriptionsWanted.add(stringifyJson(subKey));
|
|
881
954
|
socket.emit(`unavailable:${family.key}`, subKey);
|
|
882
955
|
}
|
|
883
956
|
}));
|
|
884
|
-
coreSubscriptions.add(subscribeToState(store,
|
|
885
|
-
store.logger.info(`👀`, `user`,
|
|
957
|
+
if (dynamicIndex) coreSubscriptions.add(subscribeToState(store, dynamicIndex, `expose-family:${family.key}:${socket.id}`, ({ newValue: newExposedSubKeys }) => {
|
|
958
|
+
store.logger.info(`👀`, `user`, consumer, `has the following keys available for family "${family.key}"`, newExposedSubKeys);
|
|
886
959
|
for (const subKey of newExposedSubKeys) if (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {
|
|
887
|
-
store.logger.info(`👀`, `user`,
|
|
960
|
+
store.logger.info(`👀`, `user`, consumer, `is retroactively approved for a subscription to`, subKey, `in family "${family.key}"`);
|
|
888
961
|
exposeFamilyMembers(subKey);
|
|
889
962
|
}
|
|
890
963
|
}));
|
|
@@ -897,50 +970,9 @@ function realtimeAtomFamilyProvider({ socket, userKey, store = IMPLICIT.STORE })
|
|
|
897
970
|
};
|
|
898
971
|
}
|
|
899
972
|
|
|
900
|
-
//#endregion
|
|
901
|
-
//#region src/realtime-server/realtime-state-provider.ts
|
|
902
|
-
function isReadableToken(input) {
|
|
903
|
-
return typeof input === `object` && input !== null && `key` in input && `type` in input;
|
|
904
|
-
}
|
|
905
|
-
function realtimeStateProvider({ socket, userKey, store = IMPLICIT.STORE }) {
|
|
906
|
-
store.logger.info(`🔌`, `user`, userKey, `initialized state provider`);
|
|
907
|
-
return function stateProvider(clientToken, serverData = clientToken) {
|
|
908
|
-
const isStatic = !isReadableToken(serverData);
|
|
909
|
-
const subscriptions = /* @__PURE__ */ new Set();
|
|
910
|
-
const clearSubscriptions = () => {
|
|
911
|
-
for (const unsub of subscriptions) unsub();
|
|
912
|
-
subscriptions.clear();
|
|
913
|
-
};
|
|
914
|
-
const start = () => {
|
|
915
|
-
if (isStatic) store.logger.info(`👀`, `user`, userKey, `will be served`, serverData, `as "${clientToken.key}"`);
|
|
916
|
-
else store.logger.info(`👀`, `user`, userKey, `can subscribe to state "${serverData.key}" as "${clientToken.key}"`);
|
|
917
|
-
subscriptions.add(employSocket(socket, `sub:${clientToken.key}`, () => {
|
|
918
|
-
if (isStatic) {
|
|
919
|
-
store.logger.info(`👀`, `user`, userKey, `requests`, `"${clientToken.key}"`);
|
|
920
|
-
socket.emit(`serve:${clientToken.key}`, serverData);
|
|
921
|
-
} else {
|
|
922
|
-
store.logger.info(`👀`, `user`, userKey, `subscribes to state "${serverData.key}"`, clientToken === serverData ? `directly` : `as "${clientToken.key}"`);
|
|
923
|
-
clearSubscriptions();
|
|
924
|
-
socket.emit(`serve:${clientToken.key}`, getFromStore(store, serverData));
|
|
925
|
-
subscriptions.add(subscribeToState(store, serverData, `expose-single:${socket.id}`, ({ newValue }) => {
|
|
926
|
-
socket.emit(`serve:${clientToken.key}`, newValue);
|
|
927
|
-
}));
|
|
928
|
-
subscriptions.add(employSocket(socket, `unsub:${serverData.key}`, () => {
|
|
929
|
-
store.logger.info(`🙈`, `user`, userKey, `unsubscribes from state "${serverData.key}", served`, clientToken === serverData ? `directly` : `as "${clientToken.key}"`);
|
|
930
|
-
clearSubscriptions();
|
|
931
|
-
start();
|
|
932
|
-
}));
|
|
933
|
-
}
|
|
934
|
-
}));
|
|
935
|
-
};
|
|
936
|
-
start();
|
|
937
|
-
return clearSubscriptions;
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
|
|
941
973
|
//#endregion
|
|
942
974
|
//#region src/realtime-server/realtime-state-receiver.ts
|
|
943
|
-
function realtimeStateReceiver({ socket,
|
|
975
|
+
function realtimeStateReceiver({ socket, consumer, store = IMPLICIT.STORE }) {
|
|
944
976
|
return function stateReceiver(schema, clientToken, serverToken = clientToken) {
|
|
945
977
|
const socketKey = `socket::${socket.id}`;
|
|
946
978
|
const mutexAtom = findInStore(store, mutexAtoms, serverToken.key);
|
|
@@ -954,7 +986,7 @@ function realtimeStateReceiver({ socket, userKey, store = IMPLICIT.STORE }) {
|
|
|
954
986
|
subscriptions.add(employSocket(socket, `pub:${clientToken.key}`, async (newValue) => {
|
|
955
987
|
const parsed = await schema[`~standard`].validate(newValue);
|
|
956
988
|
if (parsed.issues) {
|
|
957
|
-
store.logger.error(`❌`, `user`,
|
|
989
|
+
store.logger.error(`❌`, `user`, consumer, `attempted to publish invalid value`, newValue, `to state "${serverToken.key}"`);
|
|
958
990
|
return;
|
|
959
991
|
}
|
|
960
992
|
setIntoStore(store, serverToken, parsed.value);
|
|
@@ -996,11 +1028,11 @@ const socketAtoms = atomFamily({
|
|
|
996
1028
|
default: null
|
|
997
1029
|
});
|
|
998
1030
|
const socketKeysAtom = mutableAtom({
|
|
999
|
-
key: `
|
|
1031
|
+
key: `socketKeys`,
|
|
1000
1032
|
class: UList
|
|
1001
1033
|
});
|
|
1002
|
-
const
|
|
1003
|
-
key: `
|
|
1034
|
+
const onlineUsersAtom = mutableAtom({
|
|
1035
|
+
key: `onlineUsers`,
|
|
1004
1036
|
class: UList
|
|
1005
1037
|
});
|
|
1006
1038
|
const usersOfSockets = join({
|
|
@@ -1027,29 +1059,26 @@ function realtime(server, auth, onConnect, store = IMPLICIT.STORE) {
|
|
|
1027
1059
|
editRelationsInStore(store, usersOfSockets, (relations) => {
|
|
1028
1060
|
relations.set(userClaim, socketClaim);
|
|
1029
1061
|
});
|
|
1030
|
-
setIntoStore(store,
|
|
1062
|
+
setIntoStore(store, onlineUsersAtom, (index) => index.add(userClaim));
|
|
1031
1063
|
setIntoStore(store, socketKeysAtom, (index) => index.add(socketClaim));
|
|
1032
1064
|
next();
|
|
1033
1065
|
}).on(`connection`, async (socket) => {
|
|
1034
1066
|
const socketKey = `socket::${socket.id}`;
|
|
1035
|
-
const
|
|
1036
|
-
const userKey = getFromStore(store,
|
|
1067
|
+
const userKeySelector = findRelationsInStore(store, usersOfSockets, socketKey).userKeyOfSocket;
|
|
1068
|
+
const userKey = getFromStore(store, userKeySelector);
|
|
1037
1069
|
const serverConfig = {
|
|
1038
1070
|
store,
|
|
1039
1071
|
socket,
|
|
1040
|
-
userKey
|
|
1072
|
+
consumer: userKey
|
|
1041
1073
|
};
|
|
1042
|
-
const unsubFromMyUserKey = realtimeStateProvider(serverConfig)(
|
|
1043
|
-
key: `myUserKey`,
|
|
1044
|
-
type: `atom`
|
|
1045
|
-
}, userKey);
|
|
1074
|
+
const unsubFromMyUserKey = realtimeStateProvider(serverConfig)(myUserKeyAtom, userKey);
|
|
1046
1075
|
const disposeServices = await onConnect(serverConfig);
|
|
1047
1076
|
socket.on(`disconnect`, async () => {
|
|
1048
1077
|
store.logger.info(`📡`, `socket`, socketKey, `👤 ${userKey} disconnects`);
|
|
1049
1078
|
await disposeServices();
|
|
1050
1079
|
unsubFromMyUserKey();
|
|
1051
1080
|
editRelationsInStore(store, usersOfSockets, (rel) => rel.delete(socketKey));
|
|
1052
|
-
setIntoStore(store,
|
|
1081
|
+
setIntoStore(store, onlineUsersAtom, (keys) => (keys.delete(userKey), keys));
|
|
1053
1082
|
setIntoStore(store, socketKeysAtom, (keys) => (keys.delete(socketKey), keys));
|
|
1054
1083
|
});
|
|
1055
1084
|
});
|
|
@@ -1060,5 +1089,5 @@ function realtime(server, auth, onConnect, store = IMPLICIT.STORE) {
|
|
|
1060
1089
|
}
|
|
1061
1090
|
|
|
1062
1091
|
//#endregion
|
|
1063
|
-
export { ChildSocket, CustomSocket, PROOF_OF_LIFE_SIGNAL, ParentSocket, ROOMS, SubjectSocket, destroyRoom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtime, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, socketAtoms, socketKeysAtom, spawnRoom,
|
|
1092
|
+
export { ChildSocket, CustomSocket, PROOF_OF_LIFE_SIGNAL, ParentSocket, ROOMS, SubjectSocket, destroyRoom, onlineUsersAtom, prepareToProvideContinuity, provideEnterAndExit, provideRooms, realtime, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, roomMeta, socketAtoms, socketKeysAtom, spawnRoom, usersOfSockets };
|
|
1064
1093
|
//# sourceMappingURL=index.js.map
|