Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/OpenVidu/ConnectionObserver.php
Show All 20 Lines | public function updated(Connection $connection) | ||||
if ($connection->role != $connection->getOriginal('role')) { | if ($connection->role != $connection->getOriginal('role')) { | ||||
$params['role'] = $connection->role; | $params['role'] = $connection->role; | ||||
// TODO: When demoting publisher to subscriber maybe we should | // TODO: When demoting publisher to subscriber maybe we should | ||||
// destroy all streams using REST API. For now we trust the | // destroy all streams using REST API. For now we trust the | ||||
// participant browser to do this. | // participant browser to do this. | ||||
} | } | ||||
// Rised hand state change | // Detect metadata changes for specified properties | ||||
$newState = $connection->metadata['hand'] ?? null; | $keys = [ | ||||
$oldState = $this->getOriginal($connection, 'metadata')['hand'] ?? null; | 'hand' => 'bool', | ||||
'language' => '', | |||||
]; | |||||
foreach ($keys as $key => $type) { | |||||
$newState = $connection->metadata[$key] ?? null; | |||||
$oldState = $this->getOriginal($connection, 'metadata')[$key] ?? null; | |||||
if ($newState !== $oldState) { | if ($newState !== $oldState) { | ||||
$params['hand'] = !empty($newState); | $params[$key] = $type == 'bool' ? !empty($newState) : $newState; | ||||
} | |||||
} | } | ||||
// Send the signal to all participants | // Send the signal to all participants | ||||
if (!empty($params)) { | if (!empty($params)) { | ||||
$params['connectionId'] = $connection->id; | $params['connectionId'] = $connection->id; | ||||
$connection->room->signal('connectionUpdate', $params); | $connection->room->signal('connectionUpdate', $params); | ||||
} | } | ||||
} | } | ||||
Show All 22 Lines |