Skip to content

Commit 81db1b2

Browse files
committed
Merge pull request element-hq#160 from vector-im/conferencing
Add conferencing support
2 parents 01d3f2f + 240d550 commit 81db1b2

13 files changed

Lines changed: 423 additions & 62 deletions

File tree

‎docs/conferencing.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# VoIP Conferencing
2+
3+
This is a draft proposal for a naive voice/video conferencing implementation for
4+
Matrix clients. There are many possible conferencing architectures possible for
5+
Matrix (Multipoint Conferencing Unit (MCU); Stream Forwarding Unit (SFU); Peer-
6+
to-Peer mesh (P2P), etc; events shared in the group room; events shared 1:1;
7+
possibly even out-of-band signalling).
8+
9+
This is a starting point for a naive MCU implementation which could provide one
10+
possible Matrix-wide solution in future, which retains backwards compatibility
11+
with standard 1:1 calling.
12+
13+
* A client chooses to initiate a conference for a given room by starting a
14+
voice or video call with a 'conference focus' user. This is a virtual user
15+
(typically Application Service) which implements a conferencing bridge. It
16+
isn't defined how the client discovers or selects this user.
17+
18+
* The conference focus user MUST join the room in which the client has
19+
initiated the conference - this may require the client to invite the
20+
conference focus user to the room, depending on the room's `join_rules`. The
21+
conference focus user needs to be in the room to let the bridge eject users
22+
from the conference who have left the room in which it was initiated, and aid
23+
discovery of the conference by other users in the room. The bridge
24+
identifies the room to join based on the user ID by which it was invited.
25+
The format of this identifier is implementation dependent for now.
26+
27+
* If a client leaves the group chat room, they MUST be ejected from the
28+
conference. If a client leaves the 1:1 room with the conference focus user,
29+
they SHOULD be ejected from the conference.
30+
31+
* For now, rooms can contain multiple conference focus users - it's left to
32+
user or client implementation to select which to converge on. In future this
33+
could be mediated using a state event (e.g. `im.vector.call.mcu`), but we
34+
can't do that right now as by default normal users can't set arbitrary state
35+
events on a room.
36+
37+
* To participate in the conference, other clients initiates a standard 1:1
38+
voice or video call to the conference focus user.
39+
40+
* For best UX, clients SHOULD show the ongoing voice/video call in the UI
41+
context of the group room rather than 1:1 with the focus user. If a client
42+
recognises a conference user present in the room, it MAY chose to highlight
43+
this in the UI (e.g. with a "conference ongoing" notification, to aid
44+
discovery). Clients MAY hide the 1:1 room with the focus user (although in
45+
future this room could be used for floor control or other direct
46+
communication with the conference focus)
47+
48+
* When all users have left the conference, the 'conference focus' user SHOULD
49+
leave the room.
50+
51+
* If a conference focus user joins a room but does not receive a 1:1 voice or
52+
video call, it SHOULD time out after a period of time and leave the room.

‎skins/base/css/organisms/RoomView.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,12 @@ limitations under the License.
218218
background-color: blue;
219219
height: 5px;
220220
}
221+
222+
.mx_RoomView_ongoingConfCallNotification {
223+
width: 100%;
224+
text-align: center;
225+
background-color: #ff0064;
226+
color: #fff;
227+
font-weight: bold;
228+
padding: 6px;
229+
}

‎skins/base/css/templates/Login.css‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ limitations under the License.
7575
opacity: 0.8;
7676
}
7777

78+
.mx_Login_create:link {
79+
color: #4a4a4a;
80+
}
81+
82+
.mx_Login_links {
83+
display: block;
84+
text-align: center;
85+
width: 100%;
86+
font-size: 14px;
87+
opacity: 0.8;
88+
}
89+
90+
.mx_Login_links a:link {
91+
color: #4a4a4a;
92+
}
93+
7894
.mx_Login_loader {
7995
position: absolute;
8096
left: 50%;
@@ -85,12 +101,10 @@ limitations under the License.
85101
color: #ff2020;
86102
font-weight: bold;
87103
text-align: center;
104+
/*
88105
height: 24px;
106+
*/
89107
margin-top: 12px;
90108
margin-bottom: 12px;
91109
}
92110

93-
.mx_Login_create:link {
94-
color: #4a4a4a;
95-
}
96-

‎skins/base/views/organisms/RoomList.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818

1919
var React = require('react');
2020
var ComponentBroker = require('../../../../src/ComponentBroker');
21-
21+
var CallView = ComponentBroker.get('molecules/voip/CallView');
2222
var RoomDropTarget = ComponentBroker.get('molecules/RoomDropTarget');
2323

