Files
ThreadNet-Web/src/components/views/elements/DesktopCapturerSourcePicker.tsx
T

145 lines
4.6 KiB
TypeScript
Raw Normal View History

2020-12-26 08:32:51 +01:00
/*
2021-01-05 20:36:54 +01:00
Copyright 2021 Šimon Brandner <simon.bra.ag@gmail.com>
2020-12-26 08:32:51 +01:00
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
2021-01-05 20:36:54 +01:00
http://www.apache.org/licenses/LICENSE-2.0
2020-12-26 08:32:51 +01:00
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 from 'react';
2021-01-05 20:27:11 +01:00
import { _t } from '../../../languageHandler';
2020-12-26 08:32:51 +01:00
import BaseDialog from "..//dialogs/BaseDialog"
2020-12-26 16:56:25 +01:00
import AccessibleButton from './AccessibleButton';
2020-12-26 08:32:51 +01:00
2020-12-26 16:56:25 +01:00
export enum Tabs {
Screens = "screens",
Windows = "windows",
}
2020-12-26 18:10:50 +01:00
2020-12-26 08:32:51 +01:00
export interface DesktopCapturerSourceIProps {
2020-12-28 08:15:54 +01:00
source: DesktopCapturerSource;
onSelect(source: DesktopCapturerSource): void;
2020-12-26 08:32:51 +01:00
}
2020-12-26 18:10:50 +01:00
export class ExistingSource extends React.Component<DesktopCapturerSourceIProps> {
2020-12-26 08:32:51 +01:00
constructor(props) {
super(props);
}
onClick = (ev) => {
this.props.onSelect(this.props.source);
}
render() {
return (
2020-12-26 16:56:25 +01:00
<AccessibleButton
2021-01-05 19:49:09 +01:00
className="mx_desktopCapturerSourcePicker_stream_button"
2020-12-26 08:32:51 +01:00
title={this.props.source.name}
onClick={this.onClick} >
<img
2021-01-05 19:49:09 +01:00
className="mx_desktopCapturerSourcePicker_stream_thumbnail"
2020-12-26 08:32:51 +01:00
src={this.props.source.thumbnail.toDataURL()}
/>
2021-01-05 19:49:09 +01:00
<span className="mx_desktopCapturerSourcePicker_stream_name">{this.props.source.name}</span>
2020-12-26 16:56:25 +01:00
</AccessibleButton>
2020-12-26 08:32:51 +01:00
);
}
}
2020-12-26 16:56:25 +01:00
export interface DesktopCapturerSourcePickerIState {
selectedTab: Tabs;
2020-12-26 08:32:51 +01:00
}
export interface DesktopCapturerSourcePickerIProps {
2020-12-26 18:10:50 +01:00
sources: Array<DesktopCapturerSource>;
2020-12-28 08:15:54 +01:00
onFinished(source: DesktopCapturerSource): void;
2020-12-26 08:32:51 +01:00
}
// TODO: Figure out a way to update sources for live preview
2020-12-26 16:56:25 +01:00
export default class DesktopCapturerSourcePicker extends React.Component<
DesktopCapturerSourcePickerIProps,
DesktopCapturerSourcePickerIState
> {
2020-12-26 08:32:51 +01:00
constructor(props) {
super(props);
2020-12-26 16:56:25 +01:00
this.state = {
selectedTab: Tabs.Screens,
}
2020-12-26 08:32:51 +01:00
}
onSelect = (source) => {
this.props.onFinished(source);
}
2020-12-26 16:56:25 +01:00
onScreensClick = (ev) => {
this.setState({selectedTab: Tabs.Screens});
}
2020-12-26 08:32:51 +01:00
2020-12-26 16:56:25 +01:00
onWindowsClick = (ev) => {
this.setState({selectedTab: Tabs.Windows});
}
onCloseClick = (ev) => {
this.props.onFinished(null);
}
render() {
let sources;
if (this.state.selectedTab === Tabs.Screens) {
sources = this.props.sources
.filter((source) => {
return source.id.startsWith("screen");
})
.map((source) => {
2020-12-26 18:10:50 +01:00
return <ExistingSource source={source} onSelect={this.onSelect} key={source.id} />;
2020-12-26 16:56:25 +01:00
});
} else {
sources = this.props.sources
.filter((source) => {
return source.id.startsWith("window");
})
.map((source) => {
2020-12-26 18:10:50 +01:00
return <ExistingSource source={source} onSelect={this.onSelect} key={source.id} />;
2020-12-26 16:56:25 +01:00
});
}
2021-01-05 19:49:09 +01:00
const buttonStyle = "mx_desktopCapturerSourcePicker_tabLabel";
2020-12-26 16:56:25 +01:00
const screensButtonStyle = buttonStyle + ((this.state.selectedTab === Tabs.Screens) ? "_selected" : "");
const windowsButtonStyle = buttonStyle + ((this.state.selectedTab === Tabs.Windows) ? "_selected" : "");
2020-12-26 08:32:51 +01:00
return (
2020-12-26 16:56:25 +01:00
<BaseDialog
2021-01-05 19:49:09 +01:00
className="mx_desktopCapturerSourcePicker"
2020-12-26 16:56:25 +01:00
onFinished={this.onCloseClick}
2021-01-05 20:27:11 +01:00
title={_t("Share your screen")}
2020-12-26 16:56:25 +01:00
>
2021-01-05 19:49:09 +01:00
<div className="mx_desktopCapturerSourcePicker_tabLabels">
2020-12-26 16:56:25 +01:00
<AccessibleButton
className={screensButtonStyle}
onClick={this.onScreensClick}
>
2021-01-05 20:27:11 +01:00
{_t("Screens")}
2020-12-26 16:56:25 +01:00
</AccessibleButton>
<AccessibleButton
className={windowsButtonStyle}
onClick={this.onWindowsClick}
>
2021-01-05 20:27:11 +01:00
{_t("Windows")}
2020-12-26 16:56:25 +01:00
</AccessibleButton>
2020-12-26 08:32:51 +01:00
</div>
2021-01-05 19:49:09 +01:00
<div className="mx_desktopCapturerSourcePicker_panel">
2020-12-26 16:56:25 +01:00
{ sources }
2020-12-26 08:32:51 +01:00
</div>
</BaseDialog>
);
}
}