diff --git a/skins/base/views/pages/MatrixChat.js b/skins/base/views/pages/MatrixChat.js index 6b1ddb63..e5fbe178 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 2cfd114f..025ece38 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 21ffd632..c7e023fc 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 6e6f3482..3c735be1 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