Add hook to allow returning additional data for clients joining a room.

Signed-off-by: Joachim Bauch <bauch@struktur.de>
This commit is contained in:
Joachim Bauch 2018-12-18 14:09:12 +01:00
Родитель 02d0f43e5e
Коммит 3ad0b1bd97
Не удалось извлечь подпись
2 изменённых файлов: 82 добавлений и 0 удалений

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

@ -37,6 +37,8 @@ use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class SignalingController extends OCSController {
/** @var Config */
@ -53,6 +55,8 @@ class SignalingController extends OCSController {
private $userId;
/** @var IUserManager */
private $userManager;
/** @var EventDispatcherInterface */
private $dispatcher;
/**
* @param string $appName
@ -63,6 +67,7 @@ class SignalingController extends OCSController {
* @param IDBConnection $connection
* @param Messages $messages
* @param IUserManager $userManager
* @param EventDispatcherInterface $dispatcher
* @param string $UserId
*/
public function __construct($appName,
@ -73,6 +78,7 @@ class SignalingController extends OCSController {
IDBConnection $connection,
Messages $messages,
IUserManager $userManager,
EventDispatcherInterface $dispatcher,
$UserId) {
parent::__construct($appName, $request);
$this->config = $config;
@ -81,6 +87,7 @@ class SignalingController extends OCSController {
$this->manager = $manager;
$this->messages = $messages;
$this->userManager = $userManager;
$this->dispatcher = $dispatcher;
$this->userId = $UserId;
}
@ -411,6 +418,14 @@ class SignalingController extends OCSController {
}
}
$event = new GenericEvent($room, [
'action' => $action,
'participant' => $participant,
'sessionid' => $sessionId,
'userid' => $userId,
]);
$this->dispatcher->dispatch(self::class . '::signalingBackendRoom', $event);
$response = [
'type' => 'room',
'room' => [
@ -422,6 +437,9 @@ class SignalingController extends OCSController {
],
],
];
if ($event->hasArgument('roomSession')) {
$response['room']['session'] = $event->getArgument('roomSession');
}
return new DataResponse($response);
}

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

@ -35,6 +35,8 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class CustomInputSignalingController extends SignalingController {
@ -76,6 +78,9 @@ class SignalingControllerTest extends \Test\TestCase {
/** @var string */
private $userId;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var CustomInputSignalingController */
private $controller;
@ -97,6 +102,7 @@ class SignalingControllerTest extends \Test\TestCase {
$this->manager = $this->createMock(Manager::class);
$this->messages = $this->createMock(Messages::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->dispatcher = \OC::$server->getEventDispatcher();
$this->recreateSignalingController();
}
@ -110,6 +116,7 @@ class SignalingControllerTest extends \Test\TestCase {
$this->dbConnection,
$this->messages,
$this->userManager,
$this->dispatcher,
$this->userId
);
}
@ -514,6 +521,63 @@ class SignalingControllerTest extends \Test\TestCase {
], $result->getData());
}
public function testBackendRoomSessionFromEvent() {
$this->dispatcher->addListener(SignalingController::class . '::signalingBackendRoom', function(GenericEvent $event) {
$room = $event->getSubject();
$event->setArgument('roomSession', [
'foo' => 'bar',
'room' => $room->getToken(),
]);
});
$roomToken = 'the-room';
$roomName = 'the-room-name';
$room = $this->createMock(Room::class);
$this->manager->expects($this->once())
->method('getRoomByToken')
->with($roomToken)
->willReturn($room);
$participant = $this->createMock(Participant::class);
$room->expects($this->once())
->method('getName')
->willReturn($roomName);
$room->expects($this->once())
->method('getParticipant')
->with($this->userId)
->willReturn($participant);
$room->expects($this->atLeastOnce())
->method('getToken')
->willReturn($roomToken);
$room->expects($this->once())
->method('getType')
->willReturn(Room::ONE_TO_ONE_CALL);
$result = $this->performBackendRequest([
'type' => 'room',
'room' => [
'roomid' => $roomToken,
'userid' => $this->userId,
'sessionid' => '',
],
]);
$this->assertSame([
'type' => 'room',
'room' => [
'version' => '1.0',
'roomid' => $roomToken,
'properties' => [
'name' => $roomName,
'type' => Room::ONE_TO_ONE_CALL,
],
'session' => [
'foo' => 'bar',
'room' => $roomToken,
],
],
], $result->getData());
}
public function testBackendPingUnknownRoom() {
$roomToken = 'the-room';
$room = $this->createMock(Room::class);