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) {
this.client = matrixClient;
this.groupRoomId = groupChatRoomId;
// abuse browserify's core node Buffer support (strip padding ='s)
var base64RoomId = new Buffer(groupChatRoomId).toString("base64").replace(/=/g, "");
this.confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
this.confUserId = module.exports.getConferenceUserIdForRoom(this.groupRoomId);
}
ConferenceCall.prototype.setup = function() {
@ -19,8 +17,12 @@ ConferenceCall.prototype.setup = function() {
return this._joinConferenceUser().then(function() {
return self._getConferenceUserRoom();
}).then(function(room) {
// return a call for *this* room to be placed.
return Matrix.createNewMatrixCall(self.client, room.roomId);
// return a call for *this* room to be placed. We also tack on
// 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;
};
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;

View file

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