@openpeepshq/core 0.1.31 → 0.1.33

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.
Files changed (167) hide show
  1. package/dist/accessTokens/helpers.d.ts +2 -2
  2. package/dist/accessTokens/tokens.js +14 -7
  3. package/dist/accounts/mutations.d.ts +2 -2
  4. package/dist/analytics/cache.js +12 -7
  5. package/dist/analytics/clicks.d.ts +20 -0
  6. package/dist/analytics/clicks.js +194 -0
  7. package/dist/analytics/index.d.ts +1 -0
  8. package/dist/analytics/index.js +1 -0
  9. package/dist/analytics/metrics.d.ts +1 -0
  10. package/dist/analytics/metrics.js +5 -0
  11. package/dist/analytics/pdfReport.d.ts +1 -0
  12. package/dist/analytics/pdfReport.js +7 -5
  13. package/dist/analytics/privacy.d.ts +18 -0
  14. package/dist/analytics/privacy.js +10 -0
  15. package/dist/analytics/read.js +74 -16
  16. package/dist/analytics/report.d.ts +32 -1
  17. package/dist/analytics/report.js +9 -2
  18. package/dist/backups/index.js +13 -5
  19. package/dist/backups/metadata.d.ts +7 -0
  20. package/dist/config/defaults/community.js +0 -6
  21. package/dist/config/defaults/core.js +1 -0
  22. package/dist/config/defaults/db.d.ts +0 -2
  23. package/dist/config/defaults/db.js +0 -2
  24. package/dist/config/index.d.ts +20 -9
  25. package/dist/db/helpers.d.ts +6 -28
  26. package/dist/db/helpers.js +19 -149
  27. package/dist/db/index.d.ts +2 -0
  28. package/dist/db/index.js +4 -0
  29. package/dist/db/init.js +3 -2
  30. package/dist/db/migration/detect.d.ts +0 -3
  31. package/dist/db/migration/detect.js +0 -54
  32. package/dist/db/migration/importCollections.d.ts +1 -1
  33. package/dist/db/migration/importCollections.js +22 -6
  34. package/dist/db/migration/shared.d.ts +0 -4
  35. package/dist/db/migration/shared.js +0 -7
  36. package/dist/db/migration/transform.d.ts +2 -0
  37. package/dist/db/migration/transform.js +23 -0
  38. package/dist/db/pg/client.js +4 -0
  39. package/dist/db/pg/filters/edges.d.ts +1 -1
  40. package/dist/db/pg/filters/edges.js +1 -1
  41. package/dist/db/pg/filters/posts.d.ts +1 -0
  42. package/dist/db/pg/filters/posts.js +11 -1
  43. package/dist/db/pg/map/filters.js +5 -0
  44. package/dist/db/pg/map/relations.d.ts +1 -1
  45. package/dist/db/pg/map/relations.js +89 -41
  46. package/dist/db/pg/migrate.d.ts +23 -0
  47. package/dist/db/pg/migrate.js +87 -1
  48. package/dist/db/pg/queries/derived.d.ts +5 -0
  49. package/dist/db/pg/queries/derived.js +21 -0
  50. package/dist/db/pg/schema/analytics.d.ts +76 -0
  51. package/dist/db/pg/schema/analytics.js +11 -1
  52. package/dist/db/pg/schema/documents.d.ts +143 -0
  53. package/dist/db/pg/schema/documents.js +22 -1
  54. package/dist/db/pg/schema/edges.d.ts +1 -0
  55. package/dist/db/pg/schema/edges.js +1 -0
  56. package/dist/db/pg/schema/index.d.ts +218 -0
  57. package/dist/db/pg/sql/0005_open_power_man.sql +9 -0
  58. package/dist/db/pg/sql/0006_fine_trish_tilby.sql +8 -0
  59. package/dist/db/pg/sql/0007_shallow_oracle.sql +3 -0
  60. package/dist/db/pg/sql/0008_group_owner_roles.sql +31 -0
  61. package/dist/db/pg/sql/0009_event_occurrences.sql +26 -0
  62. package/dist/db/pg/sql/meta/0004_snapshot.json +1 -1
  63. package/dist/db/pg/sql/meta/0005_snapshot.json +4179 -0
  64. package/dist/db/pg/sql/meta/0006_snapshot.json +4200 -0
  65. package/dist/db/pg/sql/meta/0007_snapshot.json +4179 -0
  66. package/dist/db/pg/sql/meta/0009_snapshot.json +4299 -0
  67. package/dist/db/pg/sql/meta/_journal.json +35 -0
  68. package/dist/db/replaceOrigin.d.ts +11 -0
  69. package/dist/db/replaceOrigin.js +116 -0
  70. package/dist/db/types.d.ts +0 -4
  71. package/dist/events/index.d.ts +2 -1
  72. package/dist/events/index.js +54 -33
  73. package/dist/groups/finders.d.ts +2 -2
  74. package/dist/groups/helpers.d.ts +6 -6
  75. package/dist/groups/mapping.d.ts +4 -4
  76. package/dist/groups/mapping.js +2 -2
  77. package/dist/groups/mutations.js +1 -1
  78. package/dist/inviteLinks/helpers.d.ts +4 -4
  79. package/dist/jams/cache.d.ts +1 -1
  80. package/dist/jams/cache.js +2 -1
  81. package/dist/jams/finders.d.ts +2 -1
  82. package/dist/jams/finders.js +18 -7
  83. package/dist/jams/helpers.d.ts +8 -4
  84. package/dist/jams/index.d.ts +4 -3
  85. package/dist/jams/index.js +23 -12
  86. package/dist/jams/livekit.d.ts +46 -8
  87. package/dist/jams/livekit.js +103 -21
  88. package/dist/jams/mapping.d.ts +14 -4
  89. package/dist/jams/mutations.d.ts +2 -0
  90. package/dist/jams/rtmp.d.ts +5 -0
  91. package/dist/jams/rtmp.js +8 -0
  92. package/dist/jams/token.d.ts +3 -3
  93. package/dist/jams/token.js +15 -12
  94. package/dist/jams/waitingRoom.d.ts +6 -4
  95. package/dist/jams/waitingRoom.js +33 -24
  96. package/dist/migration/index.d.ts +4 -0
  97. package/dist/migration/index.js +4 -0
  98. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +3 -1
  99. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +3 -1
  100. package/dist/notifications/helpers.js +6 -2
  101. package/dist/notifications/jobs.js +13 -2
  102. package/dist/notifications/push.js +11 -4
  103. package/dist/plugins/helpers.d.ts +6 -2
  104. package/dist/plugins/helpers.js +22 -10
  105. package/dist/plugins/index.d.ts +6 -1
  106. package/dist/plugins/index.js +54 -13
  107. package/dist/plugins/install.d.ts +20 -0
  108. package/dist/plugins/install.js +223 -0
  109. package/dist/plugins/state.d.ts +4 -0
  110. package/dist/plugins/state.js +29 -0
  111. package/dist/posts/contextClosure.d.ts +2 -1
  112. package/dist/posts/contextClosure.js +6 -1
  113. package/dist/posts/conversationQueries.d.ts +23 -0
  114. package/dist/posts/conversationQueries.js +135 -0
  115. package/dist/posts/eventAgenda.d.ts +165 -0
  116. package/dist/posts/eventAgenda.js +120 -0
  117. package/dist/posts/eventOccurrenceJobs.d.ts +4 -0
  118. package/dist/posts/eventOccurrenceJobs.js +23 -0
  119. package/dist/posts/eventOccurrences.d.ts +4 -0
  120. package/dist/posts/eventOccurrences.js +40 -0
  121. package/dist/posts/finders.d.ts +39 -13
  122. package/dist/posts/finders.js +51 -66
  123. package/dist/posts/helpers/filters.js +1 -1
  124. package/dist/posts/helpers/index.d.ts +120 -34
  125. package/dist/posts/helpers/index.js +34 -21
  126. package/dist/posts/index.d.ts +4 -0
  127. package/dist/posts/index.js +4 -0
  128. package/dist/posts/mapping.d.ts +454 -0
  129. package/dist/posts/mapping.js +43 -9
  130. package/dist/posts/mutations.d.ts +4 -2
  131. package/dist/posts/mutations.js +49 -16
  132. package/dist/posts/rsvpConfirmationEmail.js +2 -1
  133. package/dist/posts/unseenCounts.d.ts +12 -0
  134. package/dist/posts/unseenCounts.js +98 -0
  135. package/dist/profiles/cache.d.ts +5 -1
  136. package/dist/profiles/cache.js +27 -1
  137. package/dist/profiles/helpers.d.ts +5 -5
  138. package/dist/profiles/index.d.ts +1 -0
  139. package/dist/profiles/index.js +1 -0
  140. package/dist/profiles/mapping.d.ts +45 -4
  141. package/dist/profiles/mapping.js +24 -0
  142. package/dist/profiles/mutations.js +12 -14
  143. package/dist/pushSubscriptions/helpers.d.ts +2 -2
  144. package/dist/pushSubscriptions/mutations.js +13 -1
  145. package/dist/reports/helpers.d.ts +6 -6
  146. package/dist/reports/helpers.js +2 -1
  147. package/dist/reports/mapping.js +6 -2
  148. package/dist/roles/defaults.js +1 -0
  149. package/dist/roles/mutations.d.ts +3 -3
  150. package/dist/roles/mutations.js +5 -3
  151. package/dist/server/index.d.ts +15 -7
  152. package/dist/server/index.js +15 -8
  153. package/dist/session/index.d.ts +28 -0
  154. package/dist/session/index.js +79 -0
  155. package/dist/stats/finders.d.ts +1912 -362
  156. package/dist/stats/mapping.d.ts +26 -5
  157. package/package.json +7 -12
  158. package/dist/db/arango.d.ts +0 -2
  159. package/dist/db/arango.js +0 -110
  160. package/dist/db/migration/autoMigrate.d.ts +0 -2
  161. package/dist/db/migration/autoMigrate.js +0 -111
  162. package/dist/db/migration/cli.d.ts +0 -1
  163. package/dist/db/migration/cli.js +0 -56
  164. package/dist/db/migration/exportArango.d.ts +0 -4
  165. package/dist/db/migration/exportArango.js +0 -80
  166. package/dist/db/replaceHostname.d.ts +0 -1
  167. package/dist/db/replaceHostname.js +0 -88
