Pass the call around different CallViews to keep media flowing

Previously, the CallView was attached to the RoomView, so you would get
a new CallView each time you changed the room and the one you changed
from would be destroyed. This would destroy media capture/playback as
the element was no longer in the DOM.

This is now fixed by having a "global" CallView which is attached at
the MatrixChat "page" level in the DOM hierarchy. This CallView isn't
scoped to a particular room; it will render any "active" call it can
find that *isn't the current room being displayed*. This has the side
effect of enforcing 1 call per app semantics as only the first active
call found is returned.

This fixes https://github.com/vector-im/vector-web/issues/31
This is unfinished (CSS for the global call view isn't done)
pull/160/head
Kegan Dougal 2015-09-15 11:05:53 +01:00
parent fc892b3580
commit 59986d8b72
4 changed files with 57 additions and 6 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
var React = require('react'); var React = require('react');
var ComponentBroker = require('../../../../src/ComponentBroker'); var ComponentBroker = require('../../../../src/ComponentBroker');
var CallHandler = require('../../../../src/CallHandler');
var LeftPanel = ComponentBroker.get('organisms/LeftPanel'); var LeftPanel = ComponentBroker.get('organisms/LeftPanel');
var RoomView = ComponentBroker.get('organisms/RoomView'); var RoomView = ComponentBroker.get('organisms/RoomView');
@ -29,8 +30,9 @@ var CreateRoom = ComponentBroker.get('organisms/CreateRoom');
var RoomDirectory = ComponentBroker.get('organisms/RoomDirectory'); var RoomDirectory = ComponentBroker.get('organisms/RoomDirectory');
var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar'); var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar');
var Notifier = ComponentBroker.get('organisms/Notifier'); var Notifier = ComponentBroker.get('organisms/Notifier');
var CallView = ComponentBroker.get('molecules/voip/CallView');
var MatrixChatController = require("../../../../src/controllers/pages/MatrixChat"); var MatrixChatController = require('../../../../src/controllers/pages/MatrixChat');
// should be atomised // should be atomised
var Loader = require("react-loader"); var Loader = require("react-loader");
@ -53,7 +55,7 @@ module.exports = React.createClass({
render: function() { render: function() {
if (this.state.logged_in && this.state.ready) { if (this.state.logged_in && this.state.ready) {
var page_element; var page_element, call_element;
var right_panel = ""; var right_panel = "";
switch (this.state.page_type) { switch (this.state.page_type) {
@ -74,6 +76,17 @@ module.exports = React.createClass({
right_panel = <RightPanel/> right_panel = <RightPanel/>
break; break;
} }
// if we aren't viewing a room with an ongoing call, but there is an
// active call, show the call element - we need to do this to make
// audio/video not crap out
if (this.state.active_call && (
!this.state.currentRoom || !CallHandler.getCall(this.state.currentRoom))) {
console.log(
"Creating global CallView for active call in room %s",
this.state.active_call.roomId
);
call_element = <CallView className="mx_MatrixChat_callView"/>
}
if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) { if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
return ( return (
@ -81,6 +94,7 @@ module.exports = React.createClass({
<MatrixToolbar /> <MatrixToolbar />
<div className="mx_MatrixChat mx_MatrixChat_toolbarShowing"> <div className="mx_MatrixChat mx_MatrixChat_toolbarShowing">
<LeftPanel selectedRoom={this.state.currentRoom} /> <LeftPanel selectedRoom={this.state.currentRoom} />
{call_element}
<main className="mx_MatrixChat_middlePanel"> <main className="mx_MatrixChat_middlePanel">
{page_element} {page_element}
</main> </main>
@ -93,6 +107,7 @@ module.exports = React.createClass({
return ( return (
<div className="mx_MatrixChat"> <div className="mx_MatrixChat">
<LeftPanel selectedRoom={this.state.currentRoom} /> <LeftPanel selectedRoom={this.state.currentRoom} />
{call_element}
<main className="mx_MatrixChat_middlePanel"> <main className="mx_MatrixChat_middlePanel">
{page_element} {page_element}
</main> </main>

View File

@ -106,7 +106,7 @@ function _setCallListeners(call) {
play("ringbackAudio"); play("ringbackAudio");
} }
else if (newState === "ended" && oldState === "connected") { else if (newState === "ended" && oldState === "connected") {
_setCallState(call, call.roomId, "ended"); _setCallState(undefined, call.roomId, "ended");
pause("ringbackAudio"); pause("ringbackAudio");
play("callendAudio"); play("callendAudio");
} }
@ -239,5 +239,16 @@ dis.register(function(payload) {
module.exports = { module.exports = {
getCall: function(roomId) { getCall: function(roomId) {
return calls[roomId] || null; return calls[roomId] || null;
},
getAnyActiveCall: function() {
var roomsWithCalls = Object.keys(calls);
for (var i = 0; i < roomsWithCalls.length; i++) {
if (calls[roomsWithCalls[i]] &&
calls[roomsWithCalls[i]].call_state !== "ended") {
return calls[roomsWithCalls[i]];
}
}
return null;
} }
}; };

View File

@ -17,6 +17,7 @@ limitations under the License.
'use strict'; 'use strict';
var dis = require("../../../dispatcher"); var dis = require("../../../dispatcher");
var CallHandler = require("../../../CallHandler"); var CallHandler = require("../../../CallHandler");
var MatrixClientPeg = require("../../../MatrixClientPeg");
/* /*
* State vars: * State vars:
@ -24,14 +25,30 @@ var CallHandler = require("../../../CallHandler");
* *
* Props: * Props:
* this.props.room = Room (JS SDK) * this.props.room = Room (JS SDK)
*
* Internal state:
* this._trackedRoom = (either from props.room or programatically set)
*/ */
module.exports = { module.exports = {
componentDidMount: function() { componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
this._trackedRoom = null;
if (this.props.room) { if (this.props.room) {
this.showCall(this.props.room.roomId); this._trackedRoom = this.props.room;
this.showCall(this._trackedRoom.roomId);
}
else {
var call = CallHandler.getAnyActiveCall();
if (call) {
console.log(
"Global CallView is now tracking active call in room %s",
call.roomId
);
this._trackedRoom = MatrixClientPeg.get().getRoom(call.roomId);
this.showCall(call.roomId);
}
} }
}, },
@ -41,8 +58,8 @@ module.exports = {
onAction: function(payload) { onAction: function(payload) {
// if we were given a room_id to track, don't handle anything else. // if we were given a room_id to track, don't handle anything else.
if (payload.room_id && this.props.room && if (payload.room_id && this._trackedRoom &&
this.props.room.roomId !== payload.room_id) { this._trackedRoom.roomId !== payload.room_id) {
return; return;
} }
if (payload.action !== 'call_state') { if (payload.action !== 'call_state') {

View File

@ -26,6 +26,7 @@ var dis = require("../../dispatcher");
var q = require("q"); var q = require("q");
var ComponentBroker = require('../../ComponentBroker'); var ComponentBroker = require('../../ComponentBroker');
var CallHandler = require("../../CallHandler");
var Notifier = ComponentBroker.get('organisms/Notifier'); var Notifier = ComponentBroker.get('organisms/Notifier');
var MatrixTools = require('../../MatrixTools'); var MatrixTools = require('../../MatrixTools');
@ -205,6 +206,13 @@ module.exports = {
case 'notifier_enabled': case 'notifier_enabled':
this.forceUpdate(); this.forceUpdate();
break; break;
case 'call_state':
// listen for call state changes to prod the render method, which
// may hide the global CallView if the call it is tracking is dead
this.setState({
active_call: CallHandler.getAnyActiveCall()
});
break;
} }
}, },