Add events when participants disconnect

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-09-25 14:19:28 +02:00
Родитель 51a5f8618c
Коммит 9a6c4410a1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
3 изменённых файлов: 39 добавлений и 44 удалений

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

@ -201,26 +201,23 @@ class CallController extends OCSController {
* @return DataResponse
*/
public function leaveCall($token) {
if ($this->userId !== null) {
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
$sessionId = $this->session->get('spreed-session');
$this->session->remove('spreed-session');
try {
$room = $this->manager->getRoomForParticipantByToken($token, $this->userId);
if ($this->userId === null) {
$participant = $room->getParticipantBySession($sessionId);
$room->removeParticipantBySession($participant);
} else {
$participant = $room->getParticipant($this->userId);
if ($participant->getParticipantType() === Participant::USER_SELF_JOINED) {
$room->removeParticipantBySession($participant);
}
} catch (RoomNotFoundException $e) {
} catch (\RuntimeException $e) {
$room->disconnectUserFromAllRooms($participant->getUser());
}
// As a pre-caution we simply disconnect the user from all rooms
$this->manager->disconnectUserFromAllRooms($this->userId);
} else {
$sessionId = $this->session->get('spreed-session');
$this->manager->removeSessionFromAllRooms($sessionId);
} catch (RoomNotFoundException $e) {
} catch (ParticipantNotFoundException $e) {
}
$this->session->remove('spreed-session');
return new DataResponse();
}

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

@ -394,27 +394,6 @@ class Manager {
return $row['sessionId'];
}
/**
* @param string $userId
*/
public function disconnectUserFromAllRooms($userId) {
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
->set('sessionId', $query->createNamedParameter('0'))
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)));
$query->execute();
}
/**
* @param string $sessionId
*/
public function removeSessionFromAllRooms($sessionId) {
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)));
$query->execute();
}
/**
* @param string $userId
* @return string[]

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

@ -407,6 +407,8 @@ class Room {
public function enterRoomAsUser($userId, $password) {
$this->dispatcher->dispatch(self::class . '::preUserEnterRoom', new GenericEvent($this));
$this->disconnectUserFromAllRooms($userId);
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
->set('sessionId', $query->createParameter('sessionId'))
@ -436,18 +438,35 @@ class Room {
$query->execute();
}
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
->set('sessionId', $query->createNamedParameter('0'))
->where($query->expr()->neq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($userId)));
$query->execute();
$this->dispatcher->dispatch(self::class . '::postUserEnterRoom', new GenericEvent($this));
return $sessionId;
}
/**
* @param string $userId
*/
public function disconnectUserFromAllRooms($userId) {
$this->dispatcher->dispatch(self::class . '::preUserDisconnectRoom', new GenericEvent($this));
// Reset sessions on all normal rooms
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
->set('sessionId', $query->createNamedParameter('0'))
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->neq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
$query->execute();
// And kill session on all self joined rooms
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->eq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
$query->execute();
$this->dispatcher->dispatch(self::class . '::postUserDisconnectRoom', new GenericEvent($this));
}
/**
* @param string $password
* @return string