1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
signaling.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\Call;
4
5use Bitrix\Im\Call\Integration\Chat;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\Loader;
8use Bitrix\Main\Localization\Loc;
9
11{
12 protected $call;
13
14 public function __construct(Call $call)
15 {
16 $this->call = $call;
17 }
18
19 public function sendInviteToUser(int $senderId, int $toUserId, $invitedUsers, $isLegacyMobile, bool $video = false, bool $sendPush = true)
20 {
21 $users = $this->call->getUsers();
22
23 $parentCall = $this->call->getParentId() ? Call::loadWithId($this->call->getParentId()) : null;
24 $skipPush = $parentCall ? $parentCall->getUsers() : [];
25 $skipPush = array_flip($skipPush);
26
27 $associatedEntity = $this->call->getAssociatedEntity();
28 $isBroadcast = ($associatedEntity instanceof Chat) && $associatedEntity->isBroadcast();
29
30 $config = [
31 'call' => $this->call->toArray(($senderId == $toUserId ? $toUserId : 0)),
32 'users' => $users,
33 'invitedUsers' => $invitedUsers,
34 'userData' => $this->call->getUserData(),
35 'senderId' => $senderId,
36 'publicIds' => $this->getPublicIds([$toUserId]),
37 'isLegacyMobile' => $isLegacyMobile,
38 'video' => $video,
39 'logToken' => $this->call->getLogToken($toUserId),
40 ];
41 $connectionData = $this->call->getConnectionData($toUserId);
42 if ($connectionData !== null)
43 {
44 $config['connectionData'] = $connectionData;
45 }
46
47 $push = null;
48 if (!isset($skipPush[$toUserId]) && $sendPush && !$isBroadcast)
49 {
50 $push = $this->getInvitePush($senderId, $toUserId, $isLegacyMobile, $video);
51 }
52
53 $this->send('Call::incoming', $toUserId, $config, $push);
54 }
55
56 public function sendInvite(int $senderId, array $toUserIds, $isLegacyMobile, bool $video = false, bool $sendPush = true)
57 {
58 $users = $this->call->getUsers();
59
60 $parentCall = $this->call->getParentId() ? Call::loadWithId($this->call->getParentId()) : null;
61 $skipPush = $parentCall ? $parentCall->getUsers() : [];
62 $skipPush = array_flip($skipPush);
63
64 $associatedEntity = $this->call->getAssociatedEntity();
65 $isBroadcast = ($associatedEntity instanceof Chat) && $associatedEntity->isBroadcast();
66
67 foreach ($toUserIds as $toUserId)
68 {
69 $push = null;
70 $config = [
71 'call' => $this->call->toArray((count($toUserIds) == 1 ? $toUserId : 0)),
72 'users' => $users,
73 'invitedUsers' => $toUserIds,
74 'userData' => $this->call->getUserData(),
75 'senderId' => $senderId,
76 'publicIds' => $this->getPublicIds($users),
77 'isLegacyMobile' => $isLegacyMobile,
78 'video' => $video,
79 'logToken' => $this->call->getLogToken($toUserId),
80 ];
81 $connectionData = $this->call->getConnectionData($toUserId);
82 if ($connectionData !== null)
83 {
84 $config['connectionData'] = $connectionData;
85 }
86 if (!isset($skipPush[$toUserId]) && $sendPush && !$isBroadcast)
87 {
88 $push = $this->getInvitePush($senderId, $toUserId, $isLegacyMobile, $video);
89 }
90
91 $this->send('Call::incoming', $toUserId, $config, $push);
92 }
93 }
94
95 protected function getInvitePush(int $senderId, int $toUserId, $isLegacyMobile, $video): array
96 {
97 $users = $this->call->getUsers();
98 $associatedEntity = $this->call->getAssociatedEntity();
99 $name = $associatedEntity ? $associatedEntity->getName($toUserId) : Loc::getMessage('IM_CALL_INVITE_NA');
100
101 $email = null;
102 $phone = null;
103 if ($associatedEntity instanceof Chat)
104 {
105 if ($associatedEntity->isPrivateChat())
106 {
107 $userInstance = \Bitrix\Im\User::getInstance($senderId);
108 $email = $userInstance->getEmail();
109 $phone = $userInstance->getPhone();
110 $phone = preg_replace("/[^0-9#*+,;]/", "", $phone);
111 }
112 $avatar = $associatedEntity->getAvatar($toUserId);
113 }
114
115 $pushText = Loc::getMessage('IM_CALL_INVITE', ['#USER_NAME#' => $name]);
116 $pushTag = 'IM_CALL_'.$this->call->getId();
117 $push = [
118 'message' => $pushText,
119 'expiry' => 0,
120 'params' => [
121 'ACTION' => 'IMINV_'.$this->call->getId()."_".time()."_".($video ? 'Y' : 'N'),
122 'PARAMS' => [
123 'type' => 'internal',
124 'callerName' => htmlspecialcharsback($name),
125 'callerAvatar' => $avatar ?? '',
126 'call' => $this->call->toArray($toUserId),
127 'video' => $video,
128 'users' => $users,
129 'isLegacyMobile' => $isLegacyMobile,
130 'senderId' => $senderId,
131 'senderEmail' => $email,
132 'senderPhone' => $phone,
133 'logToken' => $this->call->getLogToken($toUserId),
134 'ts' => time(),
135 ]
136 ],
137 'advanced_params' => [
138 'id' => $pushTag,
139 'notificationsToCancel' => [$pushTag],
140 'androidHighPriority' => true,
141 'useVibration' => true,
142 'isVoip' => true,
143 'callkit' => true,
144 ],
145 'sound' => 'call.aif',
146 'send_immediately' => 'Y',
147 ];
148
149 $connectionData = $this->call->getConnectionData($toUserId);
150 if ($connectionData !== null)
151 {
152 $push['params']['PARAMS']['connectionData'] = $connectionData;
153 }
154
155 return $push;
156 }
157
163 public function sendUsersJoined(int $senderId, array $joinedUsers)
164 {
165 $config = [
166 'call' => $this->call->toArray(),
167 'users' => $joinedUsers,
168 'userData' => $this->call->prepareUserData($joinedUsers),
169 'senderId' => $senderId,
170 'publicIds' => $this->getPublicIds($joinedUsers),
171 ];
172
173 return $this->send('Call::usersJoined', $this->call->getUsers(), $config);
174 }
175
176 public function sendUsersInvited(int $senderId, array $toUserIds, array $users, bool $show)
177 {
178 $config = [
179 'call' => $this->call->toArray(),
180 'users' => $users,
181 'userData' => $this->call->prepareUserData($users),
182 'senderId' => $senderId,
183 'publicIds' => $this->getPublicIds($users),
184 'show' => $show,
185 ];
186
187 return $this->send('Call::usersInvited', $toUserIds, $config);
188 }
189
190 public function sendAssociatedEntityReplaced(int $senderId)
191 {
192 $config = [
193 'call' => $this->call->toArray(),
194 'senderId' => $senderId,
195 ];
196
197 $toUserIds = $this->call->getUsers();
198
199 return $this->send('Call::associatedEntityReplaced', $toUserIds, $config);
200 }
201
202 public function sendAnswer(int $senderId, $callInstanceId, $isLegacyMobile)
203 {
204 $config = [
205 'call' => $this->call->toArray(),
206 'senderId' => $senderId,
207 'callInstanceId' => $callInstanceId,
208 'isLegacyMobile' => $isLegacyMobile,
209 ];
210
211 $toUserIds = array_diff($this->call->getUsers(), [$senderId]);
212 $this->send('Call::answer', $toUserIds, $config, null, 3600);
213
214 $push = [
215 'send_immediately' => 'Y',
216 'expiry' => 0,
217 'params' => [],
218 'advanced_params' => [
219 'id' => 'IM_CALL_'.$this->call->getId().'_ANSWER',
220 'notificationsToCancel' => ['IM_CALL_'.$this->call->getId()],
221 'isVoip' => true,
222 'callkit' => true,
223 'filterCallback' => [static::class, 'filterPushesForApple'],
224 ]
225 ];
226
227 $this->send('Call::answer', $senderId, $config, $push, 3600);
228 }
229
230 public function sendPing(int $senderId, $requestId)
231 {
232 $config = [
233 'requestId' => $requestId,
234 'callId' => $this->call->getId(),
235 'senderId' => $senderId
236 ];
237
238 $toUserIds = $this->call->getUsers();
239 $toUserIds = array_filter($toUserIds, function ($value) use ($senderId) {
240 return $value != $senderId;
241 });
242 return $this->send('Call::ping', $toUserIds, $config, null, 0);
243 }
244
245 public function sendNegotiationNeeded(int $senderId, int $toUserId, $restart)
246 {
247 return $this->send('Call::negotiationNeeded', $toUserId, [
248 'senderId' => $senderId,
249 'restart' => $restart
250 ]);
251 }
252
253 public function sendConnectionOffer(int $senderId, int $toUserId, string $connectionId, string $offerSdp, string $userAgent)
254 {
255 return $this->send('Call::connectionOffer', $toUserId, [
256 'senderId' => $senderId,
257 'connectionId' => $connectionId,
258 'sdp' => $offerSdp,
259 'userAgent' => $userAgent
260 ]);
261 }
262
263 public function sendConnectionAnswer(int $senderId, int $toUserId, string $connectionId, string $answerSdp, string $userAgent)
264 {
265 return $this->send('Call::connectionAnswer', $toUserId, [
266 'senderId' => $senderId,
267 'connectionId' => $connectionId,
268 'sdp' => $answerSdp,
269 'userAgent' => $userAgent
270 ]);
271 }
272
273 public function sendIceCandidates(int $senderId, int $toUserId, string $connectionId, array $iceCandidates)
274 {
275 return $this->send('Call::iceCandidate', $toUserId, [
276 'senderId' => $senderId,
277 'connectionId' => $connectionId,
278 'candidates' => $iceCandidates
279 ]);
280 }
281
282 public function sendHangup(int $senderId, array $toUserIds, ?string $callInstanceId, $code = 200)
283 {
284 $config = [
285 'senderId' => $senderId,
286 'callInstanceId' => $callInstanceId,
287 'code' => $code,
288 ];
289
290 $push = [
291 'send_immediately' => 'Y',
292 //'expiry' => 0,
293 'params' => [],
294 'advanced_params' => [
295 'id' => 'IM_CALL_'.$this->call->getId().'_FINISH',
296 'notificationsToCancel' => ['IM_CALL_'.$this->call->getId()],
297 'callkit' => true,
298 'filterCallback' => [static::class, 'filterPushesForApple'],
299 ]
300 ];
301
302 return $this->send('Call::hangup', $toUserIds, $config, $push, 3600);
303 }
304
305 public function sendFinish()
306 {
307 $push = [
308 'send_immediately' => 'Y',
309 //'expiry' => 0,
310 'params' => [],
311 'advanced_params' => [
312 'id' => 'IM_CALL_'.$this->call->getId().'_FINISH',
313 'notificationsToCancel' => ['IM_CALL_'.$this->call->getId()],
314 'callkit' => true,
315 'filterCallback' => [static::class, 'filterPushesForApple'],
316 ]
317 ];
318
319 return $this->send('Call::finish', $this->call->getUsers(), [], $push, 3600);
320 }
321
322 public function sendSwitchTrackRecordStatus(int $senderId, bool $isTrackRecordOn, string $errorCode = '')
323 {
324 $toUserIds = array_diff($this->call->getUsers(), [$senderId]);
325
326 return $this->send('Call::switchTrackRecordStatus', $toUserIds, [
327 'senderId' => $senderId,
328 'isTrackRecordOn' => $isTrackRecordOn,
329 'callUuid' => $this->call->getUuid(),
330 'errorCode' => $errorCode,
331 ]);
332 }
333
334 public static function filterPushesForApple($message, $deviceType, $deviceToken)
335 {
336 if (!Loader::includeModule('pull'))
337 {
338 return false;
339 }
340 $result = !in_array(
341 $deviceType,
342 [
345 ],
346 true)
347 ;
348 return $result;
349 }
350
351 protected function getPublicIds(array $userIds)
352 {
353 if (!Loader::includeModule('pull'))
354 {
355 return [];
356 }
357
358 return \Bitrix\Pull\Channel::getPublicIds([
359 'USERS' => $userIds,
360 'JSON' => true
361 ]);
362 }
363
364 protected function send(string $command, $users, array $params = [], $push = null, $ttl = 5)
365 {
366 if (!Loader::includeModule('pull'))
367 {
368 return false;
369 }
370
371 if (!isset($params['call']))
372 {
373 $params['call'] = [
374 'ID' => $this->call->getId(),
375 'UUID' => $this->call->getUuid(),
376 'PROVIDER' => $this->call->getProvider(),
377 'SCHEME' => $this->call->getScheme(),
378 ];
379 }
380
381 if (!isset($params['callId']))
382 {
383 $params['callId'] = $this->call->getId();
384 }
385
387 'module_id' => 'im',
388 'command' => $command,
389 'params' => $params,
390 'push' => $push,
391 'expiry' => $ttl
392 ]);
393
394 return true;
395 }
396}
Определения call.php:24
static loadWithId($id)
Определения call.php:1305
sendSwitchTrackRecordStatus(int $senderId, bool $isTrackRecordOn, string $errorCode='')
Определения signaling.php:322
sendHangup(int $senderId, array $toUserIds, ?string $callInstanceId, $code=200)
Определения signaling.php:282
sendFinish()
Определения signaling.php:305
getPublicIds(array $userIds)
Определения signaling.php:351
getInvitePush(int $senderId, int $toUserId, $isLegacyMobile, $video)
Определения signaling.php:95
static filterPushesForApple($message, $deviceType, $deviceToken)
Определения signaling.php:334
sendAnswer(int $senderId, $callInstanceId, $isLegacyMobile)
Определения signaling.php:202
sendConnectionOffer(int $senderId, int $toUserId, string $connectionId, string $offerSdp, string $userAgent)
Определения signaling.php:253
sendAssociatedEntityReplaced(int $senderId)
Определения signaling.php:190
send(string $command, $users, array $params=[], $push=null, $ttl=5)
Определения signaling.php:364
__construct(Call $call)
Определения signaling.php:14
sendInviteToUser(int $senderId, int $toUserId, $invitedUsers, $isLegacyMobile, bool $video=false, bool $sendPush=true)
Определения signaling.php:19
sendPing(int $senderId, $requestId)
Определения signaling.php:230
sendUsersJoined(int $senderId, array $joinedUsers)
Определения signaling.php:163
sendInvite(int $senderId, array $toUserIds, $isLegacyMobile, bool $video=false, bool $sendPush=true)
Определения signaling.php:56
sendUsersInvited(int $senderId, array $toUserIds, array $users, bool $show)
Определения signaling.php:176
sendConnectionAnswer(int $senderId, int $toUserId, string $connectionId, string $answerSdp, string $userAgent)
Определения signaling.php:263
sendIceCandidates(int $senderId, int $toUserId, string $connectionId, array $iceCandidates)
Определения signaling.php:273
sendNegotiationNeeded(int $senderId, int $toUserId, $restart)
Определения signaling.php:245
static getInstance($userId=null)
Определения user.php:45
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
const TYPE_APPLE_VOIP
Определения services_descriptions.php:9
const TYPE_APPLE
Определения services_descriptions.php:8
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
htmlspecialcharsback($str)
Определения tools.php:2693
$name
Определения menu_edit.php:35
$email
Определения payment.php:49
$message
Определения payment.php:8
$config
Определения quickway.php:69
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799