Skip to content

Commit 1060fb8

Browse files
authored
Merge pull request #398 from nextcloud/mcu-integration
MCU integration
2 parents f1cbbf2 + 18957e6 commit 1060fb8

6 files changed

Lines changed: 529 additions & 108 deletions

File tree

js/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@
398398
.then(function() {
399399
self.stopListening(self.activeRoom, 'change:participantInCall');
400400

401+
var participants;
401402
if (OC.getCurrentUser().uid) {
402403
roomChannel.trigger('active', token);
403404

@@ -406,14 +407,15 @@
406407
self.activeRoom = room;
407408
}
408409
});
410+
participants = self.activeRoom.get('participants');
409411
} else {
410412
// The public page supports only a single room, so the
411413
// active room is already the room for the given token.
412-
413-
self.setRoomMessageForGuest(self.activeRoom.get('participants'));
414+
participants = self.activeRoom.get('participants');
415+
self.setRoomMessageForGuest(participants);
414416
}
415417
// Disable video when entering a room with more than 5 participants.
416-
if (Object.keys(self.activeRoom.get('participants')).length > 5) {
418+
if (participants && Object.keys(participants).length > 5) {
417419
self.disableVideo();
418420
}
419421

js/signaling.js

Lines changed: 132 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@
184184
this.currentRoomToken = token;
185185
this._trigger('joinRoom', [token]);
186186
this._runPendingChatRequests();
187+
if (this.currentCallToken === token) {
188+
// We were in this call before, join again.
189+
this.joinCall(token);
190+
} else {
191+
this.currentCallToken = null;
192+
}
187193
this._joinRoomSuccess(token, result.ocs.data.sessionId);
188194
}.bind(this),
189195
error: function (result) {
@@ -270,7 +276,7 @@
270276
// Override in subclasses if necessary.
271277
};
272278

273-
OCA.Talk.Signaling.Base.prototype.leaveCall = function(token) {
279+
OCA.Talk.Signaling.Base.prototype.leaveCall = function(token, keepToken) {
274280

275281
if (!token) {
276282
return;
@@ -284,7 +290,7 @@
284290
this._trigger('leaveCall', [token]);
285291
this._leaveCallSuccess(token);
286292
// We left the current call.
287-
if (token === this.currentCallToken) {
293+
if (!keepToken && token === this.currentCallToken) {
288294
this.currentCallToken = null;
289295
}
290296
}.bind(this)
@@ -455,6 +461,10 @@
455461
}
456462
};
457463

464+
OCA.Talk.Signaling.Internal.prototype.forceReconnect = function(/* newSession */) {
465+
console.error("Forced reconnects are not supported with the internal signaling.");
466+
};
467+
458468
OCA.Talk.Signaling.Internal.prototype._sendMessageWithCallback = function(ev) {
459469
var message = [{
460470
ev: ev
@@ -719,6 +729,7 @@
719729
this.id = 1;
720730
this.pendingMessages = [];
721731
this.connected = false;
732+
this._forceReconnect = false;
722733
this.socket = new WebSocket(this.url);
723734
window.signalingSocket = this.socket;
724735
this.socket.onopen = function(event) {
@@ -779,18 +790,50 @@
779790
}.bind(this);
780791
};
781792

782-
OCA.Talk.Signaling.Standalone.prototype.disconnect = function() {
783-
if (this.socket) {
793+
OCA.Talk.Signaling.Standalone.prototype.sendBye = function() {
794+
if (this.connected) {
784795
this.doSend({
785796
"type": "bye",
786797
"bye": {}
787798
});
799+
}
800+
this.resumeId = null;
801+
};
802+
803+
OCA.Talk.Signaling.Standalone.prototype.disconnect = function() {
804+
this.sendBye();
805+
if (this.socket) {
788806
this.socket.close();
789807
this.socket = null;
790808
}
791809
OCA.Talk.Signaling.Base.prototype.disconnect.apply(this, arguments);
792810
};
793811

812+
OCA.Talk.Signaling.Standalone.prototype.forceReconnect = function(newSession) {
813+
if (!this.connected) {
814+
if (!newSession) {
815+
// Not connected, will do reconnect anyway.
816+
return;
817+
}
818+
819+
this._forceReconnect = true;
820+
return;
821+
}
822+
823+
this._forceReconnect = false;
824+
if (newSession) {
825+
if (this.currentCallToken) {
826+
// Mark this session as "no longer in the call".
827+
this.leaveCall(this.currentCallToken, true);
828+
}
829+
this.sendBye();
830+
}
831+
if (this.socket) {
832+
// Trigger reconnect.
833+
this.socket.close();
834+
}
835+
};
836+
794837
OCA.Talk.Signaling.Standalone.prototype.sendCallMessage = function(data) {
795838
this.doSend({
796839
"type": "message",
@@ -804,6 +847,23 @@
804847
});
805848
};
806849

850+
OCA.Talk.Signaling.Standalone.prototype.sendRoomMessage = function(data) {
851+
if (!this.currentCallToken) {
852+
console.warn("Not in a room, not sending room message", data);
853+
return;
854+
}
855+
856+
this.doSend({
857+
"type": "message",
858+
"message": {
859+
"recipient": {
860+
"type": "room"
861+
},
862+
"data": data
863+
}
864+
});
865+
};
866+
807867
OCA.Talk.Signaling.Standalone.prototype.doSend = function(msg, callback) {
808868
if (!this.connected && msg.type !== "hello") {
809869
// Defer sending any messages until the hello rsponse has been
@@ -833,6 +893,8 @@
833893
}
834894
};
835895
} else {
896+
// Already reconnected with a new session.
897+
this._forceReconnect = false;
836898
var user = OC.getCurrentUser();
837899
var url = OC.linkToOCS('apps/spreed/api/v1/signaling', 2) + 'backend';
838900
msg = {
@@ -870,6 +932,11 @@
870932

871933
var resumedSession = !!this.resumeId;
872934
this.connected = true;
935+
if (this._forceReconnect && resumedSession) {
936+
console.log("Perform pending forced reconnect");
937+
this.forceReconnect(true);
938+
return;
939+
}
873940
this.sessionId = data.hello.sessionid;
874941
this.resumeId = data.hello.resumeid;
875942
this.features = {};
@@ -921,6 +988,11 @@
921988
};
922989

923990
OCA.Talk.Signaling.Standalone.prototype._joinRoomSuccess = function(token, nextcloudSessionId) {
991+
if (!this.sessionId) {
992+
console.log("No hello response received yet, not joining room", token);
993+
return;
994+
}
995+
924996
console.log("Join room", token);
925997
this.doSend({
926998
"type": "room",
@@ -1110,7 +1182,7 @@
11101182
OCA.Talk.Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
11111183
switch (data.event.type) {
11121184
case "update":
1113-
this._trigger("usersChanged", [data.event.update.users]);
1185+
this._trigger("usersChanged", [data.event.update.users || []]);
11141186
this._trigger("participantListChanged");
11151187
this.internalSyncRooms();
11161188
break;
@@ -1140,4 +1212,59 @@
11401212
this.receiveMessagesAgain = false;
11411213
};
11421214

1215+
OCA.Talk.Signaling.Standalone.prototype.requestOffer = function(sessionid, roomType) {
1216+
if (!this.hasFeature("mcu")) {
1217+
console.warn("Can't request an offer without a MCU.");
1218+
return;
1219+
}
1220+
1221+
if (typeof(sessionid) !== "string") {
1222+
// Got a user object.
1223+
sessionid = sessionid.sessionId || sessionid.sessionid;
1224+
}
1225+
console.log("Request offer from", sessionid);
1226+
this.doSend({
1227+
"type": "message",
1228+
"message": {
1229+
"recipient": {
1230+
"type": "session",
1231+
"sessionid": sessionid
1232+
},
1233+
"data": {
1234+
"type": "requestoffer",
1235+
"roomType": roomType
1236+
}
1237+
}
1238+
});
1239+
};
1240+
1241+
OCA.Talk.Signaling.Standalone.prototype.sendOffer = function(sessionid, roomType) {
1242+
// TODO(jojo): This should go away and "requestOffer" should be used
1243+
// instead by peers that want an offer by the MCU. See the calling
1244+
// location for further details.
1245+
if (!this.hasFeature("mcu")) {
1246+
console.warn("Can't send an offer without a MCU.");
1247+
return;
1248+
}
1249+
1250+
if (typeof(sessionid) !== "string") {
1251+
// Got a user object.
1252+
sessionid = sessionid.sessionId || sessionid.sessionid;
1253+
}
1254+
console.log("Send offer to", sessionid);
1255+
this.doSend({
1256+
"type": "message",
1257+
"message": {
1258+
"recipient": {
1259+
"type": "session",
1260+
"sessionid": sessionid
1261+
},
1262+
"data": {
1263+
"type": "sendoffer",
1264+
"roomType": roomType
1265+
}
1266+
}
1267+
});
1268+
};
1269+
11431270
})(OCA, OC, $);

js/simplewebrtc.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18145,25 +18145,8 @@
1814518145

1814618146
self.emit('localScreenAdded', el);
1814718147
self.connection.emit('shareScreen');
18148-
18149-
self.webrtc.peers.forEach(function (existingPeer) {
18150-
var peer;
18151-
if (existingPeer.type === 'video') {
18152-
peer = self.webrtc.createPeer({
18153-
id: existingPeer.id,
18154-
type: 'screen',
18155-
sharemyscreen: true,
18156-
enableDataChannels: false,
18157-
receiveMedia: {
18158-
offerToReceiveAudio: 0,
18159-
offerToReceiveVideo: 0
18160-
},
18161-
broadcaster: self.connection.getSessionid(),
18162-
});
18163-
self.emit('createdPeer', peer);
18164-
peer.start();
18165-
}
18166-
});
18148+
// NOTE: we don't create screen peers for existing video peers here,
18149+
// this is done by the application code in "webrtc.js".
1816718150
});
1816818151
this.webrtc.on('localScreenStopped', function (stream) {
1816918152
if (self.getLocalScreen()) {

0 commit comments

Comments
 (0)