Skip to content

Commit 7866979

Browse files
committed
Show/hide the Hangup button depending on the state of the conf call.
1 parent 5e3698d commit 7866979

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

‎src/ConferenceHandler.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ var DOMAIN = "matrix.org";
99
function ConferenceCall(matrixClient, groupChatRoomId) {
1010
this.client = matrixClient;
1111
this.groupRoomId = groupChatRoomId;
12-
// abuse browserify's core node Buffer support (strip padding ='s)
13-
var base64RoomId = new Buffer(groupChatRoomId).toString("base64").replace(/=/g, "");
14-
this.confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
12+
this.confUserId = module.exports.getConferenceUserIdForRoom(this.groupRoomId);
1513
}
1614

1715
ConferenceCall.prototype.setup = function() {
1816
var self = this;
1917
return this._joinConferenceUser().then(function() {
2018
return self._getConferenceUserRoom();
2119
}).then(function(room) {
22-
// return a call for *this* room to be placed.
23-
return Matrix.createNewMatrixCall(self.client, room.roomId);
20+
// return a call for *this* room to be placed. We also tack on
21+
// confUserId to speed up lookups (else we'd need to loop every room
22+
// looking for a 1:1 room with this conf user ID!)
23+
var call = Matrix.createNewMatrixCall(self.client, room.roomId);
24+
call.confUserId = self.confUserId;
25+
return call;
2426
});
2527
};
2628

@@ -78,5 +80,11 @@ module.exports.isConferenceUser = function(roomMember) {
7880
return false;
7981
};
8082

83+
module.exports.getConferenceUserIdForRoom = function(roomId) {
84+
// abuse browserify's core node Buffer support (strip padding ='s)
85+
var base64RoomId = new Buffer(roomId).toString("base64").replace(/=/g, "");
86+
return "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
87+
};
88+
8189
module.exports.ConferenceCall = ConferenceCall;
8290

‎src/controllers/molecules/RoomHeader.js‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ limitations under the License.
1919
/*
2020
* State vars:
2121
* this.state.call_state = the UI state of the call (see CallHandler)
22+
*
23+
* Props:
24+
* room (JS SDK Room)
2225
*/
2326

2427
var React = require('react');
2528
var dis = require("../../dispatcher");
2629
var CallHandler = require("../../CallHandler");
30+
var ConferenceHandler = require("../../ConferenceHandler");
2731

2832
module.exports = {
2933
propTypes: {
@@ -44,7 +48,7 @@ module.exports = {
4448
componentDidMount: function() {
4549
this.dispatcherRef = dis.register(this.onAction);
4650
if (this.props.room) {
47-
var call = CallHandler.getCall(this.props.room.roomId);
51+
var call = this._getCall(this.props.room.roomId);
4852
var callState = call ? call.call_state : "ended";
4953
this.setState({
5054
call_state: callState
@@ -57,15 +61,12 @@ module.exports = {
5761
},
5862

5963
onAction: function(payload) {
60-
// if we were given a room_id to track, don't handle anything else.
61-
if (payload.room_id && this.props.room &&
62-
this.props.room.roomId !== payload.room_id) {
64+
// don't filter out payloads for room IDs other than props.room because
65+
// we may be interested in the conf 1:1 room
66+
if (payload.action !== 'call_state' || !payload.room_id) {
6367
return;
6468
}
65-
if (payload.action !== 'call_state') {
66-
return;
67-
}
68-
var call = CallHandler.getCall(payload.room_id);
69+
var call = this._getCall(payload.room_id);
6970
var callState = call ? call.call_state : "ended";
7071
this.setState({
7172
call_state: callState
@@ -87,9 +88,30 @@ module.exports = {
8788
});
8889
},
8990
onHangupClick: function() {
91+
var call = this._getCall(this.props.room.roomId);
92+
if (!call) { return; }
9093
dis.dispatch({
9194
action: 'hangup',
92-
room_id: this.props.room.roomId
95+
// hangup the call for this room, which may not be the room in props
96+
// (e.g. conferences which will hangup the 1:1 room instead)
97+
room_id: call.roomId
9398
});
99+
},
100+
101+
_getCall: function(roomId) {
102+
var call = CallHandler.getCall(roomId);
103+
if (!call) {
104+
// search for a conference 1:1 call
105+
var activeCall = CallHandler.getAnyActiveCall();
106+
if (activeCall && activeCall.confUserId) {
107+
var thisRoomConfUserId = ConferenceHandler.getConferenceUserIdForRoom(
108+
roomId
109+
);
110+
if (thisRoomConfUserId === activeCall.confUserId) {
111+
call = activeCall;
112+
}
113+
}
114+
}
115+
return call;
94116
}
95117
};

0 commit comments

Comments
 (0)