Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/OpenViduController.php
Show First 20 Lines • Show All 423 Lines • ▼ Show 20 Lines | public function updateConnection($id, $conn) | ||||
// Store current time, so we know the order in the queue | // Store current time, so we know the order in the queue | ||||
$connection->metadata = ['hand' => time()] + $connection->metadata; | $connection->metadata = ['hand' => time()] + $connection->metadata; | ||||
} else { | } else { | ||||
$connection->metadata = array_diff_key($connection->metadata, ['hand' => 0]); | $connection->metadata = array_diff_key($connection->metadata, ['hand' => 0]); | ||||
} | } | ||||
break; | break; | ||||
case 'language': | |||||
// Only the moderator can do it | |||||
if (!$this->isModerator($connection->room)) { | |||||
return $this->errorResponse(403); | |||||
} | |||||
if ($value) { | |||||
if (preg_match('/^[a-z]{2}$/', $value)) { | |||||
$connection->metadata = ['language' => $value] + $connection->metadata; | |||||
} | |||||
} else { | |||||
$connection->metadata = array_diff_key($connection->metadata, ['language' => 0]); | |||||
} | |||||
break; | |||||
case 'role': | case 'role': | ||||
// Only the moderator can do it | // Only the moderator can do it | ||||
if (!$this->isModerator($connection->room)) { | if (!$this->isModerator($connection->room)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
// The 'owner' role is not assignable | // The 'owner' role is not assignable | ||||
if ($value & Room::ROLE_OWNER && !($connection->role & Room::ROLE_OWNER)) { | if ($value & Room::ROLE_OWNER && !($connection->role & Room::ROLE_OWNER)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} elseif (!($value & Room::ROLE_OWNER) && ($connection->role & Room::ROLE_OWNER)) { | } elseif (!($value & Room::ROLE_OWNER) && ($connection->role & Room::ROLE_OWNER)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
// The room owner has always a 'moderator' role | // The room owner has always a 'moderator' role | ||||
if (!($value & Room::ROLE_MODERATOR) && $connection->role & Room::ROLE_OWNER) { | if (!($value & Room::ROLE_MODERATOR) && $connection->role & Room::ROLE_OWNER) { | ||||
$value |= Room::ROLE_MODERATOR; | $value |= Room::ROLE_MODERATOR; | ||||
} | } | ||||
// Promotion to publisher? Put the user hand down | // Promotion to publisher? Put the user hand down | ||||
if ($value & Room::ROLE_PUBLISHER && !($connection->role & Room::ROLE_PUBLISHER)) { | if ($value & Room::ROLE_PUBLISHER && !($connection->role & Room::ROLE_PUBLISHER)) { | ||||
$connection->metadata = array_diff_key($connection->metadata, ['hand' => 0]); | $connection->metadata = array_diff_key($connection->metadata, ['hand' => 0]); | ||||
} | } | ||||
// Non-publisher cannot be a language interpreter | |||||
if (!($value & Room::ROLE_PUBLISHER)) { | |||||
$connection->metadata = array_diff_key($connection->metadata, ['language' => 0]); | |||||
} | |||||
$connection->{$key} = $value; | $connection->{$key} = $value; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// The connection observer will send a signal to everyone when needed | // The connection observer will send a signal to everyone when needed | ||||
$connection->save(); | $connection->save(); | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |