Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-06-12 17:03:56 +02:00
Родитель 2bf3c6c37d
Коммит cdada8370a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
7 изменённых файлов: 194 добавлений и 135 удалений

Просмотреть файл

@ -38,87 +38,117 @@ return [
'url' => '/messages',
'verb' => 'GET',
],
[
'name' => 'api#getRooms',
'url' => '/api/room',
'verb' => 'GET',
],
[
'name' => 'api#makePublic',
'url' => '/api/room/public',
'verb' => 'POST',
],
[
'name' => 'api#makePrivate',
'url' => '/api/room/public',
'verb' => 'DELETE',
],
[
'name' => 'api#getRoom',
'url' => '/api/room/{token}',
'verb' => 'GET',
'requirements' => ['token' => '^[a-z0-9]{4,30}$'],
],
[
'name' => 'api#renameRoom',
'url' => '/api/room/{roomId}',
'verb' => 'PUT',
'requirements' => ['roomId' => '\d+'],
],
[
'name' => 'api#addParticipantToRoom',
'url' => '/api/room/{roomId}',
'verb' => 'POST',
'requirements' => ['roomId' => '\d+'],
],
[
'name' => 'api#leaveRoom',
'url' => '/api/room/{roomId}',
'verb' => 'DELETE',
'requirements' => ['roomId' => '\d+'],
],
[
'name' => 'api#getPeersInRoom',
'url' => '/api/room/{token}/peers',
'verb' => 'GET',
'requirements' => ['token' => '^[a-z0-9]{4,30}$'],
],
[
'name' => 'api#joinRoom',
'url' => '/api/room/{token}/join',
'verb' => 'POST',
'requirements' => ['token' => '^[a-z0-9]{4,30}$'],
],
[
'name' => 'api#ping',
'url' => '/api/ping',
'verb' => 'POST',
'requirements' => ['token' => '^[a-z0-9]{4,30}$'],
],
[
'name' => 'api#leave',
'url' => '/api/leave',
'verb' => 'DELETE',
],
[
'name' => 'AppSettings#setSpreedSettings',
'url' => '/settings/admin',
'verb' => 'POST',
],
],
'ocs' => [
[
'name' => 'api#getRooms',
'url' => '/api/{apiVersion}/room',
'verb' => 'GET',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#makePublic',
'url' => '/api/{apiVersion}/room/public',
'verb' => 'POST',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#makePrivate',
'url' => '/api/{apiVersion}/room/public',
'verb' => 'DELETE',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#getRoom',
'url' => '/api/{apiVersion}/room/{token}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'api#renameRoom',
'url' => '/api/{apiVersion}/room/{roomId}',
'verb' => 'PUT',
'requirements' => [
'apiVersion' => 'v1',
'roomId' => '\d+'
],
],
[
'name' => 'api#addParticipantToRoom',
'url' => '/api/{apiVersion}/room/{roomId}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'roomId' => '\d+'
],
],
[
'name' => 'api#leaveRoom',
'url' => '/api/{apiVersion}/room/{roomId}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1',
'roomId' => '\d+'
],
],
[
'name' => 'api#getPeersInRoom',
'url' => '/api/{apiVersion}/room/{token}/peers',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'api#joinRoom',
'url' => '/api/{apiVersion}/room/{token}/join',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'api#ping',
'url' => '/api/{apiVersion}/ping',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1',
'token' => '^[a-z0-9]{4,30}$',
],
],
[
'name' => 'api#leave',
'url' => '/api/{apiVersion}/leave',
'verb' => 'DELETE',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#createOneToOneRoom',
'url' => '/api/oneToOne',
'url' => '/api/{apiVersion}/oneToOne',
'verb' => 'PUT',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#createGroupRoom',
'url' => '/api/group',
'url' => '/api/{apiVersion}/group',
'verb' => 'PUT',
'requirements' => ['apiVersion' => 'v1'],
],
[
'name' => 'api#createPublicRoom',
'url' => '/api/public',
'url' => '/api/{apiVersion}/public',
'verb' => 'PUT',
'requirements' => ['apiVersion' => 'v1'],
],
],
];

Просмотреть файл

