mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
I found our code's internal model of ringing a little overgrown (it had superfluous states like 'unknown') and difficult to extend with metadata or callbacks relating to ring attempts. By modeling ringing instead as a stream of ring attempts, where each attempt has an intent, a recipient, and an eventual outcome (accept/decline/timeout), I find it more natural to work with. This makes room for a future 'try again' callback to allow ringing someone again after a timeout, and also forced me to look for a simpler solution to the duplicate leave sound effects. I exposed the intent of the ringing attempt to the call UI so I can later use it in the header.
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { type RTCCallIntent } from "matrix-js-sdk/lib/matrixrtc";
|
|
|
|
import { type Behavior } from "../Behavior";
|
|
import {
|
|
type BaseMediaInputs,
|
|
type BaseMediaViewModel,
|
|
createBaseMedia,
|
|
} from "./MediaViewModel";
|
|
|
|
/**
|
|
* Media representing a user who is not yet part of the call — one that we are
|
|
* *ringing*.
|
|
*/
|
|
export interface RingingMediaViewModel extends BaseMediaViewModel {
|
|
type: "ringing";
|
|
pickupState$: Behavior<"ringing" | "timeout" | "decline">;
|
|
intent: RTCCallIntent;
|
|
}
|
|
|
|
export interface RingingMediaInputs extends BaseMediaInputs {
|
|
pickupState$: Behavior<"ringing" | "timeout" | "decline">;
|
|
intent: RTCCallIntent;
|
|
}
|
|
|
|
export function createRingingMedia({
|
|
pickupState$,
|
|
intent,
|
|
...inputs
|
|
}: RingingMediaInputs): RingingMediaViewModel {
|
|
return {
|
|
...createBaseMedia(inputs),
|
|
type: "ringing",
|
|
pickupState$,
|
|
intent,
|
|
};
|
|
}
|