Get new group calls working
This commit is contained in:
parent
5e4736eba5
commit
b3325faeeb
3 changed files with 24 additions and 35 deletions
|
@ -47,32 +47,32 @@ async function initClient(clientOptions, guest) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchRoom(client, roomIdOrAlias, timeout = 5000) {
|
export async function fetchGroupCall(client, roomIdOrAlias, timeout = 5000) {
|
||||||
const { roomId } = await client.joinRoom(roomIdOrAlias);
|
const { roomId } = await client.joinRoom(roomIdOrAlias);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let timeoutId;
|
let timeoutId;
|
||||||
|
|
||||||
function onRoom(room) {
|
function onGroupCallIncoming(groupCall) {
|
||||||
if (room && room.roomId === roomId) {
|
if (groupCall && groupCall.room.roomId === roomId) {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
client.removeListener("Room", onRoom);
|
client.removeListener("GroupCall.incoming", onGroupCallIncoming);
|
||||||
resolve(room);
|
resolve(groupCall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const room = client.getRoom(roomId);
|
const groupCall = client.getGroupCallForRoom(roomId);
|
||||||
|
|
||||||
if (room) {
|
if (groupCall) {
|
||||||
resolve(room);
|
resolve(groupCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on("Room", onRoom);
|
client.on("GroupCall.incoming", onGroupCallIncoming);
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
client.removeListener("Room", onRoom);
|
client.removeListener("GroupCall.incoming", onGroupCallIncoming);
|
||||||
reject(new Error("Fetching room timed out."));
|
reject(new Error("Fetching group call timed out."));
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
10
src/Home.jsx
10
src/Home.jsx
|
@ -22,6 +22,10 @@ import ColorHash from "color-hash";
|
||||||
import styles from "./Home.module.css";
|
import styles from "./Home.module.css";
|
||||||
import { FieldRow, InputField, Button, ErrorMessage } from "./Input";
|
import { FieldRow, InputField, Button, ErrorMessage } from "./Input";
|
||||||
import { Center, Content, Modal } from "./Layout";
|
import { Center, Content, Modal } from "./Layout";
|
||||||
|
import {
|
||||||
|
GroupCallIntent,
|
||||||
|
GroupCallType,
|
||||||
|
} from "matrix-js-sdk/src/browser-index";
|
||||||
|
|
||||||
const colorHash = new ColorHash({ lightness: 0.3 });
|
const colorHash = new ColorHash({ lightness: 0.3 });
|
||||||
|
|
||||||
|
@ -75,6 +79,12 @@ export function Home({ client, onLogout }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await client.createGroupCall(
|
||||||
|
room_id,
|
||||||
|
GroupCallType.Video,
|
||||||
|
GroupCallIntent.Prompt
|
||||||
|
);
|
||||||
|
|
||||||
history.push(`/room/${room_id}`);
|
history.push(`/room/${room_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
src/Room.jsx
27
src/Room.jsx
|
@ -25,11 +25,7 @@ import {
|
||||||
} from "./RoomButton";
|
} from "./RoomButton";
|
||||||
import { Header, LeftNav, RightNav, CenterNav } from "./Header";
|
import { Header, LeftNav, RightNav, CenterNav } from "./Header";
|
||||||
import { Button, ErrorMessage } from "./Input";
|
import { Button, ErrorMessage } from "./Input";
|
||||||
import {
|
import { GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
GroupCallIntent,
|
|
||||||
GroupCallState,
|
|
||||||
GroupCallType,
|
|
||||||
} from "matrix-js-sdk/src/webrtc/groupCall";
|
|
||||||
import VideoGrid, {
|
import VideoGrid, {
|
||||||
useVideoGridLayout,
|
useVideoGridLayout,
|
||||||
} from "matrix-react-sdk/src/components/views/voip/GroupCallView/VideoGrid";
|
} from "matrix-react-sdk/src/components/views/voip/GroupCallView/VideoGrid";
|
||||||
|
@ -37,7 +33,7 @@ import "matrix-react-sdk/res/css/views/voip/GroupCallView/_VideoGrid.scss";
|
||||||
import { useGroupCall } from "matrix-react-sdk/src/hooks/useGroupCall";
|
import { useGroupCall } from "matrix-react-sdk/src/hooks/useGroupCall";
|
||||||
import { useCallFeed } from "matrix-react-sdk/src/hooks/useCallFeed";
|
import { useCallFeed } from "matrix-react-sdk/src/hooks/useCallFeed";
|
||||||
import { useMediaStream } from "matrix-react-sdk/src/hooks/useMediaStream";
|
import { useMediaStream } from "matrix-react-sdk/src/hooks/useMediaStream";
|
||||||
import { fetchRoom } from "./ConferenceCallManagerHooks";
|
import { fetchGroupCall } from "./ConferenceCallManagerHooks";
|
||||||
|
|
||||||
function useLoadGroupCall(client, roomId) {
|
function useLoadGroupCall(client, roomId) {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
|
@ -47,25 +43,8 @@ function useLoadGroupCall(client, roomId) {
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function load() {
|
|
||||||
await fetchRoom(client, roomId);
|
|
||||||
|
|
||||||
let groupCall = client.getGroupCallForRoom(roomId);
|
|
||||||
|
|
||||||
if (!groupCall) {
|
|
||||||
groupCall = await client.createGroupCall(
|
|
||||||
roomId,
|
|
||||||
GroupCallType.Video,
|
|
||||||
GroupCallIntent.Prompt
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return groupCall;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState({ loading: true });
|
setState({ loading: true });
|
||||||
|
fetchGroupCall(client, roomId, 30000)
|
||||||
load()
|
|
||||||
.then((groupCall) => setState({ loading: false, groupCall }))
|
.then((groupCall) => setState({ loading: false, groupCall }))
|
||||||
.catch((error) => setState({ loading: false, error }));
|
.catch((error) => setState({ loading: false, error }));
|
||||||
}, [roomId]);
|
}, [roomId]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue