mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-15 18:49:21 +00:00
refactor widget hangup procedure
Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
@@ -201,22 +201,6 @@ export const GroupCallView: FC<Props> = ({
|
|||||||
const [leaveError, setLeaveError] = useState<Error | undefined>(undefined);
|
const [leaveError, setLeaveError] = useState<Error | undefined>(undefined);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const widgetPostHangupProcedure = async (): Promise<void> => {
|
|
||||||
if (!widget) {
|
|
||||||
logger.warn("called widgetPostHangupProcedure without a widget.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// we need to wait until the callEnded event is tracked on posthog.
|
|
||||||
// Otherwise the iFrame gets killed before the callEnded event got tracked.
|
|
||||||
await new Promise((resolve) => window.setTimeout(resolve, 10)); // 10ms
|
|
||||||
widget.api.setAlwaysOnScreen(false);
|
|
||||||
PosthogAnalytics.instance.logout();
|
|
||||||
|
|
||||||
// we will always send the hangup event after the memberships have been updated
|
|
||||||
// calling leaveRTCSession.
|
|
||||||
widget.api.transport.send(ElementWidgetActions.HangupCall, {});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onLeave = useCallback(
|
const onLeave = useCallback(
|
||||||
async (leaveError?: Error) => {
|
async (leaveError?: Error) => {
|
||||||
setLeaveError(leaveError);
|
setLeaveError(leaveError);
|
||||||
@@ -232,9 +216,6 @@ export const GroupCallView: FC<Props> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
await leaveRTCSession(rtcSession);
|
await leaveRTCSession(rtcSession);
|
||||||
if (widget) {
|
|
||||||
widgetPostHangupProcedure();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isPasswordlessUser &&
|
!isPasswordlessUser &&
|
||||||
@@ -254,7 +235,6 @@ export const GroupCallView: FC<Props> = ({
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
widget!.api.transport.reply(ev.detail, {});
|
widget!.api.transport.reply(ev.detail, {});
|
||||||
await leaveRTCSession(rtcSession);
|
await leaveRTCSession(rtcSession);
|
||||||
widgetPostHangupProcedure();
|
|
||||||
};
|
};
|
||||||
widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup);
|
widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup);
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
|||||||
import { PosthogAnalytics } from "./analytics/PosthogAnalytics";
|
import { PosthogAnalytics } from "./analytics/PosthogAnalytics";
|
||||||
import { LivekitFocus } from "./livekit/LivekitFocus";
|
import { LivekitFocus } from "./livekit/LivekitFocus";
|
||||||
import { Config } from "./config/Config";
|
import { Config } from "./config/Config";
|
||||||
|
import { ElementWidgetActions, WidgetHelpers, widget } from "./widget";
|
||||||
|
|
||||||
function makeFocus(livekitAlias: string): LivekitFocus {
|
function makeFocus(livekitAlias: string): LivekitFocus {
|
||||||
const urlFromConf = Config.get().livekit!.livekit_service_url;
|
const urlFromConf = Config.get().livekit!.livekit_service_url;
|
||||||
@@ -47,9 +48,25 @@ export function enterRTCSession(rtcSession: MatrixRTCSession): void {
|
|||||||
rtcSession.joinRoomSession([makeFocus(livekitAlias)]);
|
rtcSession.joinRoomSession([makeFocus(livekitAlias)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const widgetPostHangupProcedure = async (
|
||||||
|
widget: WidgetHelpers,
|
||||||
|
): Promise<void> => {
|
||||||
|
// we need to wait until the callEnded event is tracked on posthog.
|
||||||
|
// Otherwise the iFrame gets killed before the callEnded event got tracked.
|
||||||
|
await new Promise((resolve) => window.setTimeout(resolve, 10)); // 10ms
|
||||||
|
widget.api.setAlwaysOnScreen(false);
|
||||||
|
PosthogAnalytics.instance.logout();
|
||||||
|
|
||||||
|
// we will always send the hangup event after the memberships have been updated
|
||||||
|
// calling leaveRTCSession.
|
||||||
|
widget.api.transport.send(ElementWidgetActions.HangupCall, {});
|
||||||
|
};
|
||||||
|
|
||||||
export async function leaveRTCSession(
|
export async function leaveRTCSession(
|
||||||
rtcSession: MatrixRTCSession,
|
rtcSession: MatrixRTCSession,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
//groupCallOTelMembership?.onLeaveCall();
|
|
||||||
await rtcSession.leaveRoomSession();
|
await rtcSession.leaveRoomSession();
|
||||||
|
if (widget) {
|
||||||
|
await widgetPostHangupProcedure(widget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export interface ScreenshareStartData {
|
|||||||
desktopCapturerSourceId: string;
|
desktopCapturerSourceId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WidgetHelpers {
|
export interface WidgetHelpers {
|
||||||
api: WidgetApi;
|
api: WidgetApi;
|
||||||
lazyActions: LazyEventEmitter;
|
lazyActions: LazyEventEmitter;
|
||||||
client: Promise<MatrixClient>;
|
client: Promise<MatrixClient>;
|
||||||
|
|||||||
Reference in New Issue
Block a user