2023-08-18 16:03:21 +08:00
|
|
|
/*
|
|
|
|
Copyright 2023 New Vector Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
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 { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
|
|
|
|
|
|
|
import { PosthogAnalytics } from "./analytics/PosthogAnalytics";
|
|
|
|
import { LivekitFocus } from "./livekit/LivekitFocus";
|
|
|
|
import { Config } from "./config/Config";
|
|
|
|
|
|
|
|
function makeFocus(livekitAlias: string): LivekitFocus {
|
|
|
|
const urlFromConf = Config.get().livekit!.livekit_service_url;
|
|
|
|
if (!urlFromConf) {
|
|
|
|
throw new Error("No livekit_service_url is configured!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: "livekit",
|
|
|
|
livekit_service_url: urlFromConf,
|
|
|
|
livekit_alias: livekitAlias,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-09-23 06:05:13 +08:00
|
|
|
export function enterRTCSession(rtcSession: MatrixRTCSession): void {
|
2023-08-18 16:03:21 +08:00
|
|
|
PosthogAnalytics.instance.eventCallEnded.cacheStartCall(new Date());
|
|
|
|
PosthogAnalytics.instance.eventCallStarted.track(rtcSession.room.roomId);
|
|
|
|
|
|
|
|
// This must be called before we start trying to join the call, as we need to
|
|
|
|
// have started tracking by the time calls start getting created.
|
|
|
|
//groupCallOTelMembership?.onJoinCall();
|
|
|
|
|
2023-10-10 20:14:39 +08:00
|
|
|
// right now we assume everything is a room-scoped call
|
2023-08-18 16:03:21 +08:00
|
|
|
const livekitAlias = rtcSession.room.roomId;
|
|
|
|
|
|
|
|
rtcSession.joinRoomSession([makeFocus(livekitAlias)]);
|
|
|
|
}
|
|
|
|
|
2023-10-05 00:27:07 +08:00
|
|
|
export async function leaveRTCSession(
|
|
|
|
rtcSession: MatrixRTCSession
|
|
|
|
): Promise<void> {
|
2023-08-18 16:03:21 +08:00
|
|
|
//groupCallOTelMembership?.onLeaveCall();
|
2023-10-05 00:27:07 +08:00
|
|
|
await rtcSession.leaveRoomSession();
|
2023-08-18 16:03:21 +08:00
|
|
|
}
|