You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

69 lines
2.0 KiB

<?php
namespace App;
use Awobaz\Compoships\Database\Eloquent\Model;
class MujiCall extends Model
{
use \Awobaz\Compoships\Compoships;
public $incrementing = false;
protected $primaryKey = ['session_id', 'id'];
protected $fillable = ['session_id', 'id', 'muc', 'jidfrom', 'video', 'isfromconference'];
protected $with = ['participants', 'presences'];
public function session()
{
return $this->hasOne(Session::class);
}
public function conference()
{
return $this->hasOne(Conference::class, ['conference', 'session_id'], ['jidfrom', 'session_id']);
}
public function presences()
{
return $this->hasMany(Presence::class, ['jid', 'session_id'], ['muc', 'session_id'])
->where('value', '<', '5')
->where('resource', '!=', '');
}
public function participants()
{
return $this->hasMany(MujiCallParticipant::class, ['muji_call_id', 'session_id'], ['id', 'session_id']);
}
public function inviter()
{
return $this->hasOne(MujiCallParticipant::class, ['muji_call_id', 'session_id'], ['id', 'session_id'])
->where('inviter', true);
}
public function getJoinedAttribute(): bool
{
/**
* If we can resolve the linker we directly call it,
* If we are not in the session process we request the internal API to reach it (and do the same thing)
*/
return linker($this->session_id)
? linker($this->session_id)->currentCall->isJidInCall($this->jidfrom)
&& linker($this->session_id)->currentCall->mujiRoom == $this->muc
: (bool)requestAPI('mujiincall', post: [
'sessionid' => $this->session_id,
'jid' => $this->jidfrom,
'mujiroom' => $this->muc
]);
}
public function getIconAttribute()
{
return $this->video ? 'videocam' : 'call';
}
public function getendIconAttribute()
{
return $this->video ? 'videocam_off' : 'call_end';
}
}