Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split "being in a room" from "calling" #459

Merged
merged 4 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<bugs>https://github.com/nextcloud/spreed/issues</bugs>
<repository type="git">https://github.com/nextcloud/spreed.git</repository>

<version>2.1.9</version>
<version>2.1.10</version>

<dependencies>
<nextcloud min-version="13" max-version="13" />
Expand Down
18 changes: 18 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#joinRoom',
'url' => '/api/{apiVersion}/room/{token}/participants/active',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#exitRoom',
'url' => '/api/{apiVersion}/room/{token}/participants/active',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'Room#promoteModerator',
'url' => '/api/{apiVersion}/room/{token}/moderators',
Expand Down
46 changes: 33 additions & 13 deletions docs/api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,38 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
* Method: `DELETE`
* Endpoint: `/room/{token}/participants/self`

* Response:
- Header:
+ `200 OK`
+ `404 Not Found` When the room could not be found for the participant

### Join a room (available for call and chat)

* Method: `POST`
* Endpoint: `/room/{token}/participants/active`
* Data:

field | type | Description
------|------|------------
`password` | string | Optional: Password is only required for users which are of type `4` or `5` and only when the room has `hasPassword` set to true.

* Response:
- Header:
+ `200 OK`
+ `403 Forbidden` When the password is required and didn't match
+ `404 Not Found` When the room could not be found for the participant

- Data:

field | type | Description
------|------|------------
`sessionId` | string | 512 character long string

### Leave a room (not available for call and chat anymore)

* Method: `DELETE`
* Endpoint: `/room/{token}/participants/active`

