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 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notifications and toasts for Element Call calls (#9337)
- Loading branch information
1 parent
20f5adc
commit 6356a8c
Showing
10 changed files
with
591 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
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_IncomingCallToast { | ||
position: relative; | ||
display: flex; | ||
flex-direction: row; | ||
pointer-events: initial; /* restore pointer events so the user can accept/decline */ | ||
width: 250px; | ||
|
||
.mx_IncomingCallToast_content { | ||
display: flex; | ||
flex-direction: column; | ||
margin-left: 8px; | ||
width: 100%; | ||
|
||
.mx_IncomingCallToast_info { | ||
margin-bottom: $spacing-16; | ||
|
||
.mx_IncomingCallToast_room { | ||
display: inline-block; | ||
|
||
font-weight: bold; | ||
font-size: $font-15px; | ||
line-height: $font-24px; | ||
|
||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
|
||
margin-bottom: $spacing-4; | ||
} | ||
|
||
.mx_IncomingCallToast_message { | ||
font-size: $font-12px; | ||
line-height: $font-15px; | ||
|
||
margin-bottom: $spacing-4; | ||
} | ||
|
||
.mx_LiveContentSummary { | ||
font-size: $font-12px; | ||
line-height: $font-15px; | ||
|
||
.mx_LiveContentSummary_participants::before { | ||
width: 15px; | ||
height: 15px; | ||
} | ||
} | ||
} | ||
|
||
.mx_IncomingCallToast_joinButton { | ||
position: relative; | ||
|
||
bottom: $spacing-4; | ||
right: $spacing-4; | ||
|
||
align-self: flex-end; | ||
|
||
box-sizing: border-box; | ||
min-width: 120px; | ||
|
||
padding: $spacing-4 0; | ||
|
||
line-height: $font-24px; | ||
} | ||
} | ||
|
||
.mx_IncomingCallToast_closeButton { | ||
position: absolute; | ||
|
||
top: $spacing-4; | ||
right: $spacing-4; | ||
|
||
display: flex; | ||
height: 16px; | ||
width: 16px; | ||
|
||
&::before { | ||
content: ''; | ||
|
||
mask-image: url('$(res)/img/cancel.svg'); | ||
|
||
height: inherit; | ||
width: inherit; | ||
background-color: $secondary-content; | ||
mask-repeat: no-repeat; | ||
mask-size: contain; | ||
mask-position: center; | ||
} | ||
} | ||
} |
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
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,119 @@ | ||
/* | ||
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, { useCallback, useEffect } from 'react'; | ||
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; | ||
|
||
import { _t } from '../languageHandler'; | ||
import RoomAvatar from '../components/views/avatars/RoomAvatar'; | ||
import AccessibleButton from '../components/views/elements/AccessibleButton'; | ||
import { MatrixClientPeg } from "../MatrixClientPeg"; | ||
import defaultDispatcher from "../dispatcher/dispatcher"; | ||
import { ViewRoomPayload } from "../dispatcher/payloads/ViewRoomPayload"; | ||
import { Action } from "../dispatcher/actions"; | ||
import ToastStore from "../stores/ToastStore"; | ||
import AccessibleTooltipButton from "../components/views/elements/AccessibleTooltipButton"; | ||
import { | ||
LiveContentSummary, | ||
LiveContentSummaryWithCall, | ||
LiveContentType, | ||
} from "../components/views/rooms/LiveContentSummary"; | ||
import { useCall } from "../hooks/useCall"; | ||
import { useRoomState } from "../hooks/useRoomState"; | ||
import { ButtonEvent } from "../components/views/elements/AccessibleButton"; | ||
|
||
export const getIncomingCallToastKey = (stateKey: string) => `call_${stateKey}`; | ||
|
||
interface Props { | ||
callEvent: MatrixEvent; | ||
} | ||
|
||
export function IncomingCallToast({ callEvent }: Props) { | ||
const roomId = callEvent.getRoomId()!; | ||
const room = MatrixClientPeg.get().getRoom(roomId); | ||
const call = useCall(roomId); | ||
|
||
const dismissToast = useCallback((): void => { | ||
ToastStore.sharedInstance().dismissToast(getIncomingCallToastKey(callEvent.getStateKey()!)); | ||
}, [callEvent]); | ||
|
||
const latestEvent = useRoomState(room, useCallback((state) => { | ||
return state.getStateEvents(callEvent.getType(), callEvent.getStateKey()!); | ||
}, [callEvent])); | ||
|
||
useEffect(() => { | ||
if ("m.terminated" in latestEvent.getContent()) { | ||
dismissToast(); | ||
} | ||
}, [latestEvent, dismissToast]); | ||
|
||
const onJoinClick = useCallback((e: ButtonEvent): void => { | ||
e.stopPropagation(); | ||
|
||
defaultDispatcher.dispatch<ViewRoomPayload>({ | ||
action: Action.ViewRoom, | ||
room_id: room.roomId, | ||
view_call: true, | ||
metricsTrigger: undefined, | ||
}); | ||
dismissToast(); | ||
}, [room, dismissToast]); | ||
|
||
const onCloseClick = useCallback((e: ButtonEvent): void => { | ||
e.stopPropagation(); | ||
|
||
dismissToast(); | ||
}, [dismissToast]); | ||
|
||
return <React.Fragment> | ||
<RoomAvatar | ||
room={room ?? undefined} | ||
height={24} | ||
width={24} | ||
/> | ||
<div className="mx_IncomingCallToast_content"> | ||
<div className="mx_IncomingCallToast_info"> | ||
<span className="mx_IncomingCallToast_room"> | ||
{ room ? room.name : _t("Unknown room") } | ||
</span> | ||
<div className="mx_IncomingCallToast_message"> | ||
{ _t("Video call started") } | ||
</div> | ||
{ call | ||
? <LiveContentSummaryWithCall call={call} /> | ||
: <LiveContentSummary | ||
type={LiveContentType.Video} | ||
text={_t("Video")} | ||
active={false} | ||
participantCount={0} | ||
/> | ||
} | ||
</div> | ||
<AccessibleButton | ||
className="mx_IncomingCallToast_joinButton" | ||
onClick={onJoinClick} | ||
kind="primary" | ||
> | ||
{ _t("Join") } | ||
</AccessibleButton> | ||
</div> | ||
<AccessibleTooltipButton | ||
className="mx_IncomingCallToast_closeButton" | ||
onClick={onCloseClick} | ||
title={_t("Close")} | ||
/> | ||
</React.Fragment>; | ||
} |
Oops, something went wrong.