Skip to content

Commit 59986d8

Browse files
committed
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 element-hq#31 This is unfinished (CSS for the global call view isn't done)
1 parent fc892b3 commit 59986d8

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎skins/base/views/pages/MatrixChat.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818

1919
var React = require('react');
2020
var ComponentBroker = require('../../../../src/ComponentBroker');
21+
var CallHandler = require('../../../../src/CallHandler');
2122

2223
var LeftPanel = ComponentBroker.get('organisms/LeftPanel');
2324
var RoomView = ComponentBroker.get('organisms/RoomView');
@@ -29,8 +30,9 @@ var CreateRoom = ComponentBroker.get('organisms/CreateRoom');
2930
var RoomDirectory = ComponentBroker.get('organisms/RoomDirectory');
3031
var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar');
3132
var Notifier = ComponentBroker.get('organisms/Notifier');
33+
var CallView = ComponentBroker.get('molecules/voip/CallView');
3234

33-
var MatrixChatController = require("../../../../src/controllers/pages/MatrixChat");
35+
var MatrixChatController = require('../../../../src/controllers/pages/MatrixChat');
3436

3537
// should be atomised
3638
var Loader = require("react-loader");
@@ -53,7 +55,7 @@ module.exports = React.createClass({
5355
render: function() {
5456
if (this.state.logged_in && this.state.ready) {
5557

56-
var page_element;
58+
var page_element, call_element;
5759
var right_panel = "";
5860

5961
switch (this.state.page_type) {
@@ -74,13 +76,25 @@ module.exports = React.createClass({
7476
right_panel = <RightPanel/>
7577
break;
7678
}
79+
// if we aren't viewing a room with an ongoing call, but there is an
80+
// active call, show the call element - we need to do this to make
81+
// audio/video not crap out
82+
if (this.state.active_call && (
83+
!this.state.currentRoom || !CallHandler.getCall(this.state.currentRoom))) {
84+
console.log(
85+
"Creating global CallView for active call in room %s",
86+
this.state.active_call.roomId
87+
);
88+
call_element = <CallView className="mx_MatrixChat_callView"/>
89+
}
7790

7891
if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
7992
return (
8093
<div className="mx_MatrixChat_wrapper">
8194
<MatrixToolbar />
8295
<div className="mx_MatrixChat mx_MatrixChat_toolbarShowing">
8396
<LeftPanel selectedRoom={this.state.currentRoom} />
97+
{call_element}
8498
<main className="mx_MatrixChat_middlePanel">
8599
{page_element}
86100
</main>
@@ -93,6 +107,7 @@ module.exports = React.createClass({
93107
return (
94108
<div className="mx_MatrixChat">
95109
<LeftPanel selectedRoom={this.state.currentRoom} />
110+
{call_element}
96111
<main className="mx_MatrixChat_middlePanel">
97112
{page_element}
98113
</main>

‎src/CallHandler.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function _setCallListeners(call) {
106106
play("ringbackAudio");
107107
}
108108
else if (newState === "ended" && oldState === "connected") {
109-
_setCallState(call, call.roomId, "ended");
109+
_setCallState(undefined, call.roomId, "ended");
110110
pause("ringbackAudio");
111111
play("callendAudio");
112112
}
@@ -239,5 +239,16 @@ dis.register(function(payload) {
239239
module.exports = {
240240
getCall: function(roomId) {
241241
return calls[roomId] || null;
242+
},
243+
244+
getAnyActiveCall: function() {
245+
var roomsWithCalls = Object.keys(calls);
246+
for (var i = 0; i < roomsWithCalls.length; i++) {
247+
if (calls[roomsWithCalls[i]] &&
248+
calls[roomsWithCalls[i]].call_state !== "ended") {
249+
return calls[roomsWithCalls[i]];
250+
}
251+
}
252+
return null;
242253
}
243254
};

‎src/controllers/molecules/voip/CallView.js‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,38 @@ limitations under the License.
1717
'use strict';
1818
var dis = require("../../../dispatcher");
1919
var CallHandler = require("../../../CallHandler");
20+
var MatrixClientPeg = require("../../../MatrixClientPeg");
2021

2122
/*
2223
* State vars:
2324
* this.state.call = MatrixCall|null
2425
*
2526
* Props:
2627
* this.props.room = Room (JS SDK)
28+
*
29+
* Internal state:
30+
* this._trackedRoom = (either from props.room or programatically set)
2731
*/
2832

2933
module.exports = {
3034

3135
componentDidMount: function() {
3236
this.dispatcherRef = dis.register(this.onAction);
37+
this._trackedRoom = null;
3338
if (this.props.room) {
34-
this.showCall(this.props.room.roomId);
39+
this._trackedRoom = this.props.room;
40+
this.showCall(this._trackedRoom.roomId);
41+
}
42+
else {
43+
var call = CallHandler.getAnyActiveCall();
44+
if (call) {
45+
console.log(
46+
"Global CallView is now tracking active call in room %s",
47+
call.roomId
48+
);
49+
this._trackedRoom = MatrixClientPeg.get().getRoom(call.roomId);
50+
this.showCall(call.roomId);
51+
}
3552
}
3653
},
3754

@@ -41,8 +58,8 @@ module.exports = {
4158

4259
onAction: function(payload) {
4360
// if we were given a room_id to track, don't handle anything else.
44-
if (payload.room_id && this.props.room &&
45-
this.props.room.roomId !== payload.room_id) {
61+
if (payload.room_id && this._trackedRoom &&
62+
this._trackedRoom.roomId !== payload.room_id) {
4663
return;
4764
}
4865
if (payload.action !== 'call_state') {

‎src/controllers/pages/MatrixChat.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var dis = require("../../dispatcher");
2626
var q = require("q");
2727

2828
var ComponentBroker = require('../../ComponentBroker');
29+
var CallHandler = require("../../CallHandler");
2930
var Notifier = ComponentBroker.get('organisms/Notifier');
3031
var MatrixTools = require('../../MatrixTools');
3132

@@ -205,6 +206,13 @@ module.exports = {
205206
case 'notifier_enabled':
206207
this.forceUpdate();
207208
break;
209+
case 'call_state':
210+
// listen for call state changes to prod the render method, which
211+
// may hide the global CallView if the call it is tracking is dead
212+
this.setState({
213+
active_call: CallHandler.getAnyActiveCall()
214+
});
215+
break;
208216
}
209217
},
210218

0 commit comments

Comments
 (0)