Fix the call type selector
This commit is contained in:
parent
fc0a3f38ac
commit
ba4258aa89
3 changed files with 43 additions and 6 deletions
|
@ -56,13 +56,13 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
|
|||
const data = new FormData(e.target as HTMLFormElement);
|
||||
const roomNameData = data.get("callName");
|
||||
const roomName = typeof roomNameData === "string" ? roomNameData : "";
|
||||
// const ptt = callType === CallType.Radio;
|
||||
const ptt = callType === CallType.Radio;
|
||||
|
||||
async function submit() {
|
||||
setError(undefined);
|
||||
setLoading(true);
|
||||
|
||||
const [roomIdOrAlias] = await createRoom(client, roomName);
|
||||
const [roomIdOrAlias] = await createRoom(client, roomName, ptt);
|
||||
|
||||
if (roomIdOrAlias) {
|
||||
history.push(`/room/${roomIdOrAlias}`);
|
||||
|
@ -82,7 +82,7 @@ export function RegisteredView({ client, isPasswordlessUser }: Props) {
|
|||
}
|
||||
});
|
||||
},
|
||||
[client, history, modalState]
|
||||
[client, history, modalState, callType]
|
||||
);
|
||||
|
||||
const recentRooms = useGroupCallRooms(client);
|
||||
|
|
|
@ -17,7 +17,12 @@ import { Visibility, Preset } from "matrix-js-sdk/src/@types/partials";
|
|||
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
|
||||
import { WidgetApi } from "matrix-widget-api";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import {
|
||||
GroupCallIntent,
|
||||
GroupCallType,
|
||||
} from "matrix-js-sdk/src/webrtc/groupCall";
|
||||
|
||||
import type { Room } from "matrix-js-sdk/src/models/room";
|
||||
import IndexedDBWorker from "./IndexedDBWorker?worker";
|
||||
import { getRoomParams } from "./room/useRoomParams";
|
||||
|
||||
|
@ -290,9 +295,10 @@ export function isLocalRoomId(roomId: string): boolean {
|
|||
|
||||
export async function createRoom(
|
||||
client: MatrixClient,
|
||||
name: string
|
||||
name: string,
|
||||
ptt: boolean
|
||||
): Promise<[string, string]> {
|
||||
const result = await client.createRoom({
|
||||
const createPromise = client.createRoom({
|
||||
visibility: Visibility.Private,
|
||||
preset: Preset.PublicChat,
|
||||
name,
|
||||
|
@ -322,6 +328,36 @@ export async function createRoom(
|
|||
},
|
||||
});
|
||||
|
||||
// Wait for the room to arrive
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const onRoom = async (room: Room) => {
|
||||
if (room.roomId === (await createPromise).room_id) {
|
||||
resolve();
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
createPromise.catch((e) => {
|
||||
reject(e);
|
||||
cleanUp();
|
||||
});
|
||||
|
||||
const cleanUp = () => {
|
||||
client.off(ClientEvent.Room, onRoom);
|
||||
};
|
||||
client.on(ClientEvent.Room, onRoom);
|
||||
});
|
||||
|
||||
const result = await createPromise;
|
||||
|
||||
console.log(`Creating ${ptt ? "PTT" : "video"} group call room`);
|
||||
|
||||
await client.createGroupCall(
|
||||
result.room_id,
|
||||
ptt ? GroupCallType.Voice : GroupCallType.Video,
|
||||
ptt,
|
||||
GroupCallIntent.Room
|
||||
);
|
||||
|
||||
return [fullAliasFromRoomName(name, client), result.room_id];
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ export const useLoadGroupCall = (
|
|||
// The room doesn't exist, but we can create it
|
||||
const [, roomId] = await createRoom(
|
||||
client,
|
||||
roomNameFromRoomId(roomIdOrAlias)
|
||||
roomNameFromRoomId(roomIdOrAlias),
|
||||
createPtt
|
||||
);
|
||||
// likewise, wait for the room
|
||||
return await waitForRoom(roomId);
|
||||
|
|
Loading…
Reference in a new issue