From 353269370fc58d9662ca5290cb7b201c70a998bf Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 15 Sep 2015 13:19:07 +0100 Subject: [PATCH] Wire up the "room" CallView for conferencing This also separates out concerns better - UI elements just need to poke getCallForRoom rather than care if the thing they are displaying is a true 1:1 for this room ID or actually a conf room. --- skins/base/views/pages/MatrixChat.js | 3 ++- src/CallHandler.js | 23 +++++++++++++++++++++ src/controllers/molecules/RoomHeader.js | 24 +++------------------- src/controllers/molecules/voip/CallView.js | 11 ++++------ 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/skins/base/views/pages/MatrixChat.js b/skins/base/views/pages/MatrixChat.js index 6b1ddb635..e5fbe178a 100644 --- a/skins/base/views/pages/MatrixChat.js +++ b/skins/base/views/pages/MatrixChat.js @@ -80,7 +80,8 @@ module.exports = React.createClass({ // 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))) { + !this.state.currentRoom || + !CallHandler.getCallForRoom(this.state.currentRoom))) { console.log( "Creating global CallView for active call in room %s", this.state.active_call.roomId diff --git a/src/CallHandler.js b/src/CallHandler.js index 2cfd114f3..025ece386 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -58,6 +58,7 @@ var Modal = require("./Modal"); var ComponentBroker = require('./ComponentBroker'); var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog"); var ConferenceCall = require("./ConferenceHandler").ConferenceCall; +var ConferenceHandler = require("./ConferenceHandler"); var Matrix = require("matrix-js-sdk"); var dis = require("./dispatcher"); @@ -241,10 +242,32 @@ dis.register(function(payload) { }); module.exports = { + + getCallForRoom: function(roomId) { + return ( + module.exports.getCall(roomId) || + module.exports.getConferenceCall(roomId) + ); + }, + getCall: function(roomId) { return calls[roomId] || null; }, + getConferenceCall: function(roomId) { + // search for a conference 1:1 call for this group chat room ID + var activeCall = module.exports.getAnyActiveCall(); + if (activeCall && activeCall.confUserId) { + var thisRoomConfUserId = ConferenceHandler.getConferenceUserIdForRoom( + roomId + ); + if (thisRoomConfUserId === activeCall.confUserId) { + return activeCall; + } + } + return null; + }, + getAnyActiveCall: function() { var roomsWithCalls = Object.keys(calls); for (var i = 0; i < roomsWithCalls.length; i++) { diff --git a/src/controllers/molecules/RoomHeader.js b/src/controllers/molecules/RoomHeader.js index 21ffd632f..c7e023fc3 100644 --- a/src/controllers/molecules/RoomHeader.js +++ b/src/controllers/molecules/RoomHeader.js @@ -27,7 +27,6 @@ limitations under the License. var React = require('react'); var dis = require("../../dispatcher"); var CallHandler = require("../../CallHandler"); -var ConferenceHandler = require("../../ConferenceHandler"); module.exports = { propTypes: { @@ -48,7 +47,7 @@ module.exports = { componentDidMount: function() { this.dispatcherRef = dis.register(this.onAction); if (this.props.room) { - var call = this._getCall(this.props.room.roomId); + var call = CallHandler.getCallForRoom(this.props.room.roomId); var callState = call ? call.call_state : "ended"; this.setState({ call_state: callState @@ -66,7 +65,7 @@ module.exports = { if (payload.action !== 'call_state' || !payload.room_id) { return; } - var call = this._getCall(payload.room_id); + var call = CallHandler.getCallForRoom(payload.room_id); var callState = call ? call.call_state : "ended"; this.setState({ call_state: callState @@ -88,7 +87,7 @@ module.exports = { }); }, onHangupClick: function() { - var call = this._getCall(this.props.room.roomId); + var call = CallHandler.getCallForRoom(this.props.room.roomId); if (!call) { return; } dis.dispatch({ action: 'hangup', @@ -96,22 +95,5 @@ module.exports = { // (e.g. conferences which will hangup the 1:1 room instead) room_id: call.roomId }); - }, - - _getCall: function(roomId) { - var call = CallHandler.getCall(roomId); - if (!call) { - // search for a conference 1:1 call - var activeCall = CallHandler.getAnyActiveCall(); - if (activeCall && activeCall.confUserId) { - var thisRoomConfUserId = ConferenceHandler.getConferenceUserIdForRoom( - roomId - ); - if (thisRoomConfUserId === activeCall.confUserId) { - call = activeCall; - } - } - } - return call; } }; diff --git a/src/controllers/molecules/voip/CallView.js b/src/controllers/molecules/voip/CallView.js index 6e6f34822..3c735be1a 100644 --- a/src/controllers/molecules/voip/CallView.js +++ b/src/controllers/molecules/voip/CallView.js @@ -57,19 +57,16 @@ module.exports = { }, onAction: function(payload) { - // if we were given a room_id to track, don't handle anything else. - if (payload.room_id && this._trackedRoom && - this._trackedRoom.roomId !== payload.room_id) { - return; - } - if (payload.action !== 'call_state') { + // don't filter out payloads for room IDs other than props.room because + // we may be interested in the conf 1:1 room + if (payload.action !== 'call_state' || !payload.room_id) { return; } this.showCall(payload.room_id); }, showCall: function(roomId) { - var call = CallHandler.getCall(roomId); + var call = CallHandler.getCallForRoom(roomId); if (call) { call.setLocalVideoElement(this.getVideoView().getLocalVideoElement()); // N.B. the remote video element is used for playback for audio for voice calls