Skip to content

Commit

Permalink
Replacing MatrixClient with trimmed down RTCClient
Browse files Browse the repository at this point in the history
Signed-off-by: Milton Moura <miltonmoura@gmail.com>
  • Loading branch information
mgcm committed Feb 11, 2025
1 parent c537a36 commit 1237462
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/matrixrtc/EncryptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type MatrixEvent } from "../models/event.ts";
import { type Room } from "../models/room.ts";
import { type EncryptionConfig } from "./MatrixRTCSession.ts";
import { secureRandomBase64Url } from "../randomstring.ts";
import { type EncryptionKeysEventContent } from "./types.ts";
import { RTCClient, type EncryptionKeysEventContent } from "./types.ts";
import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
import { type MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts";
import { type CallMembership } from "./CallMembership.ts";
Expand Down Expand Up @@ -99,7 +99,7 @@ export class EncryptionManager implements IEncryptionManager {
private joinConfig: EncryptionConfig | undefined;

public constructor(
private client: Pick<MatrixClient, "sendEvent" | "getDeviceId" | "getUserId" | "cancelPendingEvent">,
private client: RTCClient,
private room: Pick<Room, "roomId">,
private getMemberships: () => CallMembership[],
private onEncryptionKeysChanged: (
Expand Down
9 changes: 6 additions & 3 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { logger as rootLogger } from "../logger.ts";
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
import { EventTimeline } from "../models/event-timeline.ts";
import { type Room } from "../models/room.ts";
import { type MatrixClient } from "../client.ts";
import { EventType } from "../@types/event.ts";
import { CallMembership } from "./CallMembership.ts";
import { RoomStateEvent } from "../models/room-state.ts";
Expand All @@ -27,6 +26,7 @@ import { KnownMembership } from "../@types/membership.ts";
import { type MatrixEvent } from "../models/event.ts";
import { LegacyMembershipManager, type IMembershipManager } from "./MembershipManager.ts";
import { EncryptionManager, type IEncryptionManager, type Statistics } from "./EncryptionManager.ts";
import { RTCClient } from "./types.ts";

const logger = rootLogger.getChild("MatrixRTCSession");

Expand Down Expand Up @@ -219,14 +219,17 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
/**
* Return the MatrixRTC session for the room, whether there are currently active members or not
*/
public static roomSessionForRoom(client: MatrixClient, room: Room): MatrixRTCSession {
public static roomSessionForRoom(
client: RTCClient,
room: Room): MatrixRTCSession
{
const callMemberships = MatrixRTCSession.callMembershipsForRoom(room);

return new MatrixRTCSession(client, room, callMemberships);
}

private constructor(
private readonly client: MatrixClient,
private readonly client: RTCClient,
public readonly room: Room,
public memberships: CallMembership[],
) {
Expand Down
12 changes: 2 additions & 10 deletions src/matrixrtc/MembershipManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EventType } from "../@types/event.ts";
import { UpdateDelayedEventAction } from "../@types/requests.ts";
import type { MatrixClient } from "../client.ts";
import { HTTPError, MatrixError } from "../http-api/errors.ts";
import { logger } from "../logger.ts";
import { EventTimeline } from "../models/event-timeline.ts";
Expand All @@ -11,6 +10,7 @@ import { type Focus } from "./focus.ts";
import { isLivekitFocusActive } from "./LivekitFocus.ts";
import { type MembershipConfig } from "./MatrixRTCSession.ts";
import { type EmptyObject } from "../@types/common.ts";
import { RTCClient } from "./types.ts";
/**
* This interface defines what a MembershipManager uses and exposes.
* This interface is what we use to write tests and allows to change the actual implementation
Expand Down Expand Up @@ -112,15 +112,7 @@ export class LegacyMembershipManager implements IMembershipManager {
public constructor(
private joinConfig: MembershipConfig | undefined,
private room: Pick<Room, "getLiveTimeline" | "roomId" | "getVersion">,
private client: Pick<
MatrixClient,
| "getUserId"
| "getDeviceId"
| "sendStateEvent"
| "_unstable_sendDelayedEvent"
| "_unstable_sendDelayedStateEvent"
| "_unstable_updateDelayedEvent"
>,
private client: RTCClient,
private getOldestMembership: () => CallMembership | undefined,
) {}

Expand Down
15 changes: 14 additions & 1 deletion src/matrixrtc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { type IMentions } from "../matrix.ts";
import { MatrixClient, type IMentions } from "../matrix.ts";

export type RTCClient = Pick<
MatrixClient,
| "cancelPendingEvent"
| "getUserId"
| "getDeviceId"
| "sendEvent"
| "sendStateEvent"
| "_unstable_sendDelayedEvent"
| "_unstable_sendDelayedStateEvent"
| "_unstable_updateDelayedEvent"
>;

export interface EncryptionKeyEntry {
index: number;
key: string;
Expand Down

0 comments on commit 1237462

Please sign in to comment.