@@ -1,13 +1,16 @@
1
- import { listParticipantIds, reclaimOrphanJamRoom, roomService, stopRecording, } from './livekit.js';
1
+ import { jamRoomName, postIdFromJamRoomName, uniquePostsById, } from '@openpeepshq/common/lib';
2
+ import { listParticipantIds, reclaimOrphanJamRoom, roomService, stopRecording, stopRtmpStream, } from './livekit.js';
2
3
  import { jamStateCache, LIVE_JAMS_CACHE_KEY, liveJamPostsCache } from './cache.js';
3
4
  import { localInstanceDomain, parseRoomInstanceDomain } from './helpers.js';
4
5
  import { findPost } from '../posts/index.js';
5
6
  import { createJamEvent } from './mutations.js';
7
+ import { clearJamAdmittance } from './waitingRoom.js';
6
8
  import { uuidv7 } from 'uuidv7';
7
9
  import { canReadPost } from '../posts/helpers/index.js';
8
10
  import { capabilitiesConfig } from '../config/index.js';
9
11
  export { createJamToken, createJamEgressToken } from './token.js';
10
- export { startRecording, stopRecording, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit.js';
12
+ export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit.js';
13
+ export { rtmpStreamOutput } from './rtmp.js';
11
14
  export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs.js';
12
15
  export * from './waitingRoom.js';
13
16
  export * from './mutations.js';
@@ -43,9 +46,10 @@ const fetchLiveJamPosts = async () => {
43
46
  if (localDomain && roomDomain && roomDomain !== localDomain) {
44
47
  return undefined;
45
48
  }
49
+ const postId = postIdFromJamRoomName(room.name);
46
50
  // Fast path: Room.numParticipants includes hidden egress — 0 means truly empty.
47
51
  if (!room.numParticipants) {
48
- const post = await findPost(room.name);
52
+ const post = await findPost(postId);
49
53
  if (post) {
50
54
  reclaimLocalOrphan(post);
51
55
  }
@@ -58,7 +62,7 @@ const fetchLiveJamPosts = async () => {
58
62
  // egress-only ghosts from real live jams.
59
63
  const humans = await listParticipantIds(room.name);
60
64
  if (humans.length === 0) {
61
- const post = await findPost(room.name);
65
+ const post = await findPost(postId);
62
66
  if (post) {
63
67
  reclaimLocalOrphan(post);
64
68
  }
@@ -67,9 +71,9 @@ const fetchLiveJamPosts = async () => {
67
71
  }
68
72
  return undefined;
69
73
  }
70
- return findPost(room.name);
74
+ return findPost(postId);
71
75
  }));
72
- return posts.filter(Boolean);
76
+ return uniquePostsById(posts);
73
77
  };
