2020-12-26 10:32:51 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
|
|
|
|
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 from 'react';
|
|
|
|
import { _td } from '../../../languageHandler';
|
|
|
|
import BaseDialog from "..//dialogs/BaseDialog"
|
2020-12-26 18:56:25 +03:00
|
|
|
import AccessibleButton from './AccessibleButton';
|
2020-12-26 10:32:51 +03:00
|
|
|
|
2020-12-26 18:56:25 +03:00
|
|
|
export enum Tabs {
|
|
|
|
Screens = "screens",
|
|
|
|
Windows = "windows",
|
|
|
|
}
|
|
|
|
export interface ElectronDesktopCapturerSource {
|
|
|
|
display_id: string;
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
thumbnail,
|
|
|
|
appIcon,
|
|
|
|
}
|
2020-12-26 10:32:51 +03:00
|
|
|
export interface DesktopCapturerSourceIProps {
|
|
|
|
source: ElectronDesktopCapturerSource,
|
|
|
|
onSelect(source: ElectronDesktopCapturerSource): void,
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DesktopCapturerSource extends React.Component<DesktopCapturerSourceIProps> {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick = (ev) => {
|
|
|
|
//ev.stopPropagation();
|
|
|
|
this.props.onSelect(this.props.source);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2020-12-26 18:56:25 +03:00
|
|
|
<AccessibleButton
|
|
|
|
className="mx_streamSelectorDialog_stream_button"
|
2020-12-26 10:32:51 +03:00
|
|
|
data-id={this.props.source.id}
|
|
|
|
title={this.props.source.name}
|
|
|
|
onClick={this.onClick} >
|
|
|
|
<img
|
2020-12-26 18:56:25 +03:00
|
|
|
className="mx_streamSelectorDialog_stream_thumbnail"
|
2020-12-26 10:32:51 +03:00
|
|
|
src={this.props.source.thumbnail.toDataURL()}
|
|
|
|
/>
|
2020-12-26 18:56:25 +03:00
|
|
|
<span className="mx_streamSelectorDialog_stream_name">{this.props.source.name}</span>
|
|
|
|
</AccessibleButton>
|
2020-12-26 10:32:51 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-26 18:56:25 +03:00
|
|
|
export interface DesktopCapturerSourcePickerIState {
|
|
|
|
selectedTab: Tabs;
|
|
|
|
}
|
2020-12-26 10:32:51 +03:00
|
|
|
export interface DesktopCapturerSourcePickerIProps {
|
|
|
|
sources: Array<ElectronDesktopCapturerSource>;
|
|
|
|
onFinished(source: ElectronDesktopCapturerSource): void,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Figure out a way to update sources for live preview
|
|
|
|
|
2020-12-26 18:56:25 +03:00
|
|
|
export default class DesktopCapturerSourcePicker extends React.Component<
|
|
|
|
DesktopCapturerSourcePickerIProps,
|
|
|
|
DesktopCapturerSourcePickerIState
|
|
|
|
> {
|
2020-12-26 10:32:51 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-12-26 18:56:25 +03:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
selectedTab: Tabs.Screens,
|
|
|
|
}
|
2020-12-26 10:32:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onSelect = (source) => {
|
|
|
|
this.props.onFinished(source);
|
|
|
|
}
|
|
|
|
|
2020-12-26 18:56:25 +03:00
|
|
|
onScreensClick = (ev) => {
|
|
|
|
this.setState({selectedTab: Tabs.Screens});
|
|
|
|
}
|
|
|
|
|
|
|
|
onWindowsClick = (ev) => {
|
|
|
|
this.setState({selectedTab: Tabs.Windows});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCloseClick = (ev) => {
|
|
|
|
this.props.onFinished(null);
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:32:51 +03:00
|
|
|
render() {
|
2020-12-26 18:56:25 +03:00
|
|
|
let sources;
|
|
|
|
if (this.state.selectedTab === Tabs.Screens) {
|
|
|
|
sources = this.props.sources
|
|
|
|
.filter((source) => {
|
|
|
|
return source.id.startsWith("screen");
|
|
|
|
})
|
|
|
|
.map((source) => {
|
|
|
|
return <DesktopCapturerSource source={source} onSelect={this.onSelect} key={source.id} />;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
sources = this.props.sources
|
|
|
|
.filter((source) => {
|
|
|
|
return source.id.startsWith("window");
|
|
|
|
})
|
|
|
|
.map((source) => {
|
|
|
|
return <DesktopCapturerSource source={source} onSelect={this.onSelect} key={source.id} />;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const buttonStyle = "mx_streamSelectorDialog_tabLabel";
|
|
|
|
const screensButtonStyle = buttonStyle + ((this.state.selectedTab === Tabs.Screens) ? "_selected" : "");
|
|
|
|
const windowsButtonStyle = buttonStyle + ((this.state.selectedTab === Tabs.Windows) ? "_selected" : "");
|
2020-12-26 10:32:51 +03:00
|
|
|
|
|
|
|
return (
|
2020-12-26 18:56:25 +03:00
|
|
|
<BaseDialog
|
|
|
|
className="mx_streamSelectorDialog"
|
|
|
|
onFinished={this.onCloseClick}
|
|
|
|
title={_td("Share your screen")}
|
|
|
|
>
|
|
|
|
<div className="mx_streamSelectorDialog_tabLabels">
|
|
|
|
<AccessibleButton
|
|
|
|
className={screensButtonStyle}
|
|
|
|
onClick={this.onScreensClick}
|
|
|
|
>
|
|
|
|
{_td("Screens")}
|
|
|
|
</AccessibleButton>
|
|
|
|
<AccessibleButton
|
|
|
|
className={windowsButtonStyle}
|
|
|
|
onClick={this.onWindowsClick}
|
|
|
|
>
|
|
|
|
{_td("Windows")}
|
|
|
|
</AccessibleButton>
|
2020-12-26 10:32:51 +03:00
|
|
|
</div>
|
2020-12-26 18:56:25 +03:00
|
|
|
<div className="mx_streamSelectorDialog_panel">
|
|
|
|
{ sources }
|
2020-12-26 10:32:51 +03:00
|
|
|
</div>
|
|
|
|
</BaseDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|