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

Fix current user not included in user list returned by signaling #1522

Merged
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
17 changes: 13 additions & 4 deletions lib/Controller/SignalingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public function pullMessages($token) {
}

$room = $this->manager->getRoomForSession($this->userId, $sessionId);
$room->ping($this->userId, $sessionId, time());

$pingTimestamp = time();
$room->ping($this->userId, $sessionId, $pingTimestamp);
} catch (RoomNotFoundException $e) {
return new DataResponse([['type' => 'usersInRoom', 'data' => []]], Http::STATUS_NOT_FOUND);
}
Expand Down Expand Up @@ -204,7 +206,7 @@ public function pullMessages($token) {
try {
// Add an update of the room participants at the end of the waiting
$room = $this->manager->getRoomForSession($this->userId, $sessionId);
$data[] = ['type' => 'usersInRoom', 'data' => $this->getUsersInRoom($room)];
$data[] = ['type' => 'usersInRoom', 'data' => $this->getUsersInRoom($room, $pingTimestamp)];
} catch (RoomNotFoundException $e) {
$data[] = ['type' => 'usersInRoom', 'data' => []];
return new DataResponse($data, Http::STATUS_NOT_FOUND);
Expand All @@ -215,11 +217,18 @@ public function pullMessages($token) {

/**
* @param Room $room
* @param int pingTimestamp
* @return array[]
*/
protected function getUsersInRoom(Room $room): array {
protected function getUsersInRoom(Room $room, int $pingTimestamp): array {
$usersInRoom = [];
$participants = $room->getParticipants(time() - 30);
// Get participants active in the last 30 seconds, or since the last
// signaling ping of the current user if it was done more than 30
// seconds ago.
$timestamp = min(time() - 30, $pingTimestamp);
// "- 1" is needed because only the participants whose last ping is
// greater than the given timestamp are returned.
$participants = $room->getParticipants($timestamp - 1);
foreach ($participants as $participant) {
if ($participant->getSessionId() === '0') {
// User is not active
Expand Down