@openpeepshq/core 0.6.1 → 0.7.0

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.
@@ -3,6 +3,7 @@ export declare const jamStateCache: import("cache-manager").Cache;
3
3
  export declare const getJamState: (jam: PostWithMeta, recurrenceId?: string) => Promise<{
4
4
  active: boolean;
5
5
  participants: string[];
6
+ observers?: number | undefined;
6
7
  }>;
7
8
  /** Caches the LiveKit scan for live jam posts (before auth filtering). */
8
9
  export declare const LIVE_JAMS_CACHE_KEY = "live-jams";
@@ -18,6 +18,7 @@ export declare const listAttendance: (jamId: string, { start, limit }?: {
18
18
  export declare const findJamState: (jam: PostWithMeta, hideParticipants?: boolean, recurrenceId?: string) => Promise<{
19
19
  participants: string[];
20
20
  active: boolean;
21
+ observers?: number | undefined;
21
22
  }>;
22
23
  export declare const findJamRecording: (recordingId: string) => Promise<import("@openpeepshq/common").JamRecordingWithMeta | undefined>;
23
24
  export declare const findActiveRecording: (jamPost: PostWithMeta) => Promise<import("@openpeepshq/common").JamRecordingWithMeta | undefined>;
@@ -13,6 +13,16 @@ export declare const JAM_ROOM_DEPARTURE_TIMEOUT_SEC = 60;
13
13
  */
14
14
  export declare const shouldReclaimJamRoom: (numParticipants: number, humanCount: number) => boolean;
15
15
  export declare const roomService: () => Promise<RoomServiceClient | undefined>;
16
+ export declare const isEgressIdentity: (identity: string) => boolean;
17
+ /**
18
+ * Split LiveKit participant identities into humans and hidden external
19
+ * sessions (observer links, recording/RTMP web egress), which share the
20
+ * `EG_` identity prefix minted by `createJamEgressToken()`.
21
+ */
22
+ export declare const splitJamParticipants: (identities: string[]) => {
23
+ humans: string[];
24
+ observers: number;
25
+ };
16
26
  export declare const listParticipantIds: (jamId: string) => Promise<string[]>;
17
27
  /**
18
28
  * Relative path for the observer view (full jam UI). Used for human
@@ -35,6 +35,34 @@ export const roomService = async () => {
35
35
  }
36
36
  return new RoomServiceClient(url, apiKey, apiSecret);
37
37
  };
38
+ /** Egress identities are minted only by createJamEgressToken(). */
39
+ const EGRESS_IDENTITY_PREFIX = 'EG_';
40
+ export const isEgressIdentity = (identity) => identity.startsWith(EGRESS_IDENTITY_PREFIX);
41
+ /**
42
+ * Split LiveKit participant identities into humans and hidden external
43
+ * sessions (observer links, recording/RTMP web egress), which share the
44
+ * `EG_` identity prefix minted by `createJamEgressToken()`.
45
+ */
46
+ export const splitJamParticipants = (identities) => {
47
+ const humans = [];
48
+ let observers = 0;
49
+ for (const identity of identities) {
50
+ if (isEgressIdentity(identity)) {
51
+ observers += 1;
52
+ }
53
+ else {
54
+ humans.push(identity);
55
+ }
56
+ }
57
+ return { humans, observers };
58
+ };
59
+ const listParticipantIdentities = async (jamId) => {
60
+ const rs = await roomService();
61
+ if (rs === undefined) {
62
+ return [];
63
+ }
64
+ return (await rs.listParticipants(jamId)).map((p) => p.identity);
65
+ };
38
66
  export const listParticipantIds = async (jamId) => {
39
67
  const rs = await roomService();
40
68
  if (rs === undefined) {
@@ -42,7 +70,7 @@ export const listParticipantIds = async (jamId) => {
42
70
  }
43
71
  return (await rs.listParticipants(jamId))
44
72
  .map((p) => p.identity)
45
- .filter((identity) => !identity.startsWith('EG_'));
73
+ .filter((identity) => !isEgressIdentity(identity));
46
74
  };
47
75
  const getJamEgressToken = async (jamId) => createSignedServiceToken({
48
76
  scopes: [
@@ -283,7 +311,7 @@ export const finishRecording = async (jamRecording) => {
283
311
  await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
284
312
  };
285
313
  export const jamState = async (jam, hideParticipants, recurrenceId) => {
286
- const inactive = { participants: [], active: false };
314
+ const inactive = { participants: [], active: false, observers: 0 };
287
315
  const rs = await roomService();
288
316
  const roomName = jamRoomName(jam.id, recurrenceId);
289
317
  if (rs === undefined) {
@@ -302,14 +330,16 @@ export const jamState = async (jam, hideParticipants, recurrenceId) => {
302
330
  if (!room.numParticipants) {
303
331
  return inactive;
304
332
  }
305
- const participants = await listParticipantIds(roomName);
306
- if (shouldReclaimJamRoom(room.numParticipants, participants.length)) {
333
+ const identities = await listParticipantIdentities(roomName);
334
+ const { humans, observers } = splitJamParticipants(identities);
335
+ if (shouldReclaimJamRoom(room.numParticipants, humans.length)) {
307
336
  void reclaimOrphanJamRoom(jam, roomName);
308
337
  return inactive;
309
338
  }
310
339
  return {
311
- participants: hideParticipants ? [] : participants,
340
+ participants: hideParticipants ? [] : humans,
312
341
  active: true,
342
+ observers,
313
343
  };
314
344
  }
315
345
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -37,10 +37,10 @@
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "@openpeepshq/common": "0.8.0",
41
- "@openpeepshq/fetch-client": "^0.2.1",
42
- "@openpeepshq/i18n": "^0.9.1",
43
- "@openpeepshq/geocoder": "^0.1.2"
40
+ "@openpeepshq/common": "0.9.0",
41
+ "@openpeepshq/geocoder": "^0.1.2",
42
+ "@openpeepshq/i18n": "^0.10.0",
43
+ "@openpeepshq/fetch-client": "^0.2.1"
44
44
  },
45
45
  "main": "dist/index.js",
46
46
  "types": "dist/index.d.ts",