Show/hide the Hangup button depending on the state of the conf call.

This commit is contained in:
Kegan Dougal 2015-09-15 13:04:09 +01:00
parent 5e3698de64
commit 7866979c79
2 changed files with 44 additions and 14 deletions

View File

@ -9,9 +9,7 @@ var DOMAIN = "matrix.org";
function ConferenceCall(matrixClient, groupChatRoomId) { function ConferenceCall(matrixClient, groupChatRoomId) {
this.client = matrixClient; this.client = matrixClient;
this.groupRoomId = groupChatRoomId; this.groupRoomId = groupChatRoomId;
// abuse browserify's core node Buffer support (strip padding ='s) this.confUserId = module.exports.getConferenceUserIdForRoom(this.groupRoomId);
var base64RoomId = new Buffer(groupChatRoomId).toString("base64").replace(/=/g, "");
this.confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
} }
ConferenceCall.prototype.setup = function() { ConferenceCall.prototype.setup = function() {
@ -19,8 +17,12 @@ ConferenceCall.prototype.setup = function() {
return this._joinConferenceUser().then(function() { return this._joinConferenceUser().then(function() {
return self._getConferenceUserRoom(); return self._getConferenceUserRoom();
}).then(function(room) { }).then(function(room) {
// return a call for *this* room to be placed. // return a call for *this* room to be placed. We also tack on
return Matrix.createNewMatrixCall(self.client, room.roomId); // confUserId to speed up lookups (else we'd need to loop every room
// looking for a 1:1 room with this conf user ID!)
var call = Matrix.createNewMatrixCall(self.client, room.roomId);
call.confUserId = self.confUserId;
return call;
}); });
}; };
@ -78,5 +80,11 @@ module.exports.isConferenceUser = function(roomMember) {
return false; return false;
}; };
module.exports.getConferenceUserIdForRoom = function(roomId) {
// abuse browserify's core node Buffer support (strip padding ='s)
var base64RoomId = new Buffer(roomId).toString("base64").replace(/=/g, "");
return "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
};
module.exports.ConferenceCall = ConferenceCall; module.exports.ConferenceCall = ConferenceCall;

View File

@ -19,11 +19,15 @@ limitations under the License.
/* /*
* State vars: * State vars:
* this.state.call_state = the UI state of the call (see CallHandler) * this.state.call_state = the UI state of the call (see CallHandler)
*
* Props:
* room (JS SDK Room)
*/ */
var React = require('react'); var React = require('react');
var dis = require("../../dispatcher"); var dis = require("../../dispatcher");
var CallHandler = require("../../CallHandler"); var CallHandler = require("../../CallHandler");
var ConferenceHandler = require("../../ConferenceHandler");
module.exports = { module.exports = {
propTypes: { propTypes: {
@ -44,7 +48,7 @@ module.exports = {
componentDidMount: function() { componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
if (this.props.room) { if (this.props.room) {
var call = CallHandler.getCall(this.props.room.roomId); var call = this._getCall(this.props.room.roomId);
var callState = call ? call.call_state : "ended"; var callState = call ? call.call_state : "ended";
this.setState({ this.setState({
call_state: callState call_state: callState
@ -57,15 +61,12 @@ module.exports = {
}, },
onAction: function(payload) { onAction: function(payload) {
// if we were given a room_id to track, don't handle anything else. // don't filter out payloads for room IDs other than props.room because
if (payload.room_id && this.props.room && // we may be interested in the conf 1:1 room
this.props.room.roomId !== payload.room_id) { if (payload.action !== 'call_state' || !payload.room_id) {
return; return;
} }
if (payload.action !== 'call_state') { var call = this._getCall(payload.room_id);
return;
}
var call = CallHandler.getCall(payload.room_id);
var callState = call ? call.call_state : "ended"; var callState = call ? call.call_state : "ended";
this.setState({ this.setState({
call_state: callState call_state: callState
@ -87,9 +88,30 @@ module.exports = {
}); });
}, },
onHangupClick: function() { onHangupClick: function() {
var call = this._getCall(this.props.room.roomId);
if (!call) { return; }
dis.dispatch({ dis.dispatch({
action: 'hangup', action: 'hangup',
room_id: this.props.room.roomId // hangup the call for this room, which may not be the room in props
// (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;
} }
}; };