@ -387,9 +387,13 @@
});
} else {
$.ajax({
url: OC.generateUrl('/apps/spreed/api/room/') + token,
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token,
type: 'GET',
success: function(data) {
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: function(result) {
var data = result.ocs.data;
self.setRoomMessageForGuest(data.participants);
self.setPageTitle(data.displayName);
if (Object.keys(data.participants).length > 5) {

Просмотреть файл

@ -31,7 +31,15 @@
comparator: function(model) {
return -(model.get('lastPing'));
},
url: OC.generateUrl('/apps/spreed/api/room')
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
/**
* @param result
* @param response
* @returns {Array}
*/
parse: function(result, response) {
return result.ocs.data;
}
});
OCA.SpreedMe.Models.RoomCollection = RoomCollection;

Просмотреть файл

@ -23,7 +23,8 @@
showCamera: function() {
$('.videoView').removeClass('hidden');
},
_createRoomSuccessHandle: function(data) {
_createRoomSuccessHandle: function(ocsResponse) {
var data = ocsResponse.ocs.data;
OC.Util.History.pushState({
token: data.token
}, OC.generateUrl('/call/' + data.token));
@ -32,26 +33,35 @@
createOneToOneVideoCall: function(recipientUserId) {
console.log(recipientUserId);
$.ajax({
url: OC.generateUrl('/apps/spreed/api/oneToOne'),
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'oneToOne',
type: 'PUT',
data: 'targetUserName='+recipientUserId,
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: _.bind(this._createRoomSuccessHandle, this)
});
},
createGroupVideoCall: function(groupId) {
console.log(groupId);
$.ajax({
url: OC.generateUrl('/apps/spreed/api/group'),
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'group',
type: 'PUT',
data: 'targetGroupName='+groupId,
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: _.bind(this._createRoomSuccessHandle, this)
});
},
createPublicVideoCall: function() {
console.log("Creating a new public room.");
$.ajax({
url: OC.generateUrl('/apps/spreed/api/public'),
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'public',
type: 'PUT',
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: _.bind(this._createRoomSuccessHandle, this)
});
},
@ -81,7 +91,10 @@
},
peers: function(token) {
return $.ajax({
url: OC.generateUrl('/apps/spreed/api/room/{token}/peers', {token: token})
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token + '/peers'
});
},
ping: function() {
@ -90,7 +103,7 @@
}
$.post(
OC.generateUrl('/apps/spreed/api/ping'),
OC.linkToOCS('apps/spreed/api/v1', 2) + 'ping',
{
token: OCA.SpreedMe.Rooms.currentRoom()
}
@ -108,7 +121,7 @@
},
leaveAllRooms: function() {
$.ajax({
url: OC.generateUrl('/apps/spreed/api/leave'),
url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'leave',
method: 'DELETE',
async: false
});

Просмотреть файл

@ -245,7 +245,7 @@
// This should be the only case
if ((this.model.get('type') !== 1) && (roomName.length <= 200)) {
$.ajax({
url: OC.generateUrl('/apps/spreed/api/room/') + this.model.get('id'),
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.model.get('id'),
type: 'PUT',
data: 'roomName='+roomName,
success: function() {
@ -260,7 +260,7 @@
// This should be the only case
if (this.model.get('type') !== 3) {
$.ajax({
url: OC.generateUrl('/apps/spreed/api/room/public'),
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + 'public',
type: 'POST',
data: 'roomId='+this.model.get('id'),
success: function() {
@ -275,7 +275,7 @@
// This should be the only case
if (this.model.get('type') === 3) {
$.ajax({
url: OC.generateUrl('/apps/spreed/api/room/public'),
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + 'public',
type: 'DELETE',
data: 'roomId='+this.model.get('id'),
success: function() {
@ -295,7 +295,7 @@
this.$el.slideUp();
$.ajax({
url: OC.generateUrl('/apps/spreed/api/room/') + this.model.get('id'),
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.model.get('id'),
type: 'DELETE'
});
},
@ -520,7 +520,7 @@
var app = OCA.SpreedMe.app;
$.post(
OC.generateUrl('/apps/spreed/api/room/') + _this.model.get('id'),
OC.linkToOCS('apps/spreed/api/v1/room', 2) + _this.model.get('id'),
{
newParticipant: e.val
}

Просмотреть файл

@ -33,16 +33,20 @@ var sessionId = '';
// The clients will then use the message command to exchange
// their signalling information.
var callback = arguments[2];
$.post(
OC.generateUrl('/apps/spreed/api/room/{token}/join', {token: data}),
function(sessionData) {
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + data + '/join',
type: 'POST',
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: function (sessionData) {
sessionId = sessionData.sessionId;
OCA.SpreedMe.Rooms.peers(data).then(function (result) {
var roomDescription = {
'clients': {}
};
result.forEach(function(element) {
result.ocs.data.forEach(function (element) {
if (sessionId !== element['sessionId']) {
roomDescription['clients'][element['sessionId']] = {
'video': true
@ -53,7 +57,7 @@ var sessionId = '';
});
}
);
});
break;
case 'message':
if(data.type === 'answer') {

Просмотреть файл

@ -29,9 +29,9 @@ use OCA\Spreed\Exceptions\RoomNotFoundException;
use OCA\Spreed\Manager;
use OCA\Spreed\Room;
use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
@ -42,7 +42,7 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\Notification\IManager as INotificationManager;
class ApiController extends Controller {
class ApiController extends OCSController {
/** @var string */
private $userId;
/** @var IL10N */
@ -103,7 +103,7 @@ class ApiController extends Controller {
*
* @NoAdminRequired
*
* @return JSONResponse
* @return DataResponse
*/
public function getRooms() {
$rooms = $this->manager->getRoomsForParticipant($this->userId);
@ -116,21 +116,21 @@ class ApiController extends Controller {
}
}
return new JSONResponse($return);
return new DataResponse($return);
}
/**
* @PublicPage
*
* @param string $token
* @return JSONResponse
* @return DataResponse
*/
public function getRoom($token) {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
return new JSONResponse($this->formatRoom($room));
return new DataResponse($this->formatRoom($room));
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
}
@ -254,13 +254,13 @@ class ApiController extends Controller {
* @PublicPage
*
* @param string $token
* @return JSONResponse
* @return DataResponse
*/
public function getPeersInRoom($token) {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
/** @var array[] $participants */
@ -289,7 +289,7 @@ class ApiController extends Controller {
];
}
return new JSONResponse($result);
return new DataResponse($result);
}
/**
@ -298,20 +298,20 @@ class ApiController extends Controller {
* @NoAdminRequired
*
* @param string $targetUserName
* @return JSONResponse
* @return DataResponse
*/
public function createOneToOneRoom($targetUserName) {
// Get the user
$targetUser = $this->userManager->get($targetUserName);
$currentUser = $this->userManager->get($this->userId);
if(!($targetUser instanceof IUser)) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
// If room exists: Reuse that one, otherwise create a new one.
try {
$room = $this->manager->getOne2OneRoom($this->userId, $targetUser->getUID());
return new JSONResponse(['token' => $room->getToken()], Http::STATUS_OK);
return new DataResponse(['token' => $room->getToken()], Http::STATUS_OK);
} catch (RoomNotFoundException $e) {
$room = $this->manager->createOne2OneRoom();
$room->addUser($currentUser);
@ -319,7 +319,7 @@ class ApiController extends Controller {
$room->addUser($targetUser);
$this->createNotification($currentUser, $targetUser, $room);
return new JSONResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
return new DataResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
}
}
@ -329,14 +329,14 @@ class ApiController extends Controller {
* @NoAdminRequired
*
* @param string $targetGroupName
* @return JSONResponse
* @return DataResponse
*/
public function createGroupRoom($targetGroupName) {
$targetGroup = $this->groupManager->get($targetGroupName);
$currentUser = $this->userManager->get($this->userId);
if(!($targetGroup instanceof IGroup)) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$usersInGroup = $targetGroup->getUsers();
@ -355,13 +355,13 @@ class ApiController extends Controller {
}
}
return new JSONResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
return new DataResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
}
/**
* @NoAdminRequired
*
* @return JSONResponse
* @return DataResponse
*/
public function createPublicRoom() {
$currentUser = $this->userManager->get($this->userId);
@ -370,7 +370,7 @@ class ApiController extends Controller {
$room = $this->manager->createPublicRoom();
$room->addUser($currentUser);
return new JSONResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
return new DataResponse(['token' => $room->getToken()], Http::STATUS_CREATED);
}
/**
@ -378,23 +378,23 @@ class ApiController extends Controller {
*
* @param int $roomId
* @param string $roomName
* @return JSONResponse
* @return DataResponse
*/
public function renameRoom($roomId, $roomName) {
try {
$room = $this->manager->getRoomForParticipant($roomId, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (strlen($roomName) > 200) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
if (!$room->setName($roomName)) {
return new JSONResponse([], Http::STATUS_METHOD_NOT_ALLOWED);
return new DataResponse([], Http::STATUS_METHOD_NOT_ALLOWED);
}
return new JSONResponse([]);
return new DataResponse([]);
}
/**
@ -402,24 +402,24 @@ class ApiController extends Controller {
*
* @param int $roomId
* @param string $newParticipant
* @return JSONResponse
* @return DataResponse
*/
public function addParticipantToRoom($roomId, $newParticipant) {
try {
$room = $this->manager->getRoomForParticipant($roomId, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$participants = $room->getParticipants();
if (isset($participants['users'][$newParticipant])) {
return new JSONResponse([]);
return new DataResponse([]);
}
$currentUser = $this->userManager->get($this->userId);
$newUser = $this->userManager->get($newParticipant);
if (!$newUser instanceof IUser) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
@ -429,26 +429,26 @@ class ApiController extends Controller {
$room->addUser($newUser);
$this->createNotification($currentUser, $newUser, $room);
return new JSONResponse(['type' => $room->getType()]);
return new DataResponse(['type' => $room->getType()]);
}
$room->addUser($newUser);
$this->createNotification($currentUser, $newUser, $room);
return new JSONResponse([]);
return new DataResponse([]);
}
/**
* @NoAdminRequired
*
* @param int $roomId
* @return JSONResponse
* @return DataResponse
*/
public function leaveRoom($roomId) {
try {
$room = $this->manager->getRoomForParticipant($roomId, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($room->getType() === Room::ONE_TO_ONE_CALL || $room->getNumberOfParticipants() === 1) {
@ -458,66 +458,66 @@ class ApiController extends Controller {
$room->removeUser($currentUser);
}
return new JSONResponse([]);
return new DataResponse([]);
}
/**
* @NoAdminRequired
*
* @param int $roomId
* @return JSONResponse
* @return DataResponse
*/
public function makePublic($roomId) {
try {
$room = $this->manager->getRoomForParticipant($roomId, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($room->getType() !== Room::PUBLIC_CALL) {
$room->changeType(Room::PUBLIC_CALL);
}
return new JSONResponse();
return new DataResponse();
}
/**
* @NoAdminRequired
*
* @param int $roomId
* @return JSONResponse
* @return DataResponse
*/
public function makePrivate($roomId) {
try {
$room = $this->manager->getRoomForParticipant($roomId, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($room->getType() === Room::PUBLIC_CALL) {
$room->changeType(Room::GROUP_CALL);
}
return new JSONResponse();
return new DataResponse();
}
/**
* @PublicPage
*
* @param string $token
* @return JSONResponse
* @return DataResponse
*/
public function ping($token) {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$sessionId = $this->session->get('spreed-session');
$room->ping($this->userId, $sessionId, time());
return new JSONResponse();
return new DataResponse();
}
/**
@ -525,13 +525,13 @@ class ApiController extends Controller {
* @UseSession
*
* @param string $token
* @return JSONResponse
* @return DataResponse
*/
public function joinRoom($token) {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
} catch (RoomNotFoundException $e) {
return new JSONResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($this->userId !== null) {
@ -548,7 +548,7 @@ class ApiController extends Controller {
$this->session->set('spreed-session', $newSessionId);
$room->ping($this->userId, $newSessionId, time());
return new JSONResponse([
return new DataResponse([
'sessionId' => $newSessionId,
]);
}
@ -557,7 +557,7 @@ class ApiController extends Controller {
* @PublicPage
* @UseSession
*
* @return JSONResponse
* @return DataResponse
*/
public function leave() {
if ($this->userId !== null) {
@ -568,7 +568,7 @@ class ApiController extends Controller {
}
$this->session->remove('spreed-session');
return new JSONResponse();
return new DataResponse();
}
/**