1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calluser.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\Call;
4
5use Bitrix\Im\Model\CallUserTable;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\Type\DateTime;
8
10{
12 const STATE_UNAVAILABLE = 'unavailable';
13 const STATE_IDLE = 'idle';
14 const STATE_CALLING = 'calling';
15 const STATE_DECLINED = 'declined';
16 const STATE_BUSY = 'busy';
17 const STATE_READY = 'ready';
18
19 protected $userId;
20 protected $callId;
21 protected $state;
22 protected $lastSeen;
23 protected $firstJoined;
24 protected $isMobile;
25 protected $sharedScreen;
26 protected $recorded;
27
28 public static function create(array $fields): static
29 {
30 if(!isset($fields['USER_ID']) || !$fields['USER_ID'])
31 {
32 throw new ArgumentException('USER_ID should be positive integer');
33 }
34 $instance = new static();
35 $instance->setFields($fields);
36 return $instance;
37 }
38
42 public function getState()
43 {
44 // previous version with 'lastSeen' field check
45 // ($this->isSeenRecently() ? $this->state : static::STATE_IDLE)
46 // will return wrong state for new scheme
47 // because this field will not be updated during a call
48 // because 'ping' requests from client side were removed
49 return $this->state;
50 }
51
52 public function isSeenRecently()
53 {
54 if(!($this->lastSeen instanceof DateTime))
55 {
56 return false;
57 }
58 $now = time();
59 $delta = $now - $this->lastSeen->getTimestamp();
60 return $delta <= static::LAST_SEEN_THRESHOLD;
61 }
62
63 public function updateState($state)
64 {
65 $fields = ['STATE' => $state];
66 if ($state === self::STATE_CALLING)
67 {
68 $fields['LAST_SEEN'] = new DateTime();
69 }
70 $this->update($fields);
71 }
72
76 public function getLastSeen()
77 {
78 return $this->lastSeen;
79 }
80
87 {
88 $this->update(['LAST_SEEN' => $lastSeen]);
89 }
90
91 public function getFirstJoined() : ?DateTime
92 {
93 return $this->firstJoined;
94 }
95
99 public function wasScreenShared()
100 {
101 return $this->sharedScreen;
102 }
103
107 public function wasRecorded()
108 {
109 return $this->recorded;
110 }
111
112
118 public function isActive()
119 {
120 $seenRecently = false;
121
122 if($this->lastSeen instanceof DateTime)
123 {
124 $now = time();
125 $delta = $now - $this->lastSeen->getTimestamp();
126 $seenRecently = $delta <= static::LAST_SEEN_THRESHOLD;
127 }
128
129 return in_array($this->state, [static::STATE_READY, static::STATE_CALLING]) && $seenRecently;
130 }
131
132 public function isUaMobile()
133 {
134 return $this->isMobile;
135 }
136
137 public function setFields(array $fields)
138 {
139 $this->userId = array_key_exists('USER_ID', $fields) ? $fields['USER_ID'] : $this->userId;
140 $this->callId = array_key_exists('CALL_ID', $fields) ? $fields['CALL_ID'] : $this->callId;
141 $this->state = array_key_exists('STATE', $fields) ? $fields['STATE'] : $this->state;
142 $this->lastSeen = array_key_exists('LAST_SEEN', $fields) ? $fields['LAST_SEEN'] : $this->lastSeen;
143 $this->firstJoined = array_key_exists('FIRST_JOINED', $fields) ? $fields['FIRST_JOINED'] : $this->firstJoined;
144 $this->isMobile = array_key_exists('IS_MOBILE', $fields) ? $fields['IS_MOBILE'] === 'Y' : $this->isMobile;
145 $this->sharedScreen = array_key_exists('SHARED_SCREEN', $fields) ? $fields['SHARED_SCREEN'] === 'Y' : $this->sharedScreen;
146 $this->recorded = array_key_exists('RECORDED', $fields) ? $fields['RECORDED'] === 'Y' : $this->recorded;
147 }
148
149 public function save()
150 {
151 CallUserTable::merge($this->toArray());
152 }
153
154 public function toArray()
155 {
156 return [
157 'USER_ID' => $this->userId,
158 'CALL_ID' => $this->callId,
159 'STATE' => $this->state,
160 'LAST_SEEN' => $this->lastSeen,
161 'FIRST_JOINED' => $this->firstJoined,
162 'IS_MOBILE' => is_bool($this->isMobile) ? $this->isMobile : null,
163 'SHARED_SCREEN' => is_bool($this->sharedScreen) ? $this->sharedScreen : null,
164 'RECORDED' => is_bool($this->recorded) ? $this->recorded : null
165 ];
166 }
167
168 public function update(array $fields)
169 {
170 $updateResult = CallUserTable::update(['CALL_ID' => $this->callId, 'USER_ID' => $this->userId], $fields);
171
172 if($updateResult->isSuccess())
173 {
174 $updateData = $updateResult->getData();
175 $this->setFields($updateData);
176 }
177 $this->setFields($fields);
178 }
179
180 public static function delete($callId, $userId)
181 {
182 CallUserTable::delete([
183 'CALL_ID' => $callId,
184 'USER_ID' => $userId
185 ]);
186 }
187}
updateLastSeen(DateTime $lastSeen)
Определения calluser.php:86
const STATE_BUSY
Определения calluser.php:16
updateState($state)
Определения calluser.php:63
$sharedScreen
Определения calluser.php:25
toArray()
Определения calluser.php:154
$firstJoined
Определения calluser.php:23
$isMobile
Определения calluser.php:24
$recorded
Определения calluser.php:26
$lastSeen
Определения calluser.php:22
wasRecorded()
Определения calluser.php:107
const STATE_DECLINED
Определения calluser.php:15
wasScreenShared()
Определения calluser.php:99
isActive()
Определения calluser.php:118
getFirstJoined()
Определения calluser.php:91
const STATE_IDLE
Определения calluser.php:13
const STATE_CALLING
Определения calluser.php:14
const STATE_UNAVAILABLE
Определения calluser.php:12
const STATE_READY
Определения calluser.php:17
static create(array $fields)
Определения calluser.php:28
isUaMobile()
Определения calluser.php:132
getLastSeen()
Определения calluser.php:76
update(array $fields)
Определения calluser.php:168
setFields(array $fields)
Определения calluser.php:137
const LAST_SEEN_THRESHOLD
Определения calluser.php:11
isSeenRecently()
Определения calluser.php:52
getState()
Определения calluser.php:42
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$delta
Определения prolog_main_admin.php:363
$instance
Определения ps_b24_final.php:14
$fields
Определения yandex_run.php:501