Skip to content

Commit

Permalink
Actual lobby page
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 28, 2019
1 parent 25b1dfd commit 044322e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
5 changes: 5 additions & 0 deletions js/lobby.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).ready(function(){
setTimeout(function() {
window.location.reload();
}, 5000);
});
13 changes: 10 additions & 3 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Spreed\Participant;
use OCA\Spreed\Room;
use OCA\Spreed\TalkSession;
use OCA\Spreed\Webinary;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
Expand Down Expand Up @@ -224,13 +225,14 @@ protected function guestEnterRoom(string $token, string $password): Response {
]));
}

$this->talkSession->removePasswordForRoom($token);
if ($room->hasPassword()) {
$passwordVerification = $room->verifyPassword($password);
$password = $password !== '' ? $password : (string) $this->talkSession->getPasswordForRoom($token);

$passwordVerification = $room->verifyPassword($password);
if ($passwordVerification['result']) {
$this->talkSession->setPasswordForRoom($token, $token);
$this->talkSession->setPasswordForRoom($token, $password);
} else {
$this->talkSession->removePasswordForRoom($token);
if ($passwordVerification['url'] === '') {
return new TemplateResponse($this->appName, 'authenticate', [], 'guest');
}
Expand All @@ -239,6 +241,11 @@ protected function guestEnterRoom(string $token, string $password): Response {
}
}

if ($room->getLobbyState() === Webinary::MODERATORS_ONLY) {
$response = new TemplateResponse('spreed', 'lobby', [], 'error');
return $response;
}

$params = [
'token' => $token,
'signaling-settings' => $this->config->getSettings($this->userId),
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,11 @@ public function joinRoom(string $token, string $password = ''): DataResponse {

$user = $this->userManager->get($this->userId);
try {
$result = $room->verifyPassword((string) $this->session->getPasswordForRoom($token));
if ($user instanceof IUser) {
$newSessionId = $room->joinRoom($user, $password, $this->session->getPasswordForRoom($token) === $room->getToken());
$newSessionId = $room->joinRoom($user, $password, $result['result']);
} else {
$newSessionId = $room->joinRoomGuest($password, $this->session->getPasswordForRoom($token) === $room->getToken());
$newSessionId = $room->joinRoomGuest($password, $result['result']);
}
} catch (InvalidPasswordException $e) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Spreed\Room;
use OCA\Spreed\Signaling\Messages;
use OCA\Spreed\TalkSession;
use OCA\Spreed\Webinary;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -163,11 +164,19 @@ public function pullMessages(string $token): DataResponse {
}

$room = $this->manager->getRoomForSession($this->userId, $sessionId);
$participant = $room->getParticipantBySession($sessionId);

if (!$participant->hasModeratorPermissions() &&
$room->getLobbyState() !== Webinary::ALL_PARTICIPANTS) {
throw new RoomNotFoundException('Lobby enabled');
}

$pingTimestamp = $this->timeFactory->getTime();
$room->ping($this->userId, $sessionId, $pingTimestamp);
} catch (RoomNotFoundException $e) {
return new DataResponse([['type' => 'usersInRoom', 'data' => []]], Http::STATUS_NOT_FOUND);
} catch (ParticipantNotFoundException $e) {
return new DataResponse([['type' => 'usersInRoom', 'data' => []]], Http::STATUS_NOT_FOUND);
}

while ($seconds > 0) {
Expand Down
22 changes: 13 additions & 9 deletions lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,39 @@ public function beforeController($controller, $methodName): void {
protected function getLoggedIn(AEnvironmentAwareController $controller, bool $moderatorRequired): void {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
$controller->setRoom($room);

$participant = $room->getParticipant($this->userId);
$controller->setParticipant($participant);

if ($moderatorRequired && !$participant->hasModeratorPermissions(false)) {
throw new NotAModeratorException();
}

$controller->setRoom($room);
$controller->setParticipant($participant);
}

/**
* @param AEnvironmentAwareController $controller
* @param bool $moderatorRequired
* @throws NotAModeratorException
* @throws ParticipantNotFoundException
*/
protected function getLoggedInOrGuest(AEnvironmentAwareController $controller, bool $moderatorRequired): void {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
$controller->setRoom($room);

if ($this->userId !== null) {
$participant = $room->getParticipant($this->userId);
} else {
$sessionId = $this->talkSession->getSessionForRoom($token);
$participant = $room->getParticipantBySession($sessionId);
}
$controller->setParticipant($participant);

if ($moderatorRequired && !$participant->hasModeratorPermissions()) {
throw new NotAModeratorException();
}

$controller->setRoom($room);
$controller->setParticipant($participant);
}

/**
Expand All @@ -167,13 +169,15 @@ protected function checkReadOnlyState(AEnvironmentAwareController $controller):
protected function checkLobbyState(AEnvironmentAwareController $controller): void {
try {
$this->getLoggedInOrGuest($controller, true);
return;
} catch (NotAModeratorException $e) {
$room = $controller->getRoom();
if (!$room instanceof Room || $room->getLobbyState() === Webinary::ALL_PARTICIPANTS) {
throw new LobbyException();
}
} catch (ParticipantNotFoundException $e) {
}

$room = $controller->getRoom();
if (!$room instanceof Room || $room->getLobbyState() !== Webinary::ALL_PARTICIPANTS) {
throw new LobbyException();
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions templates/lobby.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
script('spreed', 'lobby');
?>
<div class="error">
<h2><?php p($l->t('Lobby')); ?></h2>
<p><?php p($l->t('Please stand by')); ?></p>
</div>

0 comments on commit 044322e

Please sign in to comment.