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.
This commit is contained in:
Kegan Dougal 2015-09-15 13:19:07 +01:00
parent 7866979c79
commit 353269370f
4 changed files with 32 additions and 29 deletions

View File

@ -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

View File

@ -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++) {

View File

@ -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;
}
};

View File

@ -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