@openpeepshq/core 0.1.33 → 0.1.35
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/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +36 -33
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +17 -12
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +164 -140
- package/dist/analytics/report.d.ts +22 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +82 -25
- package/dist/backups/metadata.d.ts +2 -3
- package/dist/backups/metadata.js +6 -2
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/capabilities.js +13 -2
- package/dist/config/defaults/community.js +8 -3
- package/dist/config/defaults/core.d.ts +1 -1
- package/dist/config/defaults/core.js +16 -8
- package/dist/config/index.d.ts +22 -0
- package/dist/config/index.js +15 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.d.ts +1 -0
- package/dist/db/helpers.js +25 -7
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -0
- package/dist/db/init.js +2 -3
- package/dist/db/migration/importCollections.d.ts +14 -9
- package/dist/db/migration/importCollections.js +121 -174
- package/dist/db/migration/shared.d.ts +2 -33
- package/dist/db/migration/shared.js +17 -87
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/collections.d.ts +2 -2
- package/dist/db/pg/collections.js +2 -2
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +12 -0
- package/dist/db/pg/filters/posts.js +30 -4
- package/dist/db/pg/filters/profiles.d.ts +1 -0
- package/dist/db/pg/filters/profiles.js +2 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +40 -10
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +65 -25
- package/dist/db/pg/map/registry.d.ts +5 -0
- package/dist/db/pg/map/registry.js +133 -56
- package/dist/db/pg/map/relations.js +76 -68
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.d.ts +1 -2
- package/dist/db/pg/migrate.js +8 -9
- package/dist/db/pg/queries/activity.js +5 -5
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/queries/sorts.d.ts +1 -0
- package/dist/db/pg/queries/sorts.js +4 -0
- package/dist/db/pg/schema/documents.d.ts +279 -41
- package/dist/db/pg/schema/documents.js +136 -22
- package/dist/db/pg/schema/edges.d.ts +116 -7
- package/dist/db/pg/schema/edges.js +9 -2
- package/dist/db/pg/schema/index.d.ts +362 -15
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
- package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
- package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
- package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
- package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
- package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
- package/dist/db/pg/sql/meta/_journal.json +49 -0
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +14 -3
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +1 -0
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.d.ts +17 -0
- package/dist/federation/activities.js +25 -0
- package/dist/federation/identity.d.ts +16 -0
- package/dist/federation/identity.js +52 -0
- package/dist/federation/index.d.ts +4 -0
- package/dist/federation/index.js +3 -0
- package/dist/federation/profiles.d.ts +3 -0
- package/dist/federation/profiles.js +14 -0
- package/dist/groups/finders.d.ts +2 -1
- package/dist/groups/helpers.d.ts +18 -0
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -2
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.d.ts +6 -3
- package/dist/hashtags/finders.js +2 -0
- package/dist/hashtags/helpers.d.ts +8 -0
- package/dist/hashtags/helpers.js +4 -0
- package/dist/hashtags/index.d.ts +2 -0
- package/dist/hashtags/index.js +2 -0
- package/dist/hashtags/mutations.d.ts +3 -0
- package/dist/hashtags/mutations.js +13 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +3 -1
- package/dist/i18n/pluginLocales.d.ts +6 -0
- package/dist/i18n/pluginLocales.js +15 -0
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.d.ts +19 -0
- package/dist/jams/export.js +58 -0
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +10 -0
- package/dist/jams/health.js +50 -0
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.d.ts +2 -0
- package/dist/jams/index.js +25 -18
- package/dist/jams/jobs.js +2 -3
- package/dist/jams/livekit.d.ts +49 -4
- package/dist/jams/livekit.js +62 -45
- package/dist/jams/mapping.d.ts +3 -3
- package/dist/jams/mutations.d.ts +1 -1
- package/dist/jams/recording.d.ts +10 -0
- package/dist/jams/recording.js +33 -1
- package/dist/jams/token.d.ts +13 -1
- package/dist/jams/token.js +25 -18
- package/dist/jams/waitingRoom.js +1 -1
- package/dist/jobs/index.d.ts +1 -0
- package/dist/jobs/index.js +9 -3
- package/dist/jobs/jobDetail.js +6 -12
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.js +13 -29
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +73 -12
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +25 -11
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/index.js +4 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +3 -5
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +11 -6
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
- package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +17 -0
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
- package/dist/notifications/defaultNotifications/rsvp/index.js +31 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +82 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
- package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.js +13 -10
- package/dist/notifications/jobs.js +10 -5
- package/dist/notifications/mutations.js +8 -1
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +39 -4
- package/dist/plugins/install.d.ts +28 -9
- package/dist/plugins/install.js +302 -56
- package/dist/plugins/pluginAuth.d.ts +1 -1
- package/dist/plugins/pluginAuth.js +13 -10
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +9 -0
- package/dist/posts/activity.js +34 -0
- package/dist/posts/contextClosure.d.ts +1 -9
- package/dist/posts/contextClosure.js +14 -44
- package/dist/posts/conversationQueries.d.ts +7 -0
- package/dist/posts/conversationQueries.js +76 -4
- package/dist/posts/eventAgenda.d.ts +1 -0
- package/dist/posts/eventAgenda.js +17 -8
- package/dist/posts/eventOccurrenceJobs.js +7 -2
- package/dist/posts/eventOccurrences.d.ts +6 -0
- package/dist/posts/eventOccurrences.js +22 -1
- package/dist/posts/finders.d.ts +56 -9
- package/dist/posts/finders.js +84 -23
- package/dist/posts/helpers/filters.js +13 -9
- package/dist/posts/helpers/index.d.ts +179 -14
- package/dist/posts/helpers/index.js +70 -34
- package/dist/posts/index.d.ts +5 -2
- package/dist/posts/index.js +5 -2
- package/dist/posts/mapping.d.ts +765 -30
- package/dist/posts/mapping.js +74 -31
- package/dist/posts/mutations.d.ts +516 -3
- package/dist/posts/mutations.js +179 -41
- package/dist/posts/pollEnd.d.ts +3 -0
- package/dist/posts/pollEnd.js +4 -0
- package/dist/posts/pollEndJobs.d.ts +8 -0
- package/dist/posts/pollEndJobs.js +49 -0
- package/dist/posts/replyClosure.d.ts +10 -0
- package/dist/posts/replyClosure.js +43 -0
- package/dist/posts/rsvpConfirmationEmail.js +23 -15
- package/dist/posts/threadPreview.d.ts +8 -0
- package/dist/posts/threadPreview.js +44 -0
- package/dist/posts/unseenCounts.js +4 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +21 -5
- package/dist/profileSettings/mapping.d.ts +2 -0
- package/dist/profiles/activityQueries.d.ts +5 -0
- package/dist/profiles/activityQueries.js +85 -0
- package/dist/profiles/activitySummary.d.ts +3 -0
- package/dist/profiles/activitySummary.js +82 -0
- package/dist/profiles/blocks.d.ts +12 -0
- package/dist/profiles/blocks.js +73 -0
- package/dist/profiles/cache.d.ts +1 -0
- package/dist/profiles/cache.js +30 -10
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.d.ts +2 -1
- package/dist/profiles/finders.js +15 -8
- package/dist/profiles/helpers.d.ts +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/mapping.d.ts +10 -5
- package/dist/profiles/mapping.js +13 -1
- package/dist/profiles/mutations.d.ts +8 -4
- package/dist/profiles/mutations.js +31 -4
- package/dist/redis/connection.d.ts +2 -0
- package/dist/redis/connection.js +25 -6
- package/dist/reports/helpers.js +7 -3
- package/dist/roles/index.d.ts +1 -1
- package/dist/roles/index.js +1 -1
- package/dist/roles/mapping.d.ts +1 -0
- package/dist/roles/mutations.js +85 -3
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/search/mapping.d.ts +1 -1
- package/dist/search/mapping.js +6 -2
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.js +31 -14
- package/dist/server/stablePublicServerInfo.d.ts +17 -0
- package/dist/server/stablePublicServerInfo.js +37 -0
- package/dist/server/status.d.ts +25 -0
- package/dist/server/status.js +97 -0
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.d.ts +1 -17681
- package/dist/stats/finders.js +22 -9
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +39 -2
- package/dist/stats/mapping.js +8 -4
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -7
- package/dist/db/migration/detect.d.ts +0 -3
- package/dist/db/migration/detect.js +0 -33
- package/dist/db/migration/importPostgres.d.ts +0 -3
- package/dist/db/migration/importPostgres.js +0 -18
- package/dist/db/migration/transform.d.ts +0 -20
- package/dist/db/migration/transform.js +0 -232
- package/dist/db/migration/validate.d.ts +0 -18
- package/dist/db/migration/validate.js +0 -69
- package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
- package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
- package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
- package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
- package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
- package/dist/mastodon/index.d.ts +0 -4
- package/dist/mastodon/index.js +0 -51
- package/dist/mastodon/types.d.ts +0 -7579
- package/dist/mastodon/types.js +0 -523
- package/dist/mastodon/typescript.d.ts +0 -1578
- package/dist/mastodon/typescript.js +0 -1
- package/dist/migration/index.d.ts +0 -4
- package/dist/migration/index.js +0 -4
- package/dist/roles/defaults.d.ts +0 -2
- package/dist/roles/defaults.js +0 -95
|
@@ -18,12 +18,11 @@ export const updateInviteLink = async (id, inviteLinkData) => {
|
|
|
18
18
|
return inviteLinksMapping.update(db, id, inviteLinkData);
|
|
19
19
|
};
|
|
20
20
|
export const redeemInviteLink = async (inviteLink, profile) => {
|
|
21
|
-
|
|
22
|
-
if (((_a = inviteLink.profile) === null || _a === void 0 ? void 0 : _a.id) === profile.id) {
|
|
21
|
+
if (inviteLink.profile?.id === profile.id) {
|
|
23
22
|
throw new Error('Invite link creator and redeemer cannot be the same');
|
|
24
23
|
}
|
|
25
24
|
await allpeepDb().then(({ db }) => redeemInviteLinkConnector(db, profile, inviteLink));
|
|
26
|
-
const groupIds = [...new Set(
|
|
25
|
+
const groupIds = [...new Set(inviteLink.groupIds ?? [])];
|
|
27
26
|
const adder = inviteLink.profile;
|
|
28
27
|
for (const groupId of groupIds) {
|
|
29
28
|
const group = await findGroup(groupId);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Profile } from '@openpeepshq/common/types';
|
|
2
|
+
export type JamAttendanceKind = 'community' | 'public';
|
|
3
|
+
export type JamAttendanceExportRow = {
|
|
4
|
+
kind: JamAttendanceKind | '';
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
handle: string;
|
|
8
|
+
joinedAt: string;
|
|
9
|
+
};
|
|
10
|
+
type JoinRecord = {
|
|
11
|
+
profileId: string;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
};
|
|
14
|
+
type AttendanceProfile = Pick<Profile, 'type' | 'displayName' | 'handle' | 'guestData'>;
|
|
15
|
+
export declare const jamAttendanceExportHeaders: readonly ["Type", "Name", "Email", "Handle", "Joined At"];
|
|
16
|
+
export declare const jamAttendanceRowFromJoin: (join: JoinRecord, profile: AttendanceProfile | undefined) => JamAttendanceExportRow;
|
|
17
|
+
export declare const jamAttendanceExportCsv: (rows: JamAttendanceExportRow[]) => string;
|
|
18
|
+
export declare const exportJamAttendanceCsv: (jamId: string) => Promise<string>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { and, asc, eq, isNull, sql } from 'drizzle-orm';
|
|
2
|
+
import { toCsvRow } from '@openpeepshq/common/lib';
|
|
3
|
+
import { database } from '../db/index.js';
|
|
4
|
+
import { jamEvents } from '../db/pg/schema/index.js';
|
|
5
|
+
import { normalizeIsoDatetime } from '../db/pg/mappers.js';
|
|
6
|
+
import { getProfiles } from '../profiles/index.js';
|
|
7
|
+
export const jamAttendanceExportHeaders = [
|
|
8
|
+
'Type',
|
|
9
|
+
'Name',
|
|
10
|
+
'Email',
|
|
11
|
+
'Handle',
|
|
12
|
+
'Joined At',
|
|
13
|
+
];
|
|
14
|
+
export const jamAttendanceRowFromJoin = (join, profile) => {
|
|
15
|
+
const isPublic = profile?.type === 'guest';
|
|
16
|
+
return {
|
|
17
|
+
kind: profile ? (isPublic ? 'public' : 'community') : '',
|
|
18
|
+
name: profile?.displayName || (isPublic ? '' : (profile?.handle ?? '')),
|
|
19
|
+
// Community emails aren't here: several accounts can control one profile.
|
|
20
|
+
email: isPublic ? (profile?.guestData?.email ?? '') : '',
|
|
21
|
+
handle: isPublic ? '' : (profile?.handle ?? ''),
|
|
22
|
+
joinedAt: join.createdAt,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const jamAttendanceExportCsv = (rows) => [
|
|
26
|
+
toCsvRow([...jamAttendanceExportHeaders]),
|
|
27
|
+
...rows.map((row) => toCsvRow([row.kind, row.name, row.email, row.handle, row.joinedAt])),
|
|
28
|
+
].join('\n');
|
|
29
|
+
const listJamJoinEvents = async (jamId) => {
|
|
30
|
+
const db = await database();
|
|
31
|
+
const rows = await db
|
|
32
|
+
.select({
|
|
33
|
+
createdAt: jamEvents.createdAt,
|
|
34
|
+
body: jamEvents.body,
|
|
35
|
+
})
|
|
36
|
+
.from(jamEvents)
|
|
37
|
+
.where(and(eq(jamEvents.postId, jamId), isNull(jamEvents.deletedAt), sql `${jamEvents.body}->>'type' = 'join'`))
|
|
38
|
+
.orderBy(asc(jamEvents.createdAt), asc(jamEvents.id));
|
|
39
|
+
return rows.flatMap((row) => {
|
|
40
|
+
const profileId = row.body?.profileId;
|
|
41
|
+
if (typeof profileId !== 'string' || !profileId) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
profileId,
|
|
47
|
+
createdAt: normalizeIsoDatetime(row.createdAt),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const exportJamAttendanceCsv = async (jamId) => {
|
|
53
|
+
const joins = await listJamJoinEvents(jamId);
|
|
54
|
+
const profileIds = [...new Set(joins.map((join) => join.profileId))];
|
|
55
|
+
const profiles = profileIds.length ? await getProfiles(profileIds) : [];
|
|
56
|
+
const profilesById = new Map(profiles.map((profile) => [profile.id, profile]));
|
|
57
|
+
return jamAttendanceExportCsv(joins.map((join) => jamAttendanceRowFromJoin(join, profilesById.get(join.profileId))));
|
|
58
|
+
};
|
package/dist/jams/finders.js
CHANGED
|
@@ -10,7 +10,10 @@ export const listJamEvents = (jamId, { start, limit } = {}) => allpeepDb().then(
|
|
|
10
10
|
export const listAttendance = (jamId, { start, limit } = {}) => allpeepDb().then(({ db }) => baseListJam({ jamId, type: 'join' }, { start, limit }).all(db));
|
|
11
11
|
export const findJamState = async (jam, hideParticipants, recurrenceId) => {
|
|
12
12
|
const state = await getJamState(jam, recurrenceId);
|
|
13
|
-
return
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
participants: hideParticipants ? [] : state.participants,
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
18
|
export const findJamRecording = async (recordingId) => allpeepDb()
|
|
16
19
|
.then(({ db }) => jamRecordingsMapping.find(db, recordingId))
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const LIVEKIT_HEALTH_TIMEOUT_MS = 5000;
|
|
2
|
+
export declare const LIVEKIT_HEALTH_MAX_ATTEMPTS = 3;
|
|
3
|
+
/**
|
|
4
|
+
* True when a LiveKit RoomService call succeeds within maxAttempts. Retries so a
|
|
5
|
+
* single transient failure does not disable jams for a full /server/info bucket.
|
|
6
|
+
* Credentials in config are not enough — invalid keys fail on first RPC.
|
|
7
|
+
*/
|
|
8
|
+
export declare const probeLivekitConnection: (listRooms: () => Promise<unknown>, timeoutMs?: number, maxAttempts?: number) => Promise<boolean>;
|
|
9
|
+
/** Cached LiveKit reachability. False when unset, unauthorized, or unreachable. */
|
|
10
|
+
export declare const isLivekitConnected: () => Promise<boolean>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createCache } from 'cache-manager';
|
|
2
|
+
import { logger } from '../log/index.js';
|
|
3
|
+
import { roomService } from './livekit.js';
|
|
4
|
+
const log = logger('app:jams:livekit');
|
|
5
|
+
/** Sentinel room name so the probe authenticates without listing every room. */
|
|
6
|
+
const LIVEKIT_HEALTH_ROOM = '__openpeeps_livekit_health__';
|
|
7
|
+
const LIVEKIT_HEALTH_CACHE_KEY = 'livekit-health';
|
|
8
|
+
export const LIVEKIT_HEALTH_TIMEOUT_MS = 5000;
|
|
9
|
+
export const LIVEKIT_HEALTH_MAX_ATTEMPTS = 3;
|
|
10
|
+
const livekitHealthCache = createCache({
|
|
11
|
+
ttl: 20 * 1000,
|
|
12
|
+
refreshThreshold: 5 * 1000,
|
|
13
|
+
});
|
|
14
|
+
const withTimeout = (promise, timeoutMs) => new Promise((resolve, reject) => {
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
reject(new Error('LiveKit health check timed out'));
|
|
17
|
+
}, timeoutMs);
|
|
18
|
+
promise.then((value) => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
resolve(value);
|
|
21
|
+
}, (err) => {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
reject(err);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* True when a LiveKit RoomService call succeeds within maxAttempts. Retries so a
|
|
28
|
+
* single transient failure does not disable jams for a full /server/info bucket.
|
|
29
|
+
* Credentials in config are not enough — invalid keys fail on first RPC.
|
|
30
|
+
*/
|
|
31
|
+
export const probeLivekitConnection = async (listRooms, timeoutMs = LIVEKIT_HEALTH_TIMEOUT_MS, maxAttempts = LIVEKIT_HEALTH_MAX_ATTEMPTS) => {
|
|
32
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
33
|
+
try {
|
|
34
|
+
await withTimeout(listRooms(), timeoutMs);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
log.warn(`LiveKit health check failed (attempt ${attempt}/${maxAttempts}): ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
/** Cached LiveKit reachability. False when unset, unauthorized, or unreachable. */
|
|
44
|
+
export const isLivekitConnected = () => livekitHealthCache.wrap(LIVEKIT_HEALTH_CACHE_KEY, async () => {
|
|
45
|
+
const rs = await roomService();
|
|
46
|
+
if (rs === undefined) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return probeLivekitConnection(() => rs.listRooms([LIVEKIT_HEALTH_ROOM]));
|
|
50
|
+
});
|
package/dist/jams/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JamRecording, JamRecordingWithMeta, PostWithMeta, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const connectRecording: (db: import("../db").PgDb, from: ProfileWithMeta, to: PostWithMeta, data?: {
|
|
3
|
-
status: "completed" | "failed" | "active" | "requested";
|
|
3
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
4
4
|
kind?: "file" | "rtmp" | undefined;
|
|
5
5
|
destinationHost?: string | undefined;
|
|
6
6
|
egressId?: string | undefined;
|
|
@@ -32,7 +32,7 @@ export declare const connectRecording: (db: import("../db").PgDb, from: ProfileW
|
|
|
32
32
|
} & {
|
|
33
33
|
id?: string;
|
|
34
34
|
}) => Promise<import("../db/pg/map").WithId<{
|
|
35
|
-
status: "completed" | "failed" | "active" | "requested";
|
|
35
|
+
status: "completed" | "failed" | "active" | "requested" | "finalizing";
|
|
36
36
|
kind?: "file" | "rtmp" | undefined;
|
|
37
37
|
destinationHost?: string | undefined;
|
|
38
38
|
egressId?: string | undefined;
|
package/dist/jams/helpers.js
CHANGED
|
@@ -5,7 +5,11 @@ import { findProfile } from '../profiles/index.js';
|
|
|
5
5
|
import { findPost } from '../posts/index.js';
|
|
6
6
|
import { config } from '../config/index.js';
|
|
7
7
|
export const connectRecording = connector(collectionInfos.profilesCollection, collectionInfos.postsCollection, collectionInfos.jamRecordingsCollection);
|
|
8
|
-
export const transformJamRecordingData = async (recording) => (
|
|
8
|
+
export const transformJamRecordingData = async (recording) => ({
|
|
9
|
+
...jamRecordingSchema.parse(recording),
|
|
10
|
+
profile: (await findProfile(recording._from.split('/')[1])),
|
|
11
|
+
post: (await findPost(recording._to.split('/')[1])),
|
|
12
|
+
});
|
|
9
13
|
/** Hostname used when stamping LiveKit room metadata (`instanceDomain`). */
|
|
10
14
|
export const localInstanceDomain = async () => {
|
|
11
15
|
const host = (await config()).server.host;
|
|
@@ -23,7 +27,7 @@ export const parseRoomInstanceDomain = (metadata) => {
|
|
|
23
27
|
? parsed.instanceDomain.toLowerCase()
|
|
24
28
|
: undefined;
|
|
25
29
|
}
|
|
26
|
-
catch
|
|
30
|
+
catch {
|
|
27
31
|
return undefined;
|
|
28
32
|
}
|
|
29
33
|
};
|
package/dist/jams/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type AuthorizationData, type MuteParticipantRequest, type PostWithMeta, type Profile } from '@openpeepshq/common/types';
|
|
2
2
|
export { createJamToken, createJamEgressToken } from './token';
|
|
3
|
+
export { isLivekitConnected } from './health';
|
|
3
4
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit';
|
|
4
5
|
export { rtmpStreamOutput } from './rtmp';
|
|
5
6
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs';
|
|
6
7
|
export * from './waitingRoom';
|
|
7
8
|
export * from './mutations';
|
|
8
9
|
export * from './finders';
|
|
10
|
+
export * from './export';
|
|
9
11
|
export * from './recording';
|
|
10
12
|
export { deriveJamRecordingUploadSecret, jamRecordingUploadSecret, } from './recordingUploadAuth';
|
|
11
13
|
export declare const listLiveJams: (authData: AuthorizationData) => Promise<PostWithMeta[]>;
|
package/dist/jams/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jamRoomName, postIdFromJamRoomName, uniquePostsById, } from '@openpeepshq/common/lib';
|
|
2
|
-
import { listParticipantIds, reclaimOrphanJamRoom, roomService, stopRecording, stopRtmpStream, } from './livekit.js';
|
|
2
|
+
import { listParticipantIds, reclaimOrphanJamRoom, roomService, shouldReclaimJamRoom, stopRecording, stopRtmpStream, } from './livekit.js';
|
|
3
3
|
import { jamStateCache, LIVE_JAMS_CACHE_KEY, liveJamPostsCache } from './cache.js';
|
|
4
4
|
import { localInstanceDomain, parseRoomInstanceDomain } from './helpers.js';
|
|
5
5
|
import { findPost } from '../posts/index.js';
|
|
@@ -8,15 +8,19 @@ import { clearJamAdmittance } from './waitingRoom.js';
|
|
|
8
8
|
import { uuidv7 } from 'uuidv7';
|
|
9
9
|
import { canReadPost } from '../posts/helpers/index.js';
|
|
10
10
|
import { capabilitiesConfig } from '../config/index.js';
|
|
11
|
+
import { logger } from '../log/index.js';
|
|
11
12
|
export { createJamToken, createJamEgressToken } from './token.js';
|
|
13
|
+
export { isLivekitConnected } from './health.js';
|
|
12
14
|
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
15
|
export { rtmpStreamOutput } from './rtmp.js';
|
|
14
16
|
export { jamRecordingStopQueue, jamRecordingStopWorker, scheduleRecordingAutoStop, cancelRecordingAutoStop, JAM_RECORDING_MAX_DURATION_MS, } from './jobs.js';
|
|
15
17
|
export * from './waitingRoom.js';
|
|
16
18
|
export * from './mutations.js';
|
|
17
19
|
export * from './finders.js';
|
|
20
|
+
export * from './export.js';
|
|
18
21
|
export * from './recording.js';
|
|
19
22
|
export { deriveJamRecordingUploadSecret, jamRecordingUploadSecret, } from './recordingUploadAuth.js';
|
|
23
|
+
const log = logger('app:jams:livekit');
|
|
20
24
|
const invalidateJamCaches = async (jamId) => {
|
|
21
25
|
await Promise.all([
|
|
22
26
|
jamStateCache.del(jamId).catch(() => undefined),
|
|
@@ -35,10 +39,18 @@ const fetchLiveJamPosts = async () => {
|
|
|
35
39
|
if (rs === undefined) {
|
|
36
40
|
return [];
|
|
37
41
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
let rooms;
|
|
43
|
+
let localDomain;
|
|
44
|
+
try {
|
|
45
|
+
[rooms, localDomain] = await Promise.all([
|
|
46
|
+
rs.listRooms(),
|
|
47
|
+
localInstanceDomain(),
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
log.warn(`Failed to list live jam rooms: ${e.message}`);
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
42
54
|
const posts = await Promise.all(rooms.map(async (room) => {
|
|
43
55
|
const roomDomain = parseRoomInstanceDomain(room.metadata);
|
|
44
56
|
// Shared SFU: ignore other communities' rooms. Untagged rooms (pre-stamp)
|
|
@@ -47,21 +59,16 @@ const fetchLiveJamPosts = async () => {
|
|
|
47
59
|
return undefined;
|
|
48
60
|
}
|
|
49
61
|
const postId = postIdFromJamRoomName(room.name);
|
|
50
|
-
//
|
|
62
|
+
// Zero participants: host may still be connecting after Start, or the
|
|
63
|
+
// room is inside departureTimeout. LiveKit closes these; deleting them
|
|
64
|
+
// drops the host back to the join screen.
|
|
51
65
|
if (!room.numParticipants) {
|
|
52
|
-
const post = await findPost(postId);
|
|
53
|
-
if (post) {
|
|
54
|
-
reclaimLocalOrphan(post);
|
|
55
|
-
}
|
|
56
|
-
else if (!roomDomain || roomDomain === localDomain) {
|
|
57
|
-
void rs.deleteRoom(room.name).catch(() => undefined);
|
|
58
|
-
}
|
|
59
66
|
return undefined;
|
|
60
67
|
}
|
|
61
|
-
//
|
|
62
|
-
// egress-only
|
|
68
|
+
// Someone is connected. Egress counts toward numParticipants, so an
|
|
69
|
+
// egress-only room never hits emptyTimeout and has to be reclaimed.
|
|
63
70
|
const humans = await listParticipantIds(room.name);
|
|
64
|
-
if (humans.length
|
|
71
|
+
if (shouldReclaimJamRoom(room.numParticipants, humans.length)) {
|
|
65
72
|
const post = await findPost(postId);
|
|
66
73
|
if (post) {
|
|
67
74
|
reclaimLocalOrphan(post);
|
|
@@ -82,7 +89,7 @@ export const listLiveJams = async (authData) => {
|
|
|
82
89
|
]);
|
|
83
90
|
return posts.filter(canReadPost(config, authData));
|
|
84
91
|
};
|
|
85
|
-
export const findJamEvent = async (id) => findPost(id).then((post) =>
|
|
92
|
+
export const findJamEvent = async (id) => findPost(id).then((post) => post?.data?.type === 'event' && post.data?.jam ? post : undefined);
|
|
86
93
|
export const closeJam = async (profile, jamEvent, recurrenceId) => {
|
|
87
94
|
const rs = await roomService();
|
|
88
95
|
if (rs === undefined) {
|
|
@@ -115,5 +122,5 @@ export const muteParticipant = async (jamId, data, recurrenceId) => {
|
|
|
115
122
|
if (!result) {
|
|
116
123
|
return { success: false };
|
|
117
124
|
}
|
|
118
|
-
return { success: result
|
|
125
|
+
return { success: result?.muted };
|
|
119
126
|
};
|
package/dist/jams/jobs.js
CHANGED
|
@@ -3,15 +3,14 @@ import { logger } from '../log/index.js';
|
|
|
3
3
|
import { findPost } from '../posts/index.js';
|
|
4
4
|
import { findActiveRecording } from './finders.js';
|
|
5
5
|
const log = logger('app:jams:jobs');
|
|
6
|
-
export const JAM_RECORDING_MAX_DURATION_MS = 60 * 60 * 1000;
|
|
6
|
+
export const JAM_RECORDING_MAX_DURATION_MS = 2 * 60 * 60 * 1000;
|
|
7
7
|
const recordingStopJobId = (recordingId) => `jam-recording-stop:${recordingId}`;
|
|
8
8
|
const [jamRecordingStopQueue, jamRecordingStopWorker] = queueAndWorker('jam-recording-stop', async (job) => {
|
|
9
|
-
var _a;
|
|
10
9
|
// Dynamic import avoids a load-time cycle with livekit.ts (which schedules
|
|
11
10
|
// this job when a recording starts).
|
|
12
11
|
const { stopRecording } = await import('./livekit.js');
|
|
13
12
|
const jamPost = await findPost(job.data.jamPostId);
|
|
14
|
-
if (!jamPost ||
|
|
13
|
+
if (!jamPost || jamPost.data?.type !== 'event' || !jamPost.data.jam) {
|
|
15
14
|
log.info(`Skipping auto-stop for missing jam ${job.data.jamPostId}`);
|
|
16
15
|
return;
|
|
17
16
|
}
|
package/dist/jams/livekit.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ import { RoomServiceClient } from 'livekit-server-sdk';
|
|
|
4
4
|
export declare const JAM_ROOM_EMPTY_TIMEOUT_SEC: number;
|
|
5
5
|
/** Seconds a room stays open after the last participant leaves. */
|
|
6
6
|
export declare const JAM_ROOM_DEPARTURE_TIMEOUT_SEC = 60;
|
|
7
|
+
/**
|
|
8
|
+
* LiveKit closes rooms with no participants via emptyTimeout (host still
|
|
9
|
+
* connecting after Start) and departureTimeout (reconnect). Those rooms must
|
|
10
|
+
* not be deleted here. Reclaim only when a non-human participant (egress) is
|
|
11
|
+
* holding the room open — they count toward `numParticipants`, so LiveKit
|
|
12
|
+
* will not time the room out.
|
|
13
|
+
*/
|
|
14
|
+
export declare const shouldReclaimJamRoom: (numParticipants: number, humanCount: number) => boolean;
|
|
7
15
|
export declare const roomService: () => Promise<RoomServiceClient | undefined>;
|
|
8
16
|
export declare const listParticipantIds: (jamId: string) => Promise<string[]>;
|
|
9
17
|
/**
|
|
@@ -12,6 +20,7 @@ export declare const listParticipantIds: (jamId: string) => Promise<string[]>;
|
|
|
12
20
|
*/
|
|
13
21
|
export declare const getJamObserverPath: (jamId: string, recurrenceId?: string) => Promise<string>;
|
|
14
22
|
export declare const getJamRecordingUrl: (jamId: string, recurrenceId?: string) => Promise<string>;
|
|
23
|
+
export declare const stopEgress: (egressId: string) => Promise<void>;
|
|
15
24
|
export declare const startRecording: (profile: ProfileWithMeta, jamPost: PostWithMeta, recurrenceId?: string) => Promise<JamRecording>;
|
|
16
25
|
export declare const startRtmpStream: (profile: ProfileWithMeta, jamPost: PostWithMeta, rtmpUrl: string, destinationHost?: string) => Promise<JamRecording>;
|
|
17
26
|
export declare const stopRtmpStream: (jamPost: PostWithMeta) => Promise<{
|
|
@@ -51,11 +60,47 @@ export declare const stopRtmpStream: (jamPost: PostWithMeta) => Promise<{
|
|
|
51
60
|
profile: ProfileWithMeta;
|
|
52
61
|
post: PostWithMeta;
|
|
53
62
|
} | undefined>;
|
|
54
|
-
export declare const
|
|
55
|
-
|
|
63
|
+
export declare const stopRecording: (jamPost: PostWithMeta, recurrenceId?: string) => Promise<{
|
|
64
|
+
status: "finalizing";
|
|
65
|
+
createdAt: string;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
deletedAt?: string | null | undefined;
|
|
68
|
+
kind?: "file" | "rtmp" | undefined;
|
|
69
|
+
destinationHost?: string | undefined;
|
|
70
|
+
egressId?: string | undefined;
|
|
71
|
+
attachment?: {
|
|
72
|
+
type: string;
|
|
73
|
+
url: string;
|
|
74
|
+
previewUrl: string | null;
|
|
75
|
+
textUrl: null;
|
|
76
|
+
filename: string;
|
|
77
|
+
meta: {
|
|
78
|
+
usage?: string | undefined;
|
|
79
|
+
focus?: {
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
} | undefined;
|
|
83
|
+
mimetype?: string | undefined;
|
|
84
|
+
size?: number | undefined;
|
|
85
|
+
};
|
|
86
|
+
id: string;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
updatedAt: string;
|
|
89
|
+
description?: string | undefined;
|
|
90
|
+
blurhash?: string | undefined;
|
|
91
|
+
status?: "failed" | "processing" | "ready" | undefined;
|
|
92
|
+
error?: string | undefined;
|
|
93
|
+
deletedAt?: string | null | undefined;
|
|
94
|
+
} | undefined;
|
|
95
|
+
replyPostId?: string | undefined;
|
|
96
|
+
id: string;
|
|
97
|
+
profile: ProfileWithMeta;
|
|
98
|
+
post: PostWithMeta;
|
|
99
|
+
} | undefined>;
|
|
56
100
|
/**
|
|
57
|
-
* Stops leftover egress and deletes
|
|
58
|
-
*
|
|
101
|
+
* Stops leftover egress and deletes an egress-only LiveKit room.
|
|
102
|
+
* Do not call this for a room with zero participants — that room is still
|
|
103
|
+
* inside emptyTimeout or departureTimeout. Safe to call repeatedly.
|
|
59
104
|
*/
|
|
60
105
|
export declare const reclaimOrphanJamRoom: (jam: PostWithMeta, roomName?: string) => Promise<void>;
|
|
61
106
|
export declare const finishRecording: (jamRecording: JamRecordingWithMeta) => Promise<void>;
|
package/dist/jams/livekit.js
CHANGED
|
@@ -8,6 +8,7 @@ import { uuidv7 } from 'uuidv7';
|
|
|
8
8
|
import { createJamEvent, updateJamRecording } from './mutations.js';
|
|
9
9
|
import { findActiveRecording, findActiveRtmpStream } from './finders.js';
|
|
10
10
|
import { cancelRecordingAutoStop, scheduleRecordingAutoStop } from './jobs.js';
|
|
11
|
+
import { finalizeJamRecording } from './recording.js';
|
|
11
12
|
import { jamRecordingUploadSecret } from './recordingUploadAuth.js';
|
|
12
13
|
import { createSignedServiceToken } from '../accessTokens/tokens.js';
|
|
13
14
|
import { unprocessableRequest } from '../errors/index.js';
|
|
@@ -19,6 +20,14 @@ const log = logger('app:jams:livekit');
|
|
|
19
20
|
export const JAM_ROOM_EMPTY_TIMEOUT_SEC = 5 * 60;
|
|
20
21
|
/** Seconds a room stays open after the last participant leaves. */
|
|
21
22
|
export const JAM_ROOM_DEPARTURE_TIMEOUT_SEC = 60;
|
|
23
|
+
/**
|
|
24
|
+
* LiveKit closes rooms with no participants via emptyTimeout (host still
|
|
25
|
+
* connecting after Start) and departureTimeout (reconnect). Those rooms must
|
|
26
|
+
* not be deleted here. Reclaim only when a non-human participant (egress) is
|
|
27
|
+
* holding the room open — they count toward `numParticipants`, so LiveKit
|
|
28
|
+
* will not time the room out.
|
|
29
|
+
*/
|
|
30
|
+
export const shouldReclaimJamRoom = (numParticipants, humanCount) => humanCount === 0 && numParticipants > 0;
|
|
22
31
|
export const roomService = async () => {
|
|
23
32
|
const { url, apiKey, apiSecret } = (await config()).jams.livekit;
|
|
24
33
|
if (!url || !apiKey || !apiSecret) {
|
|
@@ -78,16 +87,30 @@ const getEgressClient = async () => {
|
|
|
78
87
|
const { url, apiKey, apiSecret } = (await config()).jams.livekit;
|
|
79
88
|
return new EgressClient(url, apiKey, apiSecret);
|
|
80
89
|
};
|
|
90
|
+
export const stopEgress = async (egressId) => {
|
|
91
|
+
const egressClient = await getEgressClient();
|
|
92
|
+
try {
|
|
93
|
+
await egressClient.stopEgress(egressId);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// LiveKit egress can time out or already be stopped/failed; the user-facing
|
|
97
|
+
// stop action should not fail because of that.
|
|
98
|
+
}
|
|
99
|
+
};
|
|
81
100
|
export const startRecording = async (profile, jamPost, recurrenceId) => {
|
|
82
101
|
const jamId = jamPost.id;
|
|
83
102
|
const roomName = jamRoomName(jamPost.id, recurrenceId);
|
|
84
103
|
const recordingId = uuidv7();
|
|
85
|
-
//
|
|
86
|
-
//
|
|
104
|
+
// A leftover `active` row may still be uploading after stop. Finalize it so
|
|
105
|
+
// Complete can succeed, and stop its egress so this start is the only live
|
|
106
|
+
// take.
|
|
87
107
|
const staleRecording = await findActiveRecording(jamPost);
|
|
88
108
|
if (staleRecording) {
|
|
89
109
|
await cancelRecordingAutoStop(staleRecording.id);
|
|
90
|
-
|
|
110
|
+
if (staleRecording.egressId) {
|
|
111
|
+
void stopEgress(staleRecording.egressId);
|
|
112
|
+
}
|
|
113
|
+
await finalizeJamRecording(staleRecording.id);
|
|
91
114
|
}
|
|
92
115
|
let recording = (await allpeepDb().then(({ db }) => connectRecording(db, profile, jamPost, {
|
|
93
116
|
id: recordingId,
|
|
@@ -128,7 +151,7 @@ export const startRecording = async (profile, jamPost, recurrenceId) => {
|
|
|
128
151
|
profileId: profile.id,
|
|
129
152
|
recurrenceId,
|
|
130
153
|
});
|
|
131
|
-
await roomService().then(async (rs) => rs
|
|
154
|
+
await roomService().then(async (rs) => rs?.sendData(roomName, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
132
155
|
// BullMQ delayed job survives API/worker restarts (unlike setTimeout).
|
|
133
156
|
await scheduleRecordingAutoStop(jamId, persistedRecordingId);
|
|
134
157
|
return recording;
|
|
@@ -150,7 +173,7 @@ const assertJamRoomOpen = async (jamId) => {
|
|
|
150
173
|
}
|
|
151
174
|
};
|
|
152
175
|
const emitJamEvent = async (jamId, jamEvent) => {
|
|
153
|
-
await roomService().then(async (rs) => rs
|
|
176
|
+
await roomService().then(async (rs) => rs?.sendData(jamId, encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
154
177
|
};
|
|
155
178
|
export const startRtmpStream = async (profile, jamPost, rtmpUrl, destinationHost) => {
|
|
156
179
|
await assertLivekitConfigured();
|
|
@@ -198,17 +221,7 @@ export const stopRtmpStream = async (jamPost) => {
|
|
|
198
221
|
profileId: stream.profile.id,
|
|
199
222
|
});
|
|
200
223
|
await emitJamEvent(jamPost.id, jamEvent);
|
|
201
|
-
return
|
|
202
|
-
};
|
|
203
|
-
export const stopEgress = async (egressId) => {
|
|
204
|
-
const egressClient = await getEgressClient();
|
|
205
|
-
try {
|
|
206
|
-
await egressClient.stopEgress(egressId);
|
|
207
|
-
}
|
|
208
|
-
catch (_a) {
|
|
209
|
-
// LiveKit egress can time out or already be stopped/failed; the user-facing
|
|
210
|
-
// stop action should not fail because of that.
|
|
211
|
-
}
|
|
224
|
+
return { ...stream, status: 'completed' };
|
|
212
225
|
};
|
|
213
226
|
export const stopRecording = async (jamPost, recurrenceId) => {
|
|
214
227
|
const jamRecording = await findActiveRecording(jamPost);
|
|
@@ -230,12 +243,14 @@ export const stopRecording = async (jamPost, recurrenceId) => {
|
|
|
230
243
|
profileId: jamRecording.profile.id,
|
|
231
244
|
recurrenceId,
|
|
232
245
|
});
|
|
233
|
-
await roomService().then(async (rs) => rs
|
|
234
|
-
|
|
246
|
+
await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamPost.id, recurrenceId), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
247
|
+
await finalizeJamRecording(jamRecording.id);
|
|
248
|
+
return { ...jamRecording, status: 'finalizing' };
|
|
235
249
|
};
|
|
236
250
|
/**
|
|
237
|
-
* Stops leftover egress and deletes
|
|
238
|
-
*
|
|
251
|
+
* Stops leftover egress and deletes an egress-only LiveKit room.
|
|
252
|
+
* Do not call this for a room with zero participants — that room is still
|
|
253
|
+
* inside emptyTimeout or departureTimeout. Safe to call repeatedly.
|
|
239
254
|
*/
|
|
240
255
|
export const reclaimOrphanJamRoom = async (jam, roomName = jam.id) => {
|
|
241
256
|
try {
|
|
@@ -252,7 +267,7 @@ export const reclaimOrphanJamRoom = async (jam, roomName = jam.id) => {
|
|
|
252
267
|
}
|
|
253
268
|
try {
|
|
254
269
|
const rs = await roomService();
|
|
255
|
-
await
|
|
270
|
+
await rs?.deleteRoom(roomName);
|
|
256
271
|
}
|
|
257
272
|
catch (e) {
|
|
258
273
|
log.warn(`Failed to delete orphan jam room ${roomName}: ${e.message}`);
|
|
@@ -265,38 +280,40 @@ export const finishRecording = async (jamRecording) => {
|
|
|
265
280
|
type: 'recordStop',
|
|
266
281
|
profileId: jamRecording.profile.id,
|
|
267
282
|
});
|
|
268
|
-
await roomService().then(async (rs) => rs
|
|
283
|
+
await roomService().then(async (rs) => rs?.sendData(jamRoomName(jamRecording.post.id), encoder.encode(JSON.stringify(jamEvent)), DataPacket_Kind.LOSSY, {}));
|
|
269
284
|
};
|
|
270
285
|
export const jamState = async (jam, hideParticipants, recurrenceId) => {
|
|
286
|
+
const inactive = { participants: [], active: false };
|
|
271
287
|
const rs = await roomService();
|
|
272
288
|
const roomName = jamRoomName(jam.id, recurrenceId);
|
|
273
289
|
if (rs === undefined) {
|
|
274
|
-
return
|
|
275
|
-
participants: [],
|
|
276
|
-
active: false,
|
|
277
|
-
};
|
|
290
|
+
return inactive;
|
|
278
291
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
292
|
+
try {
|
|
293
|
+
const room = await rs
|
|
294
|
+
.listRooms([roomName])
|
|
295
|
+
.then((rooms) => rooms.find((r) => r.name === roomName));
|
|
296
|
+
if (!room) {
|
|
297
|
+
return inactive;
|
|
298
|
+
}
|
|
299
|
+
// No one has joined yet, or the last person just left. Leave the room
|
|
300
|
+
// for LiveKit's empty/departure timeout so a host on "Connecting" is
|
|
301
|
+
// not kicked back to the lobby.
|
|
302
|
+
if (!room.numParticipants) {
|
|
303
|
+
return inactive;
|
|
304
|
+
}
|
|
305
|
+
const participants = await listParticipantIds(roomName);
|
|
306
|
+
if (shouldReclaimJamRoom(room.numParticipants, participants.length)) {
|
|
307
|
+
void reclaimOrphanJamRoom(jam, roomName);
|
|
308
|
+
return inactive;
|
|
309
|
+
}
|
|
283
310
|
return {
|
|
284
|
-
participants: [],
|
|
285
|
-
active:
|
|
311
|
+
participants: hideParticipants ? [] : participants,
|
|
312
|
+
active: true,
|
|
286
313
|
};
|
|
287
314
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
// stops appearing under Live jams.
|
|
292
|
-
void reclaimOrphanJamRoom(jam, roomName);
|
|
293
|
-
return {
|
|
294
|
-
participants: [],
|
|
295
|
-
active: false,
|
|
296
|
-
};
|
|
315
|
+
catch (e) {
|
|
316
|
+
log.warn(`Failed to read jam state for ${roomName}: ${e.message}`);
|
|
317
|
+
return inactive;
|
|
297
318
|
}
|
|
298
|
-
return {
|
|
299
|
-
participants: hideParticipants ? [] : participants,
|
|
300
|
-
active: true,
|
|
301
|
-
};
|
|
302
319
|
};
|
package/dist/jams/mapping.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
|
|
|
42
42
|
}, JamEvent, JamEvent>;
|
|
43
43
|
export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
|
|
44
44
|
export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
45
|
-
status: "active" | "completed" | "failed" | "requested";
|
|
45
|
+
status: "active" | "completed" | "failed" | "requested" | "finalizing";
|
|
46
46
|
kind?: "file" | "rtmp" | undefined;
|
|
47
47
|
destinationHost?: string | undefined;
|
|
48
48
|
egressId?: string | undefined;
|
|
@@ -76,7 +76,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
76
76
|
updatedAt: string;
|
|
77
77
|
deletedAt?: string | null | undefined;
|
|
78
78
|
} & {
|
|
79
|
-
status: "active" | "completed" | "failed" | "requested";
|
|
79
|
+
status: "active" | "completed" | "failed" | "requested" | "finalizing";
|
|
80
80
|
kind?: "file" | "rtmp" | undefined;
|
|
81
81
|
destinationHost?: string | undefined;
|
|
82
82
|
egressId?: string | undefined;
|
|
@@ -112,7 +112,7 @@ export declare const jamRecordingsMapping: import("../db/pg/map").Mapping<{
|
|
|
112
112
|
updatedAt: string;
|
|
113
113
|
deletedAt?: string | null | undefined;
|
|
114
114
|
} & {
|
|
115
|
-
status: "active" | "completed" | "failed" | "requested";
|
|
115
|
+
status: "active" | "completed" | "failed" | "requested" | "finalizing";
|
|
116
116
|
kind?: "file" | "rtmp" | undefined;
|
|
117
117
|
destinationHost?: string | undefined;
|
|
118
118
|
egressId?: string | undefined;
|
package/dist/jams/mutations.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const updateJamRecording: (recordingId: string, recording: Partia
|
|
|
5
5
|
updatedAt: string;
|
|
6
6
|
deletedAt?: string | null | undefined;
|
|
7
7
|
} & {
|
|
8
|
-
status: "active" | "completed" | "failed" | "requested";
|
|
8
|
+
status: "active" | "completed" | "failed" | "requested" | "finalizing";
|
|
9
9
|
kind?: "file" | "rtmp" | undefined;
|
|
10
10
|
destinationHost?: string | undefined;
|
|
11
11
|
egressId?: string | undefined;
|