2424
var RoomListController = require("../../../../src/controllers/organisms/RoomList");
@@ -28,8 +28,14 @@ module.exports = React.createClass({
2828
mixins: [RoomListController],
2929

3030
render: function() {
31+
var callElement;
32+
if (this.state.show_call_element) {
33+
callElement = <CallView className="mx_MatrixChat_callView"/>
34+
}
35+
3136
return (
3237
<div className="mx_RoomList">
38+
{callElement}
3339
<h2 className="mx_RoomList_favourites_label">Favourites</h2>
3440
<RoomDropTarget text="Drop here to favourite"/>
3541

‎skins/base/views/organisms/RoomView.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ module.exports = React.createClass({
176176
roomEdit = <Loader/>;
177177
}
178178

179+
var conferenceCallNotification = null;
180+
if (this.state.displayConfCallNotification) {
181+
conferenceCallNotification = (
182+
<div className="mx_RoomView_ongoingConfCallNotification" onClick={this.onConferenceNotificationClick}>
183+
Ongoing conference call
184+
</div>
185+
);
186+
}
187+
179188
var fileDropTarget = null;
180189
if (this.state.draggingFile) {
181190
fileDropTarget = <div className="mx_RoomView_fileDropTarget">
@@ -192,6 +201,7 @@ module.exports = React.createClass({
192201
onSettingsClick={this.onSettingsClick} onSaveClick={this.onSaveClick} onCancelClick={this.onCancelClick} />
193202
<div className="mx_RoomView_auxPanel">
194203
<CallView room={this.state.room}/>
204+
{ conferenceCallNotification }
195205
{ roomEdit }
196206
</div>
197207
<div ref="messageWrapper" className="mx_RoomView_messagePanel" onScroll={ this.onMessageListScroll }>

‎skins/base/views/pages/MatrixChat.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var RoomDirectory = ComponentBroker.get('organisms/RoomDirectory');
3030
var MatrixToolbar = ComponentBroker.get('molecules/MatrixToolbar');
3131
var Notifier = ComponentBroker.get('organisms/Notifier');
3232

33-
var MatrixChatController = require("../../../../src/controllers/pages/MatrixChat");
33+
var MatrixChatController = require('../../../../src/controllers/pages/MatrixChat');
3434

3535
// should be atomised
3636
var Loader = require("react-loader");
@@ -75,6 +75,7 @@ module.exports = React.createClass({
7575
break;
7676
}
7777

78+
// TODO: Fix duplication here and do conditionals like we do above
7879
if (Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
7980
return (
8081
<div className="mx_MatrixChat_wrapper">

‎skins/base/views/templates/Login.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ module.exports = React.createClass({
165165
{this.state.errorText}
166166
</div>
167167
<a className="mx_Login_create" onClick={this.showRegister} href="#">Create a new account</a>
168+
<br/>
169+
<div className="mx_Login_links">
170+
<a href="https://medium.com/@Vector">blog</a>&nbsp;&nbsp;&middot;&nbsp;&nbsp;
171+
<a href="https://twitter.com/@VectorCo">twitter</a>&nbsp;&nbsp;&middot;&nbsp;&nbsp;
172+
<a href="https://github.com/vector-im/vector-web">github</a>&nbsp;&nbsp;&middot;&nbsp;&nbsp;
173+
<a href="https://matrix.org">powered by Matrix</a>
174+
</div>
168175
</div>
169176
);
170177
},

‎src/CallHandler.js‎

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ var MatrixClientPeg = require("./MatrixClientPeg");
5757
var Modal = require("./Modal");
5858
var ComponentBroker = require('./ComponentBroker');
5959
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
60+
var ConferenceCall = require("./ConferenceHandler").ConferenceCall;
61+
var ConferenceHandler = require("./ConferenceHandler");
6062
var Matrix = require("matrix-js-sdk");
6163
var dis = require("./dispatcher");
6264

@@ -105,7 +107,7 @@ function _setCallListeners(call) {
105107
play("ringbackAudio");
106108
}
107109
else if (newState === "ended" && oldState === "connected") {
108-
_setCallState(call, call.roomId, "ended");
110+
_setCallState(undefined, call.roomId, "ended");
109111
pause("ringbackAudio");
110112
play("callendAudio");
111113
}
@@ -153,48 +155,64 @@ function _setCallState(call, roomId, status) {
153155
dis.register(function(payload) {
154156
switch (payload.action) {
155157
case 'place_call':
156-
if (calls[payload.room_id]) {
158+
if (module.exports.getAnyActiveCall()) {
159+
Modal.createDialog(ErrorDialog, {
160+
title: "Existing Call",
161+
description: "You are already in a call."
162+
});
157163
return; // don't allow >1 call to be placed.
158164
}
159165
var room = MatrixClientPeg.get().getRoom(payload.room_id);
160166
if (!room) {
161167
console.error("Room %s does not exist.", payload.room_id);
162168
return;
163169
}
170+
171+
function placeCall(newCall) {
172+
_setCallListeners(newCall);
173+
_setCallState(newCall, newCall.roomId, "ringback");
174+
if (payload.type === 'voice') {
175+
newCall.placeVoiceCall();
176+
}
177+
else if (payload.type === 'video') {
178+
newCall.placeVideoCall(
179+
payload.remote_element,
180+
payload.local_element
181+
);
182+
}
183+
else {
184+
console.error("Unknown conf call type: %s", payload.type);
185+
}
186+
}
187+
164188
var members = room.getJoinedMembers();
165-
if (members.length !== 2) {
166-
var text = members.length === 1 ? "yourself." : "more than 2 people.";
189+
if (members.length <= 1) {
167190
Modal.createDialog(ErrorDialog, {
168-
description: "You cannot place a call with " + text
191+
description: "You cannot place a call with yourself."
169192
});
170-
console.error(
171-
"Fail: There are %s joined members in this room, not 2.",
172-
room.getJoinedMembers().length
173-
);
174193
return;
175194
}
176-
console.log("Place %s call in %s", payload.type, payload.room_id);
177-
var call = Matrix.createNewMatrixCall(
178-
MatrixClientPeg.get(), payload.room_id
179-
);
180-
_setCallListeners(call);
181-
_setCallState(call, call.roomId, "ringback");
182-
if (payload.type === 'voice') {
183-
call.placeVoiceCall();
184-
}
185-
else if (payload.type === 'video') {
186-
call.placeVideoCall(
187-
payload.remote_element,
188-
payload.local_element
195+
else if (members.length === 2) {
196+
console.log("Place %s call in %s", payload.type, payload.room_id);
197+
var call = Matrix.createNewMatrixCall(
198+
MatrixClientPeg.get(), payload.room_id
189199
);
200+
placeCall(call);
190201
}
191-
else {
192-
console.error("Unknown call type: %s", payload.type);
202+
else { // > 2
203+
console.log("Place conference call in %s", payload.room_id);
204+
var confCall = new ConferenceCall(
205+
MatrixClientPeg.get(), payload.room_id
206+
);
207+
confCall.setup().done(function(call) {
208+
placeCall(call);
209+
}, function(err) {
210+
console.error("Failed to setup conference call: %s", err);
211+
});
193212
}
194-
195213
break;
196214
case 'incoming_call':
197-
if (calls[payload.call.roomId]) {
215+
if (module.exports.getAnyActiveCall()) {
198216
payload.call.hangup("busy");
199217
return; // don't allow >1 call to be received, hangup newer one.
200218
}
@@ -224,7 +242,40 @@ dis.register(function(payload) {
224242
});
225243

226244
module.exports = {
245+
246+
getCallForRoom: function(roomId) {
247+
return (
248+
module.exports.getCall(roomId) ||
249+
module.exports.getConferenceCall(roomId)
250+
);
251+
},
252+
227253
getCall: function(roomId) {
228254
return calls[roomId] || null;
255+
},
256+
257+
getConferenceCall: function(roomId) {
258+
// search for a conference 1:1 call for this group chat room ID
259+
var activeCall = module.exports.getAnyActiveCall();
260+
if (activeCall && activeCall.confUserId) {
261+
var thisRoomConfUserId = ConferenceHandler.getConferenceUserIdForRoom(
262+
roomId
263+
);
264+
if (thisRoomConfUserId === activeCall.confUserId) {
265+
return activeCall;
266+
}
267+
}
268+
return null;
269+
},
270+
271+
getAnyActiveCall: function() {
272+
var roomsWithCalls = Object.keys(calls);
273+
for (var i = 0; i < roomsWithCalls.length; i++) {
274+
if (calls[roomsWithCalls[i]] &&
275+
calls[roomsWithCalls[i]].call_state !== "ended") {
276+
return calls[roomsWithCalls[i]];
277+
}
278+
}
279+
return null;
229280
}
230281
};

0 commit comments

Comments
 (0)