Page MenuHomePhorge

Connection.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

Connection.php

<?php
namespace App\OpenVidu;
use Illuminate\Database\Eloquent\Model;
/**
* The eloquent definition of a Connection.
*
* @property string $id OpenVidu connection identifier
* @property array $metadata Connection metadata
* @property int $role Connection role
* @property int $room_id Room identifier
* @property string $session_id OpenVidu session identifier
*/
class Connection extends Model
{
protected $table = 'openvidu_connections';
public $incrementing = false;
protected $keyType = 'string';
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'metadata' => 'array',
];
/**
* Dismiss (close) the connection.
*
* @return bool True on success, False on failure
*/
public function dismiss()
{
if ($this->room->closeOVConnection($this->id)) {
$this->delete();
return true;
}
return false;
}
/**
* The room to which this connection belongs.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function room()
{
return $this->belongsTo(Room::class, 'room_id', 'id');
}
/**
* Connection role mutator
*
* @throws \Exception
*/
public function setRoleAttribute($role)
{
$new_role = 0;
$allowed_values = [
Room::ROLE_SUBSCRIBER,
Room::ROLE_PUBLISHER,
Room::ROLE_MODERATOR,
Room::ROLE_SCREEN,
Room::ROLE_OWNER,
];
foreach ($allowed_values as $value) {
if ($role & $value) {
$new_role |= $value;
$role ^= $value;
}
}
if ($role > 0) {
throw new \Exception("Invalid connection role: {$role}");
}
// It is either screen sharing connection or publisher/subscriber connection
if ($new_role & Room::ROLE_SCREEN) {
if ($new_role & Room::ROLE_PUBLISHER) {
$new_role ^= Room::ROLE_PUBLISHER;
}
if ($new_role & Room::ROLE_SUBSCRIBER) {
$new_role ^= Room::ROLE_SUBSCRIBER;
}
}
$this->attributes['role'] = $new_role;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Apr 5, 11:09 PM (1 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
15/6b/bb62e746b26901974c6185a8ca6e
Default Alt Text
Connection.php (2 KB)

Event Timeline