Skip to content

Send notification events when starting a call #3248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: livekit
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/rtcSessionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import { PosthogAnalytics } from "./analytics/PosthogAnalytics";
import { Config } from "./config/Config";
import { ElementWidgetActions, widget, type WidgetHelpers } from "./widget";
import { MatrixRTCFocusMissingError } from "./utils/errors.ts";
import { getUrlParams } from "./UrlParams.ts";
import { MatrixRTCFocusMissingError } from "./utils/errors";
import { getUrlParams } from "./UrlParams";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL params should include a flag if it should ring or not.

import { getJoinedNonFunctionalMembers } from "./utils/matrix";

const FOCI_WK_KEY = "org.matrix.msc4143.rtc_foci";

Expand Down Expand Up @@ -94,6 +95,12 @@
// if (focusOtherMembers) preferredFoci.push(focusOtherMembers);
}

function getNotifyType(room: Room): CallNotifyType | undefined {

Check failure on line 98 in src/rtcSessionHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint, format & type check

Cannot find name 'Room'.

Check failure on line 98 in src/rtcSessionHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint, format & type check

Cannot find name 'CallNotifyType'.
if (room.isCallRoom()) return undefined;

Check failure on line 99 in src/rtcSessionHelpers.ts

View workflow job for this annotation

GitHub Actions / Run unit tests

src/rtcSessionHelpers.test.ts > It joins the correct Session

TypeError: room.isCallRoom is not a function ❯ getNotifyType src/rtcSessionHelpers.ts:99:12 ❯ Module.enterRTCSession src/rtcSessionHelpers.ts:126:19 ❯ src/rtcSessionHelpers.test.ts:82:3

Check failure on line 99 in src/rtcSessionHelpers.ts

View workflow job for this annotation

GitHub Actions / Run unit tests

src/rtcSessionHelpers.test.ts > It should not fail with configuration error if homeserver config has livekit url but not fallback

TypeError: room.isCallRoom is not a function ❯ getNotifyType src/rtcSessionHelpers.ts:99:12 ❯ Module.enterRTCSession src/rtcSessionHelpers.ts:126:19 ❯ src/rtcSessionHelpers.test.ts:205:3
if (getJoinedNonFunctionalMembers(room).length === 2) return "ring";
return "notify";
}

export async function enterRTCSession(
rtcSession: MatrixRTCSession,
encryptMedia: boolean,
Expand All @@ -116,6 +123,7 @@
await makePreferredLivekitFoci(rtcSession, livekitAlias),
makeActiveFocus(),
{
notifyType: getNotifyType(rtcSession.room),

Check failure on line 126 in src/rtcSessionHelpers.ts

View workflow job for this annotation

GitHub Actions / Lint, format & type check

Object literal may only specify known properties, and 'notifyType' does not exist in type 'JoinSessionConfig'.
useNewMembershipManager,
manageMediaKeys: encryptMedia,
...(useDeviceSessionMemberEvents !== undefined && {
Expand Down
24 changes: 24 additions & 0 deletions src/utils/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
IndexedDBStore,
MemoryStore,
Preset,
type RoomMember,
UNSTABLE_ELEMENT_FUNCTIONAL_USERS,
Visibility,
Direction,
} from "matrix-js-sdk";
import { type ISyncStateData, type SyncState } from "matrix-js-sdk/lib/sync";
import { logger } from "matrix-js-sdk/lib/logger";
Expand Down Expand Up @@ -336,6 +339,27 @@ export function getRelativeRoomUrl(
return `/room/#${roomPart}?${generateUrlSearchParams(roomId, encryptionSystem, viaServers).toString()}`;
}

/**
* Returns all room members that are non-functional (all actual room members).
* A functional user is a user that is not a real user, but a bot, assistant, etc.
*/
export function getJoinedNonFunctionalMembers(room: Room): RoomMember[] {
const functionalUsersStateEvent = room
.getLiveTimeline()
.getState(Direction.Forward)
?.getStateEvents(UNSTABLE_ELEMENT_FUNCTIONAL_USERS.name, "");

const functionalMembers = Array.isArray(
functionalUsersStateEvent?.getContent().service_members,
)
? functionalUsersStateEvent.getContent().service_members
: [];

return room
.getJoinedMembers()
.filter((m) => !functionalMembers.includes(m.userId));
}

/**
* Perform a network operation with retries on ConnectionError.
* If the error is not retryable, or the max number of retries is reached, the error is rethrown.
Expand Down
Loading