* Response:
- Header:
+ `200 OK`
Expand Down Expand Up @@ -347,24 +379,12 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`

* Method: `POST`
* Endpoint: `/call/{token}`
* Data:

field | type | Description
------|------|------------
`password` | string | Optional: Password is only required for users which are of type `4` or `5` and only when the room has `hasPassword` set to true.

* Response:
- Header:
+ `200 OK`
+ `403 Forbidden` When the password is required and didn't match
+ `404 Not Found` When the room could not be found for the participant

- Data:

field | type | Description
------|------|------------
`sessionId` | string | 512 character long string

### Send ping to keep the call alive

* Method: `POST`
Expand All @@ -375,7 +395,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
+ `200 OK`
+ `404 Not Found` When the room could not be found for the participant

### Leave a call (but staying in the room for future calls)
### Leave a call (but staying in the room for future calls and chat)

* Method: `DELETE`
* Endpoint: `/call/{token}`
Expand Down
25 changes: 13 additions & 12 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@

self.setRoomMessageForGuest(self.activeRoom.get('participants'));
}

// Disable video when entering a room with more than 5 participants.
if (Object.keys(self.activeRoom.get('participants')).length > 5) {
self.disableVideo();
Expand Down Expand Up @@ -525,18 +524,10 @@
this._registerPageEvents();
this.initShareRoomClipboard();

var token = $('#app').attr('data-token');
if (token) {
if (OCA.SpreedMe.webrtc.sessionReady) {
OCA.SpreedMe.Calls.join(token);
} else {
OCA.SpreedMe.webrtc.once('connectionReady', function() {
OCA.SpreedMe.Calls.join(token);
});
}
}
OCA.SpreedMe.Calls.showCamera();

var token = $('#app').attr('data-token');

if (oc_current_user) {
this._showRoomList();
this.signaling.setRoomCollection(this._rooms)
Expand All @@ -557,10 +548,20 @@
}

this.initAudioVideoSettings(configuration);

if (token) {
if (OCA.SpreedMe.webrtc.sessionReady) {
OCA.SpreedMe.Calls.joinRoom(token);
} else {
OCA.SpreedMe.webrtc.once('connectionReady', function() {
OCA.SpreedMe.Calls.joinRoom(token);
});
}
}
},
_onPopState: function(params) {
if (!_.isUndefined(params.token)) {
OCA.SpreedMe.Calls.join(params.token);
OCA.SpreedMe.Calls.joinRoom(params.token);
}
},
onDocumentClick: function(event) {
Expand Down
20 changes: 16 additions & 4 deletions js/calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
OC.Util.History.pushState({
token: token
}, OC.generateUrl('/call/' + token));
this.join(token);
this.joinRoom(token);
},
createOneToOneVideoCall: function(recipientUserId) {
console.log("Creating one-to-one video call", recipientUserId);
Expand Down Expand Up @@ -81,7 +81,15 @@
success: _.bind(this._createCallSuccessHandle, this)
});
},
join: function(token) {
joinRoom: function(token) {
if (signaling.currentRoomToken === token) {
return;
}

OCA.SpreedMe.webrtc.leaveRoom();
OCA.SpreedMe.webrtc.joinRoom(token);
},
joinCall: function(token) {
if (signaling.currentCallToken === token) {
return;
}
Expand All @@ -90,8 +98,12 @@
$('.videoView').addClass('hidden');
$('#app-content').addClass('icon-loading');

OCA.SpreedMe.webrtc.leaveRoom();
OCA.SpreedMe.webrtc.joinRoom(token);
OCA.SpreedMe.webrtc.leaveCall();
OCA.SpreedMe.webrtc.joinCall(token);
},
leaveCall: function(token) {
$('#app-content').removeClass('incall');
OCA.SpreedMe.webrtc.leaveCall();
},
leaveCurrentCall: function(deleter) {
OCA.SpreedMe.webrtc.leaveRoom();
Expand Down
74 changes: 58 additions & 16 deletions js/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
function SignalingBase(settings) {
this.settings = settings;
this.sessionId = '';
this.currentRoomToken = null;
this.currentCallToken = null;
this.handlers = {};
this.features = {};
Expand Down Expand Up @@ -61,12 +62,16 @@

SignalingBase.prototype.emit = function(ev, data) {
switch (ev) {
case 'join':
var callback = arguments[2];
var token = data;
this.joinCall(token, callback);
case 'joinRoom':
this.joinRoom(data);
break;
case 'leave':
case 'joinCall':
this.joinCall(data, arguments[2]);
break;
case 'leaveRoom':
this.leaveCurrentRoom();
break;
case 'leaveCall':
this.leaveCurrentCall();
break;
case 'message':
Expand All @@ -75,6 +80,13 @@
}
};

SignalingBase.prototype.leaveCurrentRoom = function() {
if (this.currentCallToken) {
this.leaveRoom(this.currentCallToken);
this.currentCallToken = null;
}
};

SignalingBase.prototype.leaveCurrentCall = function() {
if (this.currentCallToken) {
this.leaveCall(this.currentCallToken);
Expand Down Expand Up @@ -207,9 +219,9 @@
return defer;
};

InternalSignaling.prototype.joinCall = function(token, callback, password) {
InternalSignaling.prototype.joinRoom = function(token, password) {
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/call', 2) + token,
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token + '/participants/active',
type: 'POST',
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
Expand All @@ -220,14 +232,9 @@
success: function (result) {
console.log("Joined", result);
this.sessionId = result.ocs.data.sessionId;
this.currentCallToken = token;
this.currentRoomToken = token;
this._startPingCall();
this._startPullingMessages();
// We send an empty call description to simplewebrtc since
// usersChanged (webrtc.js) will create/remove peer connections
// with call participants
var callDescription = {'clients': {}};
callback('', callDescription);
}.bind(this),
error: function (result) {
if (result.status === 404 || result.status === 503) {
Expand All @@ -243,7 +250,7 @@
t('spreed','Password required'),
function (result, password) {
if (result && password !== '') {
this.joinCall(token, callback, password);
this.joinRoom(token, password);
}
}.bind(this),
true,
Expand All @@ -262,11 +269,46 @@
});
};

InternalSignaling.prototype.leaveCall = function(token) {
if (token === this.currentCallToken) {
InternalSignaling.prototype.leaveRoom = function(token) {
if (this.currentCallToken) {
this.leaveCall();
}

if (token === this.currentRoomToken) {
this._stopPingCall();
this._closeEventSource();
}

$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token + '/participants/active',
method: 'DELETE',
async: false
});
};

InternalSignaling.prototype.joinCall = function(token, callback) {
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/call', 2) + token,
type: 'POST',
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: function () {
this.currentCallToken = token;
// We send an empty call description to simplewebrtc since
// usersChanged (webrtc.js) will create/remove peer connections
// with call participants
var callDescription = {'clients': {}};
callback('', callDescription);
}.bind(this),
error: function () {
// Room not found or maintenance mode
OC.redirect(OC.generateUrl('apps/spreed'));
}.bind(this)
});
};

InternalSignaling.prototype.leaveCall = function(token) {
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/call', 2) + token,
method: 'DELETE',
Expand Down
24 changes: 19 additions & 5 deletions js/simplewebrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18185,14 +18185,22 @@

SimpleWebRTC.prototype.leaveRoom = function () {
if (this.roomName) {
this.connection.emit('leave');
this.connection.emit('leaveRoom');
this.emit('leftRoom', this.roomName);
this.roomName = undefined;
}
};

SimpleWebRTC.prototype.leaveCall = function () {
if (this.roomName) {
this.connection.emit('leaveCall');
while (this.webrtc.peers.length) {
this.webrtc.peers[0].end();
}
if (this.getLocalScreen()) {
this.stopScreenShare();
}
this.emit('leftRoom', this.roomName);
this.emit('leftCall', this.roomName);
this.roomName = undefined;
}
};
Expand Down Expand Up @@ -18249,10 +18257,16 @@
});
};

SimpleWebRTC.prototype.joinRoom = function (name, cb) {
SimpleWebRTC.prototype.joinRoom = function (name) {
this.connection.emit('joinRoom', name);
this.roomName = name;
this.emit('joinedRoom', name);
};

SimpleWebRTC.prototype.joinCall = function (name, cb) {
var self = this;
this.roomName = name;
this.connection.emit('join', name, function (err, roomDescription) {
this.connection.emit('joinCall', name, function (err, roomDescription) {
console.log('join CB', err, roomDescription);
if (err) {
self.emit('error', err);
Expand Down Expand Up @@ -18282,7 +18296,7 @@
}

if (cb) cb(err, roomDescription);
self.emit('joinedRoom', name);
self.emit('joinedCall', name);
});
};

Expand Down
Loading