This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
552 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
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. | ||
*/ | ||
|
||
.mx_CallEvent_wrapper { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
.mx_CallEvent { | ||
padding: 12px; | ||
box-sizing: border-box; | ||
min-height: 60px; | ||
max-width: 600px; | ||
width: 100%; | ||
background-color: $system; | ||
border-radius: 8px; | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: $spacing-8; | ||
|
||
.mx_CallEvent_title { | ||
font-size: $font-15px; | ||
line-height: 24px; /* in px to match the avatar */ | ||
} | ||
|
||
&.mx_CallEvent_inactive .mx_CallEvent_title::before { | ||
display: inline-block; | ||
vertical-align: middle; | ||
content: ''; | ||
background-color: $secondary-content; | ||
mask-image: url('$(res)/img/element-icons/call/video-call.svg'); | ||
mask-size: 16px; | ||
width: 16px; | ||
height: 16px; | ||
margin-right: 8px; | ||
} | ||
|
||
&.mx_CallEvent_active .mx_CallEvent_title { | ||
font-weight: 600; | ||
} | ||
|
||
> .mx_BaseAvatar { | ||
align-self: flex-start; | ||
} | ||
|
||
> .mx_CallEvent_infoRows { | ||
flex-grow: 1; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
gap: $spacing-4; | ||
} | ||
|
||
> .mx_CallEvent_duration { | ||
padding: $spacing-4; | ||
color: $secondary-content; | ||
font-size: $font-12px; | ||
} | ||
|
||
> .mx_CallEvent_button { | ||
box-sizing: border-box; | ||
min-width: 120px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
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 React, { FC, forwardRef, useCallback, useContext, useEffect, useMemo, useState } from "react"; | ||
|
||
import type { MatrixEvent } from "matrix-js-sdk/src/models/event"; | ||
import type { RoomMember } from "matrix-js-sdk/src/models/room-member"; | ||
import { Call, ConnectionState } from "../../../models/Call"; | ||
import { _t } from "../../../languageHandler"; | ||
import { useCall, useConnectionState, useParticipants } from "../../../hooks/useCall"; | ||
import defaultDispatcher from "../../../dispatcher/dispatcher"; | ||
import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; | ||
import { Action } from "../../../dispatcher/actions"; | ||
import type { ButtonEvent } from "../elements/AccessibleButton"; | ||
import MemberAvatar from "../avatars/MemberAvatar"; | ||
import { LiveContentSummary, LiveContentType } from "../rooms/LiveContentSummary"; | ||
import FacePile from "../elements/FacePile"; | ||
import { formatCallTime } from "../../../DateUtils"; | ||
import AccessibleButton from "../elements/AccessibleButton"; | ||
import MatrixClientContext from "../../../contexts/MatrixClientContext"; | ||
|
||
interface CallEventDurationProps { | ||
delta: number; | ||
} | ||
|
||
const CallEventDuration: FC<CallEventDurationProps> = ({ delta }) => { | ||
// Clock desync could lead to a negative duration, so just hide it if that happens | ||
if (delta <= 0) return null; | ||
return <div className="mx_CallEvent_duration">{ formatCallTime(new Date(delta)) }</div>; | ||
}; | ||
|
||
const MAX_FACES = 8; | ||
|
||
interface ActiveCallEventProps { | ||
mxEvent: MatrixEvent; | ||
participants: Set<RoomMember>; | ||
buttonText: string; | ||
buttonKind: string; | ||
onButtonClick: ((ev: ButtonEvent) => void) | null; | ||
} | ||
|
||
const ActiveCallEvent = forwardRef<any, ActiveCallEventProps>( | ||
( | ||
{ | ||
mxEvent, | ||
participants, | ||
buttonText, | ||
buttonKind, | ||
onButtonClick, | ||
}, | ||
ref, | ||
) => { | ||
const senderName = useMemo(() => mxEvent.sender?.name ?? mxEvent.getSender(), [mxEvent]); | ||
|
||
const facePileMembers = useMemo(() => [...participants].slice(0, MAX_FACES), [participants]); | ||
const facePileOverflow = participants.size > facePileMembers.length; | ||
|
||
const [now, setNow] = useState(() => Date.now()); | ||
useEffect(() => { | ||
const timer = setInterval(() => setNow(Date.now()), 1000); | ||
return () => clearInterval(timer); | ||
}, []); | ||
|
||
return <div className="mx_CallEvent_wrapper" ref={ref}> | ||
<div className="mx_CallEvent mx_CallEvent_active"> | ||
<MemberAvatar | ||
member={mxEvent.sender} | ||
fallbackUserId={mxEvent.getSender()} | ||
viewUserOnClick | ||
width={24} | ||
height={24} | ||
/> | ||
<div className="mx_CallEvent_infoRows"> | ||
<span className="mx_CallEvent_title"> | ||
{ _t("%(name)s started a video call", { name: senderName }) } | ||
</span> | ||
<LiveContentSummary | ||
type={LiveContentType.Video} | ||
text={_t("Video call")} | ||
active={false} | ||
participantCount={participants.size} | ||
/> | ||
<FacePile members={facePileMembers} faceSize={24} overflow={facePileOverflow} /> | ||
</div> | ||
<CallEventDuration delta={now - mxEvent.getTs()} /> | ||
<AccessibleButton | ||
className="mx_CallEvent_button" | ||
kind={buttonKind} | ||
disabled={onButtonClick === null} | ||
onClick={onButtonClick} | ||
> | ||
{ buttonText } | ||
</AccessibleButton> | ||
</div> | ||
</div>; | ||
}, | ||
); | ||
|
||
interface ActiveLoadedCallEventProps { | ||
mxEvent: MatrixEvent; | ||
call: Call; | ||
} | ||
|
||
const ActiveLoadedCallEvent = forwardRef<any, ActiveLoadedCallEventProps>(({ mxEvent, call }, ref) => { | ||
const connectionState = useConnectionState(call); | ||
const participants = useParticipants(call); | ||
|
||
const connect = useCallback((ev: ButtonEvent) => { | ||
ev.preventDefault(); | ||
defaultDispatcher.dispatch<ViewRoomPayload>({ | ||
action: Action.ViewRoom, | ||
room_id: mxEvent.getRoomId()!, | ||
view_call: true, | ||
metricsTrigger: undefined, | ||
}); | ||
}, [mxEvent]); | ||
|
||
const disconnect = useCallback((ev: ButtonEvent) => { | ||
ev.preventDefault(); | ||
call.disconnect(); | ||
}, [call]); | ||
|
||
const [buttonText, buttonKind, onButtonClick] = useMemo(() => { | ||
switch (connectionState) { | ||
case ConnectionState.Disconnected: return [_t("Join"), "primary", connect]; | ||
case ConnectionState.Connecting: return [_t("Join"), "primary", null]; | ||
case ConnectionState.Connected: return [_t("Leave"), "danger", disconnect]; | ||
case ConnectionState.Disconnecting: return [_t("Leave"), "danger", null]; | ||
} | ||
}, [connectionState, connect, disconnect]); | ||
|
||
return <ActiveCallEvent | ||
ref={ref} | ||
mxEvent={mxEvent} | ||
participants={participants} | ||
buttonText={buttonText} | ||
buttonKind={buttonKind} | ||
onButtonClick={onButtonClick} | ||
/>; | ||
}); | ||
|
||
interface CallEventProps { | ||
mxEvent: MatrixEvent; | ||
} | ||
|
||
/** | ||
* An event tile representing an active or historical Element call. | ||
*/ | ||
export const CallEvent = forwardRef<any, CallEventProps>(({ mxEvent }, ref) => { | ||
const noParticipants = useMemo(() => new Set<RoomMember>(), []); | ||
const client = useContext(MatrixClientContext); | ||
const call = useCall(mxEvent.getRoomId()!); | ||
const latestEvent = client.getRoom(mxEvent.getRoomId())!.currentState | ||
.getStateEvents(mxEvent.getType(), mxEvent.getStateKey()!); | ||
|
||
if ("m.terminated" in latestEvent.getContent()) { | ||
// The call is terminated | ||
return <div className="mx_CallEvent_wrapper" ref={ref}> | ||
<div className="mx_CallEvent mx_CallEvent_inactive"> | ||
<span className="mx_CallEvent_title">{ _t("Video call ended") }</span> | ||
<CallEventDuration delta={latestEvent.getTs() - mxEvent.getTs()} /> | ||
</div> | ||
</div>; | ||
} | ||
|
||
if (call === null) { | ||
// There should be a call, but it hasn't loaded yet | ||
return <ActiveCallEvent | ||
ref={ref} | ||
mxEvent={mxEvent} | ||
participants={noParticipants} | ||
buttonText={_t("Join")} | ||
buttonKind="primary" | ||
onButtonClick={null} | ||
/>; | ||
} | ||
|
||
return <ActiveLoadedCallEvent mxEvent={mxEvent} call={call} ref={ref} />; | ||
}); |
Oops, something went wrong.