Skip to content

Commit

Permalink
Simplify the code and allow 100 secs as timeout (3 pings and a little…
Browse files Browse the repository at this point in the history
… buffer)

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 10, 2018
1 parent 5468d10 commit 1983bc5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,14 @@ protected function formatRoom(Room $room, Participant $participant = null) {
'call' => $data['inCall'],
];
}
}

$inactiveUsers = array_filter($participants['users'], function($data) {
return $data['lastPing'] <= time() - 30 &&
$data['sessionId'] !== 0 && $data['sessionId'] !== '' && $data['sessionId'] !== '0';
});

foreach ($inactiveUsers as $inactiveUserId => $data) {
$room->leaveRoom($inactiveUserId);
if ($data['sessionId'] !== '0' && $data['lastPing'] <= time() - 100) {
$room->leaveRoom($userId);
}
}

$activeGuests = array_filter($participants['guests'], function($data) {
return $data['lastPing'] > time() - 30;
return $data['lastPing'] > time() - 100;
});

$numActiveGuests = count($activeGuests);
Expand Down
2 changes: 1 addition & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public function cleanGuestParticipants() {
$query->delete('talk_participants')
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->emptyString('user_id'))
->andWhere($query->expr()->lte('last_ping', $query->createNamedParameter(time() - 30, IQueryBuilder::PARAM_INT)));
->andWhere($query->expr()->lte('last_ping', $query->createNamedParameter(time() - 100, IQueryBuilder::PARAM_INT)));
$query->execute();

$this->dispatcher->dispatch(self::class . '::postCleanGuests', new GenericEvent($this));
Expand Down

0 comments on commit 1983bc5

Please sign in to comment.