74
78
  export const listLiveJams = async (authData) => {
75
79
  const [posts, config] = await Promise.all([
@@ -79,28 +83,35 @@ export const listLiveJams = async (authData) => {
79
83
  return posts.filter(canReadPost(config, authData));
80
84
  };
81
85
  export const findJamEvent = async (id) => findPost(id).then((post) => { var _a, _b; return ((_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = post.data) === null || _b === void 0 ? void 0 : _b.jam) ? post : undefined; });
82
- export const closeJam = async (profile, jamEvent) => {
86
+ export const closeJam = async (profile, jamEvent, recurrenceId) => {
83
87
  const rs = await roomService();
84
88
  if (rs === undefined) {
85
89
  return undefined;
86
90
  }
87
- await stopRecording(jamEvent);
88
- return rs.deleteRoom(jamEvent.id).then(async () => {
89
- await invalidateJamCaches(jamEvent.id);
91
+ await stopRecording(jamEvent, recurrenceId);
92
+ await stopRtmpStream(jamEvent);
93
+ return rs
94
+ .deleteRoom(jamRoomName(jamEvent.id, recurrenceId))
95
+ .then(async () => {
96
+ await Promise.all([
97
+ invalidateJamCaches(jamRoomName(jamEvent.id, recurrenceId)),
98
+ clearJamAdmittance(jamEvent, recurrenceId).catch(() => undefined),
99
+ ]);
90
100
  return createJamEvent({
91
101
  id: uuidv7(),
92
102
  jamId: jamEvent.id,
93
103
  type: 'close',
94
104
  profileId: profile.id,
105
+ recurrenceId,
95
106
  });
96
107
  });
97
108
  };
98
- export const muteParticipant = async (jamId, data) => {
109
+ export const muteParticipant = async (jamId, data, recurrenceId) => {
99
110
  const rs = await roomService();
100
111
  if (rs === undefined) {
101
112
  return { success: false };
102
113
  }
103
- const result = await rs.mutePublishedTrack(jamId, data.identity, data.trackSid, true);
114
+ const result = await rs.mutePublishedTrack(jamRoomName(jamId, recurrenceId), data.identity, data.trackSid, true);
104
115
  if (!result) {
105
116
  return { success: false };
106
117
  }
@@ -7,18 +7,56 @@ export declare const JAM_ROOM_DEPARTURE_TIMEOUT_SEC = 60;
7
7
  export declare const roomService: () => Promise<RoomServiceClient | undefined>;
8
8
  export declare const listParticipantIds: (jamId: string) => Promise<string[]>;
9
9
  /**
10
- * Relative path for the observer view (full jam UI). Used both for human
11
- * moderator observer links and as the page LiveKit web egress records.
10
+ * Relative path for the observer view (full jam UI). Used for human
11
+ * moderator observer links, jam recording web egress, and RTMP web egress.
12
12
  */
13
- export declare const getJamObserverPath: (jamId: string) => Promise<string>;
14
- export declare const getJamRecordingUrl: (jamId: string) => Promise<string>;
15
- export declare const startRecording: (profile: ProfileWithMeta, jamPost: PostWithMeta) => Promise<JamRecording>;
13
+ export declare const getJamObserverPath: (jamId: string, recurrenceId?: string) => Promise<string>;
14
+ export declare const getJamRecordingUrl: (jamId: string, recurrenceId?: string) => Promise<string>;
15
+ export declare const startRecording: (profile: ProfileWithMeta, jamPost: PostWithMeta, recurrenceId?: string) => Promise<JamRecording>;
16
+ export declare const startRtmpStream: (profile: ProfileWithMeta, jamPost: PostWithMeta, rtmpUrl: string, destinationHost?: string) => Promise<JamRecording>;
17
+ export declare const stopRtmpStream: (jamPost: PostWithMeta) => Promise<{
18
+ status: "completed";
19
+ createdAt: string;
20
+ updatedAt: string;
21
+ deletedAt?: string | null | undefined;
22
+ kind?: "file" | "rtmp" | undefined;
23
+ destinationHost?: string | undefined;
24
+ egressId?: string | undefined;
25
+ attachment?: {
26
+ type: string;
27
+ url: string;
28
+ previewUrl: string | null;
29
+ textUrl: null;
30
+ filename: string;
31
+ meta: {
32
+ usage?: string | undefined;
33
+ focus?: {
34
+ x: number;
35
+ y: number;
36
+ } | undefined;
37
+ mimetype?: string | undefined;
38
+ size?: number | undefined;
39
+ };
40
+ id: string;
41
+ createdAt: string;
42
+ updatedAt: string;
43
+ description?: string | undefined;
44
+ blurhash?: string | undefined;
45
+ status?: "failed" | "processing" | "ready" | undefined;
46
+ error?: string | undefined;
47
+ deletedAt?: string | null | undefined;
48
+ } | undefined;
49
+ replyPostId?: string | undefined;
50
+ id: string;
51
+ profile: ProfileWithMeta;
52
+ post: PostWithMeta;
53
+ } | undefined>;
16
54
  export declare const stopEgress: (egressId: string) => Promise<void>;
17
- export declare const stopRecording: (jamPost: PostWithMeta) => Promise<JamRecordingWithMeta | undefined>;
55
+ export declare const stopRecording: (jamPost: PostWithMeta, recurrenceId?: string) => Promise<JamRecordingWithMeta | undefined>;
18
56
  /**
19
57
  * Stops leftover egress and deletes a LiveKit room that has no human
20
58
  * participants (egress-only / orphan rooms). Safe to call repeatedly.
21
59
  */
22
- export declare const reclaimOrphanJamRoom: (jam: PostWithMeta) => Promise<void>;
60
+ export declare const reclaimOrphanJamRoom: (jam: PostWithMeta, roomName?: string) => Promise<void>;
23
61
  export declare const finishRecording: (jamRecording: JamRecordingWithMeta) => Promise<void>;
24
- export declare const jamState: (jam: PostWithMeta, hideParticipants?: boolean) => Promise<JamState>;
62
+ export declare const jamState: (jam: PostWithMeta, hideParticipants?: boolean, recurrenceId?: string) => Promise<JamState>;
@@ -1,3 +1,4 @@
1
+ import { jamRoomName } from '@openpeepshq/common/lib';
1
2
  import { config } from '../config/index.js';
2
3
  import { DataPacket_Kind, EgressClient, EncodedFileOutput, EncodedFileType, EncodingOptionsPreset, RoomServiceClient, } from 'livekit-server-sdk';
3
4
  import { connectRecording } from './helpers.js';
@@ -5,12 +6,13 @@ import { allpeepDb } from '../db/index.js';
5
6
  import { serverRootUrl } from '../server/index.js';
6
7
  import { uuidv7 } from 'uuidv7';
7
8
  import { createJamEvent, updateJamRecording } from './mutations.js';
8
- import { findActiveRecording } from './finders.js';
9
+ import { findActiveRecording, findActiveRtmpStream } from './finders.js';
9
10
  import { cancelRecordingAutoStop, scheduleRecordingAutoStop } from './jobs.js';
10
11
  import { jamRecordingUploadSecret } from './recordingUploadAuth.js';
11
12
  import { createSignedServiceToken } from '../accessTokens/tokens.js';
12
13
  import { unprocessableRequest } from '../errors/index.js';
13
14
  import { logger } from '../log/index.js';
15
+ import { rtmpStreamOutput, rtmpWebEgressOptions } from './rtmp.js';
14
16
  const encoder = new TextEncoder();
15
17
  const log = logger('app:jams:livekit');
16
18
  /** Seconds a new room stays open before anyone joins. */
@@ -36,7 +38,7 @@ export const listParticipantIds = async (jamId) => {
36
38
  const getJamEgressToken = async (jamId) => createSignedServiceToken({
37
39
  scopes: [
38
40
  {
39
- resource: { type: 'jam', id: jamId },
41
+ resource: { type: 'jams', id: jamId },
40
42
  },
41
43
  ],
42
44
  name: 'jam-egress',
@@ -61,20 +63,24 @@ const assertEgressCanReachRecordingHost = async (recordingUrl) => {
61
63
  }
62
64
  };
63
65
  /**
64
- * Relative path for the observer view (full jam UI). Used both for human
65
- * moderator observer links and as the page LiveKit web egress records.
66
+ * Relative path for the observer view (full jam UI). Used for human
67
+ * moderator observer links, jam recording web egress, and RTMP web egress.
66
68
  */
67
- export const getJamObserverPath = async (jamId) => {
69
+ export const getJamObserverPath = async (jamId, recurrenceId) => {
68
70
  const jamEgressToken = await getJamEgressToken(jamId);
69
- return `/events/${jamId}/jam?observer=true&token=${jamEgressToken}`;
71
+ const occurrence = recurrenceId
72
+ ? `&occurrence=${encodeURIComponent(recurrenceId)}`
73
+ : '';
74
+ return `/events/${jamId}/jam?observer=true&token=${jamEgressToken}${occurrence}`;
70
75
  };
71
- export const getJamRecordingUrl = async (jamId) => `${await serverRootUrl()}${await getJamObserverPath(jamId)}`;
76
+ export const getJamRecordingUrl = async (jamId, recurrenceId) => `${await serverRootUrl()}${await getJamObserverPath(jamId, recurrenceId)}`;
72
77
  const getEgressClient = async () => {
73
78
  const { url, apiKey, apiSecret } = (await config()).jams.livekit;
74
79
  return new EgressClient(url, apiKey, apiSecret);
75
80
  };
76
- export const startRecording = async (profile, jamPost) => {
81
+ export const startRecording = async (profile, jamPost, recurrenceId) => {
77
82
  const jamId = jamPost.id;
83
+ const roomName = jamRoomName(jamPost.id, recurrenceId);
78
84
  const recordingId = uuidv7();
79
85
  // Clear any recording left `active` by a previous failed egress so the new
80
86
  // one is the sole active recording for this jam.
@@ -91,7 +97,7 @@ export const startRecording = async (profile, jamPost) => {
91
97
  const persistedRecordingId = recording.id;
92
98
  const egressClient = await getEgressClient();
93
99
  const outputFilename = `${persistedRecordingId}.mp4`;
94
- const recordingUrl = await getJamRecordingUrl(jamId);
100
+ const recordingUrl = await getJamRecordingUrl(jamId, recurrenceId);
95
101
  await assertEgressCanReachRecordingHost(recordingUrl);
96
102
  const uploadSecret = await jamRecordingUploadSecret(persistedRecordingId);
97
103
  const egressInfo = await egressClient.startWebEgress(recordingUrl, new EncodedFileOutput({
@@ -120,12 +126,80 @@ export const startRecording = async (profile, jamPost) => {
120
126
  jamId,
121
127
  type: 'recordStart',
122
128
  profileId: profile.id,
129
+ recurrenceId,
123
130
  });
124
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
131
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(roomName, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
125
132
  // BullMQ delayed job survives API/worker restarts (unlike setTimeout).
126
133
  await scheduleRecordingAutoStop(jamId, persistedRecordingId);
127
134
  return recording;
128
135
  };
136
+ const assertLivekitConfigured = async () => {
137
+ const { url, apiKey, apiSecret } = (await config()).jams.livekit;
138
+ if (!url || !apiKey || !apiSecret) {
139
+ throw unprocessableRequest({ errorKey: 'error.jamsUnavailable' });
140
+ }
141
+ };
142
+ const assertJamRoomOpen = async (jamId) => {
143
+ const rs = await roomService();
144
+ if (rs === undefined) {
145
+ throw unprocessableRequest({ errorKey: 'error.jamsUnavailable' });
146
+ }
147
+ const rooms = await rs.listRooms([jamId]);
148
+ if (rooms.length !== 1) {
149
+ throw unprocessableRequest({ errorKey: 'error.jamNotOpen' });
150
+ }
151
+ };
152
+ const emitJamEvent = async (jamId, jamEvent) => {
153
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
154
+ };
155
+ export const startRtmpStream = async (profile, jamPost, rtmpUrl, destinationHost) => {
156
+ await assertLivekitConfigured();
157
+ await assertJamRoomOpen(jamPost.id);
158
+ await stopRtmpStream(jamPost);
159
+ const jamId = jamPost.id;
160
+ const recordingId = uuidv7();
161
+ let recording = (await allpeepDb().then(({ db }) => connectRecording(db, profile, jamPost, {
162
+ id: recordingId,
163
+ status: 'requested',
164
+ kind: 'rtmp',
165
+ destinationHost,
166
+ })));
167
+ const persistedRecordingId = recording.id;
168
+ const observerUrl = await getJamRecordingUrl(jamId);
169
+ await assertEgressCanReachRecordingHost(observerUrl);
170
+ const egressClient = await getEgressClient();
171
+ const egressInfo = await egressClient.startWebEgress(observerUrl, rtmpStreamOutput(rtmpUrl), rtmpWebEgressOptions);
172
+ recording = (await updateJamRecording(persistedRecordingId, {
173
+ egressId: egressInfo.egressId,
174
+ status: 'active',
175
+ }));
176
+ const jamEvent = await createJamEvent({
177
+ id: uuidv7(),
178
+ jamId,
179
+ type: 'streamStart',
180
+ profileId: profile.id,
181
+ });
182
+ await emitJamEvent(jamId, jamEvent);
183
+ return recording;
184
+ };
185
+ export const stopRtmpStream = async (jamPost) => {
186
+ const stream = await findActiveRtmpStream(jamPost);
187
+ if (!stream) {
188
+ return undefined;
189
+ }
190
+ if (stream.egressId) {
191
+ void stopEgress(stream.egressId);
192
+ }
193
+ await updateJamRecording(stream.id, { status: 'completed' });
194
+ const jamEvent = await createJamEvent({
195
+ id: uuidv7(),
196
+ jamId: jamPost.id,
197
+ type: 'streamStop',
198
+ profileId: stream.profile.id,
199
+ });
200
+ await emitJamEvent(jamPost.id, jamEvent);
201
+ return Object.assign(Object.assign({}, stream), { status: 'completed' });
202
+ };
129
203
  export const stopEgress = async (egressId) => {
130
204
  const egressClient = await getEgressClient();
131
205
  try {
@@ -136,7 +210,7 @@ export const stopEgress = async (egressId) => {
136
210
  // stop action should not fail because of that.
137
211
  }
138
212
  };
139
- export const stopRecording = async (jamPost) => {
213
+ export const stopRecording = async (jamPost, recurrenceId) => {
140
214
  const jamRecording = await findActiveRecording(jamPost);
141
215
  if (!jamRecording) {
142
216
  return undefined;
@@ -154,27 +228,34 @@ export const stopRecording = async (jamPost) => {
154
228
  jamId: jamPost.id,
155
229
  type: 'recordStop',
156
230
  profileId: jamRecording.profile.id,
231
+ recurrenceId,
157
232
  });
158
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamPost.id, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
233
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRoomName(jamPost.id, recurrenceId), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
159
234
  return jamRecording;
160
235
  };
161
236
  /**
162
237
  * Stops leftover egress and deletes a LiveKit room that has no human
163
238
  * participants (egress-only / orphan rooms). Safe to call repeatedly.
164
239
  */
165
- export const reclaimOrphanJamRoom = async (jam) => {
240
+ export const reclaimOrphanJamRoom = async (jam, roomName = jam.id) => {
166
241
  try {
167
242
  await stopRecording(jam);
168
243
  }
169
244
  catch (e) {
170
245
  log.warn(`Failed to stop recording while reclaiming jam ${jam.id}: ${e.message}`);
171
246
  }
247
+ try {
248
+ await stopRtmpStream(jam);
249
+ }
250
+ catch (e) {
251
+ log.warn(`Failed to stop RTMP stream while reclaiming jam ${jam.id}: ${e.message}`);
252
+ }
172
253
  try {
173
254
  const rs = await roomService();
174
- await (rs === null || rs === void 0 ? void 0 : rs.deleteRoom(jam.id));
255
+ await (rs === null || rs === void 0 ? void 0 : rs.deleteRoom(roomName));
175
256
  }
176
257
  catch (e) {
177
- log.warn(`Failed to delete orphan jam room ${jam.id}: ${e.message}`);
258
+ log.warn(`Failed to delete orphan jam room ${roomName}: ${e.message}`);
178
259
  }
179
260
  };
180
261
  export const finishRecording = async (jamRecording) => {
@@ -184,10 +265,11 @@ export const finishRecording = async (jamRecording) => {
184
265
  type: 'recordStop',
185
266
  profileId: jamRecording.profile.id,
186
267
  });
187
- await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRecording.post.id, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
268
+ await roomService().then(async (rs) => rs === null || rs === void 0 ? void 0 : rs.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
188
269
  };
189
- export const jamState = async (jam, hideParticipants) => {
270
+ export const jamState = async (jam, hideParticipants, recurrenceId) => {
190
271
  const rs = await roomService();
272
+ const roomName = jamRoomName(jam.id, recurrenceId);
191
273
  if (rs === undefined) {
192
274
  return {
193
275
  participants: [],
@@ -195,19 +277,19 @@ export const jamState = async (jam, hideParticipants) => {
195
277
  };
196
278
  }
197
279
  const room = await rs
198
- .listRooms([jam.id])
199
- .then((rooms) => rooms.find((r) => r.name === jam.id));
280
+ .listRooms([roomName])
281
+ .then((rooms) => rooms.find((r) => r.name === roomName));
200
282
  if (!room) {
201
283
  return {
202
284
  participants: [],
203
285
  active: false,
204
286
  };
205
287
  }
206
- const participants = await listParticipantIds(jam.id);
288
+ const participants = await listParticipantIds(roomName);
207
289
  if (participants.length === 0) {
208
290
  // Room exists only for egress ghosts / empty leftovers — reclaim so it
209
291
  // stops appearing under Live jams.
210
- void reclaimOrphanJamRoom(jam);
292
+ void reclaimOrphanJamRoom(jam, roomName);
211
293
  return {
212
294
  participants: [],
213
295
  active: false,
@@ -7,38 +7,44 @@ type EdgeMetadata = {
7
7
  export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
8
8
  id: string;
9
9
  jamId: string;
10
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
10
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
11
11
  profileId: string;
12
12
  content?: string | undefined;
13
13
  reaction?: "👍" | undefined;
14
+ recurrenceId?: string | undefined;
14
15
  }, JamEvent, JamEvent>;
15
16
  export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
16
17
  id: string;
17
18
  jamId: string;
18
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
19
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
19
20
  profileId: string;
20
21
  content?: string | undefined;
21
22
  reaction?: "👍" | undefined;
23
+ recurrenceId?: string | undefined;
22
24
  }, JamEvent, JamEvent>;
23
25
  export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
24
26
  id: string;
25
27
  jamId: string;
26
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
28
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
27
29
  profileId: string;
28
30
  content?: string | undefined;
29
31
  reaction?: "👍" | undefined;
32
+ recurrenceId?: string | undefined;
30
33
  }, JamEvent, JamEvent>;
31
34
  export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
32
35
  id: string;
33
36
  jamId: string;
34
- type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop";
37
+ type: "close" | "join" | "message" | "start" | "reaction" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
35
38
  profileId: string;
36
39
  content?: string | undefined;
37
40
  reaction?: "👍" | undefined;
41
+ recurrenceId?: string | undefined;
38
42
  }, JamEvent, JamEvent>;
39
43
  export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
40
44
  export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
41
45
  status: "active" | "completed" | "failed" | "requested";
46
+ kind?: "file" | "rtmp" | undefined;
47
+ destinationHost?: string | undefined;
42
48
  egressId?: string | undefined;
43
49
  attachment?: {
44
50
  type: string;
@@ -71,6 +77,8 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
71
77
  deletedAt?: string | null | undefined;
72
78
  } & {
73
79
  status: "active" | "completed" | "failed" | "requested";
80
+ kind?: "file" | "rtmp" | undefined;
81
+ destinationHost?: string | undefined;
74
82
  egressId?: string | undefined;
75
83
  attachment?: {
76
84
  type: string;
@@ -105,6 +113,8 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
105
113
  deletedAt?: string | null | undefined;
106
114
  } & {
107
115
  status: "active" | "completed" | "failed" | "requested";
116
+ kind?: "file" | "rtmp" | undefined;
117
+ destinationHost?: string | undefined;
108
118
  egressId?: string | undefined;
109
119
  attachment?: {
110
120
  type: string;
@@ -6,6 +6,8 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
6
6
  deletedAt?: string | null | undefined;
7
7
  } & {
8
8
  status: "active" | "completed" | "failed" | "requested";
9
+ kind?: "file" | "rtmp" | undefined;
10
+ destinationHost?: string | undefined;
9
11
  egressId?: string | undefined;
10
12
  attachment?: {
11
13
  type: string;
@@ -0,0 +1,5 @@
1
+ import { EncodingOptionsPreset, StreamOutput } from 'livekit-server-sdk';
2
+ export declare const rtmpStreamOutput: (rtmpUrl: string) => StreamOutput;
3
+ export declare const rtmpWebEgressOptions: {
4
+ readonly encodingOptions: EncodingOptionsPreset.H264_1080P_30;
5
+ };
@@ -0,0 +1,8 @@
1
+ import { EncodingOptionsPreset, StreamOutput, StreamProtocol, } from 'livekit-server-sdk';
2
+ export const rtmpStreamOutput = (rtmpUrl) => new StreamOutput({
3
+ protocol: StreamProtocol.RTMP,
4
+ urls: [rtmpUrl],
5
+ });
6
+ export const rtmpWebEgressOptions = {
7
+ encodingOptions: EncodingOptionsPreset.H264_1080P_30,
8
+ };
@@ -1,4 +1,4 @@
1
1
  import { PostWithMeta, PublicProfile } from '@openpeepshq/common/types';
2
- export declare const assertJamRsvpAllowed: (event: PostWithMeta, profile: PublicProfile) => void;
3
- export declare const createJamEgressToken: (event: PostWithMeta) => Promise<string>;
4
- export declare const createJamToken: (event: PostWithMeta, profile: PublicProfile, external?: boolean) => Promise<string>;
2
+ export declare const assertJamRsvpAllowed: (event: PostWithMeta, profile: PublicProfile, recurrenceId?: string) => void;
3
+ export declare const createJamEgressToken: (event: PostWithMeta, recurrenceId?: string) => Promise<string>;
4
+ export declare const createJamToken: (event: PostWithMeta, profile: PublicProfile, external?: boolean, recurrenceId?: string) => Promise<string>;
@@ -1,5 +1,5 @@
1
1
  import { publicProfileSchema, } from '@openpeepshq/common/types';
2
- import { canModerateJam, countYesRsvps, getEffectiveRsvp, } from '@openpeepshq/common/lib';
2
+ import { canModerateJam, countYesRsvps, getEffectiveRsvp, jamRoomName, } from '@openpeepshq/common/lib';
3
3
  import { authNeeded, forbidden, notFound } from '../errors/index.js';
4
4
  import { config } from '../config/index.js';
5
5
  import { AccessToken, TrackSource } from 'livekit-server-sdk';
@@ -19,7 +19,7 @@ const calculateSources = (jam, profile) => {
19
19
  }
20
20
  return sources;
21
21
  };
22
- export const assertJamRsvpAllowed = (event, profile) => {
22
+ export const assertJamRsvpAllowed = (event, profile, recurrenceId) => {
23
23
  var _a, _b;
24
24
  const eventData = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? event.data : undefined;
25
25
  if (!(eventData === null || eventData === void 0 ? void 0 : eventData.maxAttendees)) {
@@ -28,17 +28,18 @@ export const assertJamRsvpAllowed = (event, profile) => {
28
28
  if (canModerateJam(profile, event)) {
29
29
  return;
30
30
  }
31
- if (((_b = getEffectiveRsvp(event, profile.id)) === null || _b === void 0 ? void 0 : _b.response) === 'yes') {
31
+ if (((_b = getEffectiveRsvp(event, profile.id, recurrenceId)) === null || _b === void 0 ? void 0 : _b.response) === 'yes') {
32
32
  return;
33
33
  }
34
- if (countYesRsvps(event) >= eventData.maxAttendees) {
34
+ if (countYesRsvps(event, recurrenceId) >= eventData.maxAttendees) {
35
35
  throw forbidden({ errorKey: 'error.eventAtCapacity' });
36
36
  }
37
37
  throw forbidden({ errorKey: 'error.jamRsvpRequired' });
38
38
  };
39
- export const createJamEgressToken = async (event) => {
39
+ export const createJamEgressToken = async (event, recurrenceId) => {
40
40
  var _a, _b;
41
41
  const jamId = event.id;
42
+ const roomName = jamRoomName(event.id, recurrenceId);
42
43
  const jam = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam);
43
44
  if (!jam) {
44
45
  throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
@@ -51,7 +52,7 @@ export const createJamEgressToken = async (event) => {
51
52
  }),
52
53
  });
53
54
  accessToken.addGrant({
54
- room: jamId,
55
+ room: roomName,
55
56
  hidden: true,
56
57
  roomJoin: true,
57
58
  roomRecord: true,
@@ -59,21 +60,22 @@ export const createJamEgressToken = async (event) => {
59
60
  });
60
61
  return accessToken.toJwt();
61
62
  };
62
- export const createJamToken = async (event, profile, external = false) => {
63
+ export const createJamToken = async (event, profile, external = false, recurrenceId) => {
63
64
  var _a, _b, _c;
64
65
  if (!profile.id)
65
66
  throw authNeeded({ errorKey: 'error.profileRequired' });
66
67
  const jamId = event.id;
68
+ const roomName = jamRoomName(event.id, recurrenceId);
67
69
  const jam = ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.jam);
68
70
  if (!jam) {
69
71
  throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
70
72
  }
71
- assertJamRsvpAllowed(event, profile);
73
+ assertJamRsvpAllowed(event, profile, recurrenceId);
72
74
  const rs = await roomService();
73
75
  if (rs === undefined) {
74
- throw forbidden({ errorKey: 'error.jamNotOpen' });
76
+ throw forbidden({ errorKey: 'error.jamsUnavailable' });
75
77
  }
76
- const rooms = await rs.listRooms([jamId]);
78
+ const rooms = await rs.listRooms([roomName]);
77
79
  const jamOpen = rooms.length === 1;
78
80
  if (!jamOpen && !(jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id))) {
79
81
  throw forbidden({ errorKey: 'error.jamNotOpen' });
@@ -84,7 +86,7 @@ export const createJamToken = async (event, profile, external = false) => {
84
86
  if (instanceDomain) {
85
87
  try {
86
88
  await rs.createRoom({
87
- name: jamId,
89
+ name: roomName,
88
90
  metadata: JSON.stringify({ instanceDomain }),
89
91
  emptyTimeout: JAM_ROOM_EMPTY_TIMEOUT_SEC,
90
92
  departureTimeout: JAM_ROOM_DEPARTURE_TIMEOUT_SEC,
@@ -99,6 +101,7 @@ export const createJamToken = async (event, profile, external = false) => {
99
101
  jamId,
100
102
  type: 'start',
101
103
  profileId: profile.id,
104
+ recurrenceId,
102
105
  });
103
106
  }
104
107
  const { apiKey, apiSecret } = (await config()).jams.livekit;
@@ -112,7 +115,7 @@ export const createJamToken = async (event, profile, external = false) => {
112
115
  }),
113
116
  });
114
117
  accessToken.addGrant({
115
- room: jamId,
118
+ room: roomName,
116
119
  roomJoin: true,
117
120
  roomAdmin: jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id),
118
121
  roomRecord: jam === null || jam === void 0 ? void 0 : jam.moderators.includes(profile.id),
@@ -1,5 +1,7 @@
1
1
  import { type PublicProfile, type PostWithMeta } from '@openpeepshq/common/types';
2
- export declare const currentWaitingRoomWatch: (jamEvent: PostWithMeta, onChange: (waitingRoom: Record<string, PublicProfile>) => void | Promise<void>) => Promise<() => Promise<void>>;
3
- export declare const admittanceWatch: (jamEvent: PostWithMeta, profileId: string, onToken: (token: string) => Promise<void> | void) => Promise<() => Promise<void>>;
4
- export declare const joinWaitingRoom: (event: PostWithMeta, profile: PublicProfile) => Promise<void>;
5
- export declare const acceptFromWaitingRoom: (event: PostWithMeta, profileId: string) => Promise<undefined>;
2
+ export declare const isAdmittedToJam: (event: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<boolean>;
3
+ export declare const clearJamAdmittance: (event: PostWithMeta, recurrenceId?: string) => Promise<void>;
4
+ export declare const currentWaitingRoomWatch: (jamEvent: PostWithMeta, onChange: (waitingRoom: Record<string, PublicProfile>) => void | Promise<void>, recurrenceId?: string) => Promise<() => Promise<void>>;
5
+ export declare const admittanceWatch: (jamEvent: PostWithMeta, profileId: string, onToken: (token: string) => Promise<void> | void, recurrenceId?: string) => Promise<() => Promise<void>>;
6
+ export declare const joinWaitingRoom: (event: PostWithMeta, profile: PublicProfile, recurrenceId?: string) => Promise<void>;
7
+ export declare const acceptFromWaitingRoom: (event: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<undefined>;