Skip to content

Commit

Permalink
Merge pull request #398 from nextcloud/mcu-integration
Browse files Browse the repository at this point in the history
MCU integration
  • Loading branch information
Ivansss authored Jun 22, 2018
2 parents f1cbbf2 + 18957e6 commit 1060fb8
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 108 deletions.
8 changes: 5 additions & 3 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@
.then(function() {
self.stopListening(self.activeRoom, 'change:participantInCall');

var participants;
if (OC.getCurrentUser().uid) {
roomChannel.trigger('active', token);

Expand All @@ -406,14 +407,15 @@
self.activeRoom = room;
}
});
participants = self.activeRoom.get('participants');
} else {
// The public page supports only a single room, so the
// active room is already the room for the given token.

self.setRoomMessageForGuest(self.activeRoom.get('participants'));
participants = self.activeRoom.get('participants');
self.setRoomMessageForGuest(participants);
}
// Disable video when entering a room with more than 5 participants.
if (Object.keys(self.activeRoom.get('participants')).length > 5) {
if (participants && Object.keys(participants).length > 5) {
self.disableVideo();
}

Expand Down
137 changes: 132 additions & 5 deletions js/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
this.currentRoomToken = token;
this._trigger('joinRoom', [token]);
this._runPendingChatRequests();
if (this.currentCallToken === token) {
// We were in this call before, join again.
this.joinCall(token);
} else {
this.currentCallToken = null;
}
this._joinRoomSuccess(token, result.ocs.data.sessionId);
}.bind(this),
error: function (result) {
Expand Down Expand Up @@ -270,7 +276,7 @@
// Override in subclasses if necessary.
};

OCA.Talk.Signaling.Base.prototype.leaveCall = function(token) {
OCA.Talk.Signaling.Base.prototype.leaveCall = function(token, keepToken) {

if (!token) {
return;
Expand All @@ -284,7 +290,7 @@
this._trigger('leaveCall', [token]);
this._leaveCallSuccess(token);
// We left the current call.
if (token === this.currentCallToken) {
if (!keepToken && token === this.currentCallToken) {
this.currentCallToken = null;
}
}.bind(this)
Expand Down Expand Up @@ -455,6 +461,10 @@
}
};

OCA.Talk.Signaling.Internal.prototype.forceReconnect = function(/* newSession */) {
console.error("Forced reconnects are not supported with the internal signaling.");
};

OCA.Talk.Signaling.Internal.prototype._sendMessageWithCallback = function(ev) {
var message = [{
ev: ev
Expand Down Expand Up @@ -719,6 +729,7 @@
this.id = 1;
this.pendingMessages = [];
this.connected = false;
this._forceReconnect = false;
this.socket = new WebSocket(this.url);
window.signalingSocket = this.socket;
this.socket.onopen = function(event) {
Expand Down Expand Up @@ -779,18 +790,50 @@
}.bind(this);
};

OCA.Talk.Signaling.Standalone.prototype.disconnect = function() {
if (this.socket) {
OCA.Talk.Signaling.Standalone.prototype.sendBye = function() {
if (this.connected) {
this.doSend({
"type": "bye",
"bye": {}
});
}
this.resumeId = null;
};

OCA.Talk.Signaling.Standalone.prototype.disconnect = function() {
this.sendBye();
if (this.socket) {
this.socket.close();
this.socket = null;
}
OCA.Talk.Signaling.Base.prototype.disconnect.apply(this, arguments);
};

OCA.Talk.Signaling.Standalone.prototype.forceReconnect = function(newSession) {
if (!this.connected) {
if (!newSession) {
// Not connected, will do reconnect anyway.
return;
}

this._forceReconnect = true;
return;
}

this._forceReconnect = false;
if (newSession) {
if (this.currentCallToken) {
// Mark this session as "no longer in the call".
this.leaveCall(this.currentCallToken, true);
}
this.sendBye();
}
if (this.socket) {
// Trigger reconnect.
this.socket.close();
}
};

OCA.Talk.Signaling.Standalone.prototype.sendCallMessage = function(data) {
this.doSend({
"type": "message",
Expand All @@ -804,6 +847,23 @@
});
};

OCA.Talk.Signaling.Standalone.prototype.sendRoomMessage = function(data) {
if (!this.currentCallToken) {
console.warn("Not in a room, not sending room message", data);
return;
}

this.doSend({
"type": "message",
"message": {
"recipient": {
"type": "room"
},
"data": data
}
});
};

OCA.Talk.Signaling.Standalone.prototype.doSend = function(msg, callback) {
if (!this.connected && msg.type !== "hello") {
// Defer sending any messages until the hello rsponse has been
Expand Down Expand Up @@ -833,6 +893,8 @@
}
};
} else {
// Already reconnected with a new session.
this._forceReconnect = false;
var user = OC.getCurrentUser();
var url = OC.linkToOCS('apps/spreed/api/v1/signaling', 2) + 'backend';
msg = {
Expand Down Expand Up @@ -870,6 +932,11 @@

var resumedSession = !!this.resumeId;
this.connected = true;
if (this._forceReconnect && resumedSession) {
console.log("Perform pending forced reconnect");
this.forceReconnect(true);
return;
}
this.sessionId = data.hello.sessionid;
this.resumeId = data.hello.resumeid;
this.features = {};
Expand Down Expand Up @@ -921,6 +988,11 @@
};

OCA.Talk.Signaling.Standalone.prototype._joinRoomSuccess = function(token, nextcloudSessionId) {
if (!this.sessionId) {
console.log("No hello response received yet, not joining room", token);
return;
}

console.log("Join room", token);
this.doSend({
"type": "room",
Expand Down Expand Up @@ -1110,7 +1182,7 @@
OCA.Talk.Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
switch (data.event.type) {
case "update":
this._trigger("usersChanged", [data.event.update.users]);
this._trigger("usersChanged", [data.event.update.users || []]);
this._trigger("participantListChanged");
this.internalSyncRooms();
break;
Expand Down Expand Up @@ -1140,4 +1212,59 @@
this.receiveMessagesAgain = false;
};

OCA.Talk.Signaling.Standalone.prototype.requestOffer = function(sessionid, roomType) {
if (!this.hasFeature("mcu")) {
console.warn("Can't request an offer without a MCU.");
return;
}

if (typeof(sessionid) !== "string") {
// Got a user object.
sessionid = sessionid.sessionId || sessionid.sessionid;
}
console.log("Request offer from", sessionid);
this.doSend({
"type": "message",
"message": {
"recipient": {
"type": "session",
"sessionid": sessionid
},
"data": {
"type": "requestoffer",
"roomType": roomType
}
}
});
};

OCA.Talk.Signaling.Standalone.prototype.sendOffer = function(sessionid, roomType) {
// TODO(jojo): This should go away and "requestOffer" should be used
// instead by peers that want an offer by the MCU. See the calling
// location for further details.
if (!this.hasFeature("mcu")) {
console.warn("Can't send an offer without a MCU.");
return;
}

if (typeof(sessionid) !== "string") {
// Got a user object.
sessionid = sessionid.sessionId || sessionid.sessionid;
}
console.log("Send offer to", sessionid);
this.doSend({
"type": "message",
"message": {
"recipient": {
"type": "session",
"sessionid": sessionid
},
"data": {
"type": "sendoffer",
"roomType": roomType
}
}
});
};

})(OCA, OC, $);
21 changes: 2 additions & 19 deletions js/simplewebrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18145,25 +18145,8 @@

self.emit('localScreenAdded', el);
self.connection.emit('shareScreen');

self.webrtc.peers.forEach(function (existingPeer) {
var peer;
if (existingPeer.type === 'video') {
peer = self.webrtc.createPeer({
id: existingPeer.id,
type: 'screen',
sharemyscreen: true,
enableDataChannels: false,
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 0
},
broadcaster: self.connection.getSessionid(),
});
self.emit('createdPeer', peer);
peer.start();
}
});
// NOTE: we don't create screen peers for existing video peers here,
// this is done by the application code in "webrtc.js".
});
this.webrtc.on('localScreenStopped', function (stream) {
if (self.getLocalScreen()) {
Expand Down
Loading

0 comments on commit 1060fb8

Please sign in to comment.