Merge pull request #774 from vector-im/SimonBrandner/task/refactor-calls
Don't expose `calls` on `GroupCall`
This commit is contained in:
commit
e6e18dd3f9
3 changed files with 40 additions and 43 deletions
|
@ -45,7 +45,7 @@
|
||||||
"i18next": "^21.10.0",
|
"i18next": "^21.10.0",
|
||||||
"i18next-browser-languagedetector": "^6.1.8",
|
"i18next-browser-languagedetector": "^6.1.8",
|
||||||
"i18next-http-backend": "^1.4.4",
|
"i18next-http-backend": "^1.4.4",
|
||||||
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#9d3ac66cf847fe8cb0359d64e1f1d67902b982a1",
|
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#2c8eece5ca5333c6e6a14e8ed53f359ed0e9e9bf",
|
||||||
"matrix-widget-api": "^1.0.0",
|
"matrix-widget-api": "^1.0.0",
|
||||||
"mermaid": "^8.13.8",
|
"mermaid": "^8.13.8",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
|
|
|
@ -23,12 +23,7 @@ import {
|
||||||
GroupCallUnknownDeviceError,
|
GroupCallUnknownDeviceError,
|
||||||
GroupCallError,
|
GroupCallError,
|
||||||
} from "matrix-js-sdk/src/webrtc/groupCall";
|
} from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
import {
|
import { CallFeed, CallFeedEvent } from "matrix-js-sdk/src/webrtc/callFeed";
|
||||||
CallState,
|
|
||||||
MatrixCall,
|
|
||||||
CallEvent,
|
|
||||||
} from "matrix-js-sdk/src/webrtc/call";
|
|
||||||
import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
|
|
||||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { IWidgetApiRequest } from "matrix-widget-api";
|
import { IWidgetApiRequest } from "matrix-widget-api";
|
||||||
|
@ -96,29 +91,20 @@ function getParticipants(
|
||||||
const participants = new Map<RoomMember, Map<string, ParticipantInfo>>();
|
const participants = new Map<RoomMember, Map<string, ParticipantInfo>>();
|
||||||
|
|
||||||
for (const [member, participantsStateMap] of groupCall.participants) {
|
for (const [member, participantsStateMap] of groupCall.participants) {
|
||||||
const callMap = groupCall.calls.get(member);
|
|
||||||
const participantInfoMap = new Map<string, ParticipantInfo>();
|
const participantInfoMap = new Map<string, ParticipantInfo>();
|
||||||
participants.set(member, participantInfoMap);
|
participants.set(member, participantInfoMap);
|
||||||
|
|
||||||
for (const [deviceId, participant] of participantsStateMap) {
|
for (const [deviceId, participant] of participantsStateMap) {
|
||||||
const call = callMap?.get(deviceId);
|
|
||||||
const feed = groupCall.userMediaFeeds.find(
|
const feed = groupCall.userMediaFeeds.find(
|
||||||
(f) => f.userId === member.userId && f.deviceId === deviceId
|
(f) => f.userId === member.userId && f.deviceId === deviceId
|
||||||
);
|
);
|
||||||
|
|
||||||
let connectionState = ConnectionState.EstablishingCall;
|
|
||||||
if (feed?.isLocal()) {
|
|
||||||
connectionState = ConnectionState.Connected;
|
|
||||||
} else if (call !== undefined) {
|
|
||||||
if (call.state === CallState.Connected) {
|
|
||||||
connectionState = ConnectionState.Connected;
|
|
||||||
} else if (call.state === CallState.Connecting) {
|
|
||||||
connectionState = ConnectionState.WaitMedia;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
participantInfoMap.set(deviceId, {
|
participantInfoMap.set(deviceId, {
|
||||||
connectionState,
|
connectionState: feed
|
||||||
|
? feed.connected
|
||||||
|
? ConnectionState.Connected
|
||||||
|
: ConnectionState.WaitMedia
|
||||||
|
: ConnectionState.EstablishingCall,
|
||||||
presenter: participant.screensharing,
|
presenter: participant.screensharing,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -188,19 +174,49 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prevUserMediaFeeds = new Set<CallFeed>();
|
||||||
|
|
||||||
function onUserMediaFeedsChanged(userMediaFeeds: CallFeed[]): void {
|
function onUserMediaFeedsChanged(userMediaFeeds: CallFeed[]): void {
|
||||||
|
for (const feed of prevUserMediaFeeds) {
|
||||||
|
feed.off(CallFeedEvent.ConnectedChanged, onConnectedChanged);
|
||||||
|
}
|
||||||
|
prevUserMediaFeeds.clear();
|
||||||
|
|
||||||
|
for (const feed of userMediaFeeds) {
|
||||||
|
feed.on(CallFeedEvent.ConnectedChanged, onConnectedChanged);
|
||||||
|
prevUserMediaFeeds.add(feed);
|
||||||
|
}
|
||||||
|
|
||||||
updateState({
|
updateState({
|
||||||
userMediaFeeds: [...userMediaFeeds],
|
userMediaFeeds: [...userMediaFeeds],
|
||||||
participants: getParticipants(groupCall),
|
participants: getParticipants(groupCall),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prevScreenshareFeeds = new Set<CallFeed>();
|
||||||
|
|
||||||
function onScreenshareFeedsChanged(screenshareFeeds: CallFeed[]): void {
|
function onScreenshareFeedsChanged(screenshareFeeds: CallFeed[]): void {
|
||||||
|
for (const feed of prevScreenshareFeeds) {
|
||||||
|
feed.off(CallFeedEvent.ConnectedChanged, onConnectedChanged);
|
||||||
|
}
|
||||||
|
prevScreenshareFeeds.clear();
|
||||||
|
|
||||||
|
for (const feed of screenshareFeeds) {
|
||||||
|
feed.on(CallFeedEvent.ConnectedChanged, onConnectedChanged);
|
||||||
|
prevScreenshareFeeds.add(feed);
|
||||||
|
}
|
||||||
|
|
||||||
updateState({
|
updateState({
|
||||||
screenshareFeeds: [...screenshareFeeds],
|
screenshareFeeds: [...screenshareFeeds],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onConnectedChanged(connected: boolean): void {
|
||||||
|
updateState({
|
||||||
|
participants: getParticipants(groupCall),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onActiveSpeakerChanged(activeSpeaker: CallFeed | undefined): void {
|
function onActiveSpeakerChanged(activeSpeaker: CallFeed | undefined): void {
|
||||||
updateState({
|
updateState({
|
||||||
activeSpeaker: activeSpeaker ?? null,
|
activeSpeaker: activeSpeaker ?? null,
|
||||||
|
@ -228,25 +244,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevCalls = new Set<MatrixCall>();
|
function onCallsChanged(): void {
|
||||||
|
|
||||||
function onCallState(): void {
|
|
||||||
updateState({ participants: getParticipants(groupCall) });
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCallsChanged(
|
|
||||||
calls: Map<RoomMember, Map<string, MatrixCall>>
|
|
||||||
): void {
|
|
||||||
for (const call of prevCalls) call.off(CallEvent.State, onCallState);
|
|
||||||
prevCalls.clear();
|
|
||||||
|
|
||||||
for (const deviceMap of calls.values()) {
|
|
||||||
for (const call of deviceMap.values()) {
|
|
||||||
call.on(CallEvent.State, onCallState);
|
|
||||||
prevCalls.add(call);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateState({ participants: getParticipants(groupCall) });
|
updateState({ participants: getParticipants(groupCall) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10266,12 +10266,11 @@ matrix-events-sdk@0.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd"
|
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd"
|
||||||
integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==
|
integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==
|
||||||
|
|
||||||
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#9d3ac66cf847fe8cb0359d64e1f1d67902b982a1":
|
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#76b255bdd89d2fa486537b5a2d530226bc280a6e":
|
||||||
version "21.2.0"
|
version "21.2.0"
|
||||||
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/9d3ac66cf847fe8cb0359d64e1f1d67902b982a1"
|
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/76b255bdd89d2fa486537b5a2d530226bc280a6e"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.12.5"
|
"@babel/runtime" "^7.12.5"
|
||||||
"@types/sdp-transform" "^2.4.5"
|
|
||||||
another-json "^0.2.0"
|
another-json "^0.2.0"
|
||||||
bs58 "^5.0.0"
|
bs58 "^5.0.0"
|
||||||
content-type "^1.0.4"
|
content-type "^1.0.4"
|
||||||
|
|
Loading…
Reference in a new issue