2016-02-23 18:46:27 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-10-12 19:03:38 +03:00
|
|
|
Copyright 2017 New Vector Ltd
|
2016-02-23 18:46:27 +03: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
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-05-30 17:09:57 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-30 17:09:57 +03:00
|
|
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import dis from "../../../dispatcher";
|
|
|
|
import ObjectUtils from '../../../ObjectUtils';
|
2017-06-09 13:06:44 +03:00
|
|
|
import AppsDrawer from './AppsDrawer';
|
2017-11-13 22:19:33 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2018-11-26 19:58:51 +03:00
|
|
|
import classNames from 'classnames';
|
2018-12-24 17:27:50 +03:00
|
|
|
import RateLimitedFunc from '../../../ratelimitedfunc';
|
2018-12-24 18:09:10 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2017-05-30 17:09:57 +03:00
|
|
|
|
|
|
|
|
2016-02-23 18:46:27 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'AuxPanel',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
// js-sdk room object
|
2017-12-26 04:03:18 +03:00
|
|
|
room: PropTypes.object.isRequired,
|
|
|
|
userId: PropTypes.string.isRequired,
|
2018-02-23 18:37:33 +03:00
|
|
|
showApps: PropTypes.bool, // Render apps
|
|
|
|
hideAppsDrawer: PropTypes.bool, // Do not display apps drawer and content (may still be rendered)
|
2016-02-23 18:46:27 +03:00
|
|
|
|
|
|
|
// Conference Handler implementation
|
2017-12-26 04:03:18 +03:00
|
|
|
conferenceHandler: PropTypes.object,
|
2016-02-23 18:46:27 +03:00
|
|
|
|
|
|
|
// set to true to show the file drop target
|
2017-12-26 04:03:18 +03:00
|
|
|
draggingFile: PropTypes.bool,
|
2016-02-23 18:46:27 +03:00
|
|
|
|
|
|
|
// set to true to show the 'active conf call' banner
|
2017-12-26 04:03:18 +03:00
|
|
|
displayConfCallNotification: PropTypes.bool,
|
2016-02-23 18:46:27 +03:00
|
|
|
|
|
|
|
// maxHeight attribute for the aux panel and the video
|
|
|
|
// therein
|
2017-12-26 04:03:18 +03:00
|
|
|
maxHeight: PropTypes.number,
|
2016-02-23 18:46:27 +03:00
|
|
|
|
2016-03-08 15:16:34 +03:00
|
|
|
// a callback which is called when the content of the aux panel changes
|
|
|
|
// content in a way that is likely to make it change size.
|
2017-12-26 04:03:18 +03:00
|
|
|
onResize: PropTypes.func,
|
2018-11-26 19:58:51 +03:00
|
|
|
fullHeight: PropTypes.bool,
|
2016-03-08 15:16:34 +03:00
|
|
|
},
|
|
|
|
|
2018-02-09 16:23:34 +03:00
|
|
|
defaultProps: {
|
|
|
|
showApps: true,
|
|
|
|
hideAppsDrawer: false,
|
|
|
|
},
|
|
|
|
|
2019-01-08 14:14:31 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return { counters: this._computeCounters() };
|
|
|
|
},
|
|
|
|
|
2018-12-24 17:27:50 +03:00
|
|
|
componentDidMount: function() {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
cli.on("RoomState.events", this._rateLimitedUpdate);
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("RoomState.events", this._rateLimitedUpdate);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-08 15:16:34 +03:00
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
return (!ObjectUtils.shallowEqual(this.props, nextProps) ||
|
|
|
|
!ObjectUtils.shallowEqual(this.state, nextState));
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function(prevProps, prevState) {
|
|
|
|
// most changes are likely to cause a resize
|
|
|
|
if (this.props.onResize) {
|
|
|
|
this.props.onResize();
|
|
|
|
}
|
2016-02-23 18:46:27 +03:00
|
|
|
},
|
|
|
|
|
2016-09-03 15:27:46 +03:00
|
|
|
onConferenceNotificationClick: function(ev, type) {
|
2016-02-23 18:46:27 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'place_call',
|
2016-09-02 17:38:28 +03:00
|
|
|
type: type,
|
2016-02-23 18:46:27 +03:00
|
|
|
room_id: this.props.room.roomId,
|
|
|
|
});
|
2016-09-03 15:27:46 +03:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2016-02-23 18:46:27 +03:00
|
|
|
},
|
|
|
|
|
2018-12-24 17:27:50 +03:00
|
|
|
_rateLimitedUpdate: new RateLimitedFunc(function() {
|
2019-01-10 19:54:08 +03:00
|
|
|
if (SettingsStore.isFeatureEnabled("feature_state_counters")) {
|
|
|
|
this.setState({counters: this._computeCounters()});
|
|
|
|
}
|
2018-12-24 17:27:50 +03:00
|
|
|
}, 500),
|
|
|
|
|
2019-01-08 14:14:31 +03:00
|
|
|
_computeCounters: function() {
|
|
|
|
let counters = [];
|
|
|
|
|
|
|
|
if (this.props.room && SettingsStore.isFeatureEnabled("feature_state_counters")) {
|
|
|
|
const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter');
|
|
|
|
stateEvs.sort((a, b) => {
|
|
|
|
return a.getStateKey() < b.getStateKey();
|
|
|
|
});
|
|
|
|
|
|
|
|
stateEvs.forEach((ev, idx) => {
|
|
|
|
const title = ev.getContent().title;
|
|
|
|
const value = ev.getContent().value;
|
|
|
|
const link = ev.getContent().link;
|
|
|
|
const severity = ev.getContent().severity || "normal";
|
|
|
|
const stateKey = ev.getStateKey();
|
|
|
|
|
2019-03-11 17:04:12 +03:00
|
|
|
// We want a non-empty title but can accept falsey values (e.g.
|
|
|
|
// zero)
|
|
|
|
if (title && value !== undefined) {
|
2019-01-08 14:14:31 +03:00
|
|
|
counters.push({
|
|
|
|
"title": title,
|
|
|
|
"value": value,
|
|
|
|
"link": link,
|
|
|
|
"severity": severity,
|
|
|
|
"stateKey": stateKey
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return counters;
|
|
|
|
},
|
|
|
|
|
2016-02-23 18:46:27 +03:00
|
|
|
render: function() {
|
2017-05-17 23:15:57 +03:00
|
|
|
const CallView = sdk.getComponent("voip.CallView");
|
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
2016-02-23 18:46:27 +03:00
|
|
|
|
2017-05-17 23:15:57 +03:00
|
|
|
let fileDropTarget = null;
|
2016-02-23 18:46:27 +03:00
|
|
|
if (this.props.draggingFile) {
|
|
|
|
fileDropTarget = (
|
|
|
|
<div className="mx_RoomView_fileDropTarget">
|
|
|
|
<div className="mx_RoomView_fileDropTargetLabel"
|
2017-06-08 16:08:51 +03:00
|
|
|
title={_t("Drop File Here")}>
|
2019-01-11 04:37:28 +03:00
|
|
|
<TintableSvg src={require("../../../../res/img/upload-big.svg")} width="45" height="59" />
|
2017-10-11 19:56:17 +03:00
|
|
|
<br />
|
|
|
|
{ _t("Drop file here to upload") }
|
2016-02-23 18:46:27 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:15:57 +03:00
|
|
|
let conferenceCallNotification = null;
|
2016-02-23 18:46:27 +03:00
|
|
|
if (this.props.displayConfCallNotification) {
|
2017-06-10 00:06:43 +03:00
|
|
|
let supportedText = '';
|
|
|
|
let joinNode;
|
2016-02-23 18:46:27 +03:00
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
2017-05-30 17:09:57 +03:00
|
|
|
supportedText = _t(" (unsupported)");
|
2017-05-17 23:15:57 +03:00
|
|
|
} else {
|
2017-06-10 00:06:43 +03:00
|
|
|
joinNode = (<span>
|
2017-11-13 22:19:33 +03:00
|
|
|
{ _t(
|
2017-06-08 16:45:59 +03:00
|
|
|
"Join as <voiceText>voice</voiceText> or <videoText>video</videoText>.",
|
2017-11-13 22:19:33 +03:00
|
|
|
{},
|
|
|
|
{
|
|
|
|
'voiceText': (sub) => <a onClick={(event)=>{ this.onConferenceNotificationClick(event, 'voice');}} href="#">{ sub }</a>,
|
|
|
|
'videoText': (sub) => <a onClick={(event)=>{ this.onConferenceNotificationClick(event, 'video');}} href="#">{ sub }</a>,
|
|
|
|
},
|
2017-10-11 19:56:17 +03:00
|
|
|
) }
|
2016-09-02 17:38:28 +03:00
|
|
|
</span>);
|
|
|
|
}
|
2017-06-10 00:06:43 +03:00
|
|
|
// XXX: the translation here isn't great: appending ' (unsupported)' is likely to not make sense in many languages,
|
|
|
|
// but there are translations for this in the languages we do have so I'm leaving it for now.
|
2016-02-23 18:46:27 +03:00
|
|
|
conferenceCallNotification = (
|
2016-09-02 17:38:28 +03:00
|
|
|
<div className="mx_RoomView_ongoingConfCallNotification">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ _t("Ongoing conference call%(supportedText)s.", {supportedText: supportedText}) }
|
2017-06-10 00:06:43 +03:00
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
{ joinNode }
|
2016-02-23 18:46:27 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:15:57 +03:00
|
|
|
const callView = (
|
2016-02-23 18:46:27 +03:00
|
|
|
<CallView ref="callView" room={this.props.room}
|
|
|
|
ConferenceHandler={this.props.conferenceHandler}
|
2016-03-08 15:16:34 +03:00
|
|
|
onResize={this.props.onResize}
|
2016-02-23 18:46:27 +03:00
|
|
|
maxVideoHeight={this.props.maxHeight}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2017-10-12 19:03:38 +03:00
|
|
|
const appsDrawer = <AppsDrawer ref="appsDrawer"
|
|
|
|
room={this.props.room}
|
|
|
|
userId={this.props.userId}
|
|
|
|
maxHeight={this.props.maxHeight}
|
|
|
|
showApps={this.props.showApps}
|
2018-02-09 16:23:34 +03:00
|
|
|
hide={this.props.hideAppsDrawer}
|
2017-10-12 19:03:38 +03:00
|
|
|
/>;
|
2017-05-17 23:15:57 +03:00
|
|
|
|
2018-12-24 17:27:50 +03:00
|
|
|
let stateViews = null;
|
2019-01-08 14:14:31 +03:00
|
|
|
if (this.state.counters && SettingsStore.isFeatureEnabled("feature_state_counters")) {
|
2018-12-24 17:27:50 +03:00
|
|
|
let counters = [];
|
|
|
|
|
2019-01-08 14:14:31 +03:00
|
|
|
this.state.counters.forEach((counter, idx) => {
|
|
|
|
const title = counter.title;
|
|
|
|
const value = counter.value;
|
|
|
|
const link = counter.link;
|
|
|
|
const severity = counter.severity;
|
|
|
|
const stateKey = counter.stateKey;
|
2018-12-24 17:27:50 +03:00
|
|
|
|
|
|
|
if (title && value && severity) {
|
|
|
|
let span = <span>{ title }: { value }</span>
|
|
|
|
|
|
|
|
if (link) {
|
|
|
|
span = (
|
|
|
|
<a href={link} target="_blank" rel="noopener">
|
|
|
|
{ span }
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
span = (
|
|
|
|
<span
|
|
|
|
className="m_RoomView_auxPanel_stateViews_span"
|
|
|
|
data-severity={severity}
|
|
|
|
key={ "x-" + stateKey }
|
|
|
|
>
|
|
|
|
{span}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
|
|
|
counters.push(span);
|
|
|
|
counters.push(
|
|
|
|
<span
|
|
|
|
className="m_RoomView_auxPanel_stateViews_delim"
|
|
|
|
key={"delim" + idx}
|
|
|
|
> ─ </span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (counters.length > 0) {
|
|
|
|
counters.pop(); // remove last deliminator
|
|
|
|
stateViews = (
|
|
|
|
<div className="m_RoomView_auxPanel_stateViews">
|
|
|
|
{ counters }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-26 19:58:51 +03:00
|
|
|
const classes = classNames({
|
|
|
|
"mx_RoomView_auxPanel": true,
|
|
|
|
"mx_RoomView_auxPanel_fullHeight": this.props.fullHeight,
|
|
|
|
});
|
|
|
|
const style = {};
|
|
|
|
if (!this.props.fullHeight) {
|
|
|
|
style.maxHeight = this.props.maxHeight;
|
|
|
|
}
|
|
|
|
|
2016-02-23 18:46:27 +03:00
|
|
|
return (
|
2018-11-26 19:58:51 +03:00
|
|
|
<div className={classes} style={style} >
|
2018-12-24 17:27:50 +03:00
|
|
|
{ stateViews }
|
2017-05-17 23:15:57 +03:00
|
|
|
{ appsDrawer }
|
2016-02-23 18:46:27 +03:00
|
|
|
{ fileDropTarget }
|
|
|
|
{ callView }
|
|
|
|
{ conferenceCallNotification }
|
|
|
|
{ this.props.children }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|