19 public function sendInviteToUser(
int $senderId,
int $toUserId, $invitedUsers, $isLegacyMobile,
bool $video =
false,
bool $sendPush =
true)
21 $users = $this->call->getUsers();
23 $parentCall = $this->call->getParentId() ?
Call::loadWithId($this->call->getParentId()) :
null;
24 $skipPush = $parentCall ? $parentCall->getUsers() : [];
25 $skipPush = array_flip($skipPush);
27 $associatedEntity = $this->call->getAssociatedEntity();
28 $isBroadcast = ($associatedEntity instanceof
Chat) && $associatedEntity->isBroadcast();
31 'call' => $this->call->toArray(($senderId == $toUserId ? $toUserId : 0)),
33 'invitedUsers' => $invitedUsers,
35 'senderId' => $senderId,
37 'isLegacyMobile' => $isLegacyMobile,
39 'logToken' => $this->call->getLogToken($toUserId),
41 $connectionData = $this->call->getConnectionData($toUserId);
42 if ($connectionData !==
null)
44 $config[
'connectionData'] = $connectionData;
47 if (!isset($skipPush[$toUserId]) && $sendPush && !$isBroadcast)
49 $push = $this->
getInvitePush($senderId, $toUserId, $isLegacyMobile, $video);
52 $this->
send(
'Call::incoming', $toUserId, $config, $push);
55 public function sendInvite(
int $senderId, array $toUserIds, $isLegacyMobile,
bool $video =
false,
bool $sendPush =
true)
57 $users = $this->call->getUsers();
59 $parentCall = $this->call->getParentId() ?
Call::loadWithId($this->call->getParentId()) :
null;
60 $skipPush = $parentCall ? $parentCall->getUsers() : [];
61 $skipPush = array_flip($skipPush);
63 $associatedEntity = $this->call->getAssociatedEntity();
64 $isBroadcast = ($associatedEntity instanceof
Chat) && $associatedEntity->isBroadcast();
66 foreach ($toUserIds as $toUserId)
69 'call' => $this->call->toArray((count($toUserIds) == 1 ? $toUserId : 0)),
71 'invitedUsers' => $toUserIds,
73 'senderId' => $senderId,
75 'isLegacyMobile' => $isLegacyMobile,
77 'logToken' => $this->call->getLogToken($toUserId),
79 if (!isset($skipPush[$toUserId]) && $sendPush && !$isBroadcast)
81 $push = $this->
getInvitePush($senderId, $toUserId, $isLegacyMobile, $video);
84 $this->
send(
'Call::incoming', $toUserId, $config, $push);
88 protected function getInvitePush(
int $senderId,
int $toUserId, $isLegacyMobile, $video)
90 $users = $this->call->getUsers();
91 $associatedEntity = $this->call->getAssociatedEntity();
92 $name = $associatedEntity ? $associatedEntity->getName($toUserId) :
Loc::getMessage(
'IM_CALL_INVITE_NA');
96 if ($associatedEntity instanceof
Chat)
98 if ($associatedEntity->isPrivateChat())
100 $userInstance = \Bitrix\Im\User::getInstance($senderId);
101 $email = $userInstance->getEmail();
102 $phone = $userInstance->getPhone();
103 $phone = preg_replace(
"/[^0-9#*+,;]/",
"", $phone);
105 $avatar = $associatedEntity->getAvatar($toUserId);
108 $pushText =
Loc::getMessage(
'IM_CALL_INVITE', [
'#USER_NAME#' => $name]);
109 $pushTag =
'IM_CALL_'.$this->call->getId();
111 'message' => $pushText,
114 'ACTION' =>
'IMINV_'.$this->call->getId().
"_".time().
"_".($video ?
'Y' :
'N'),
116 'type' =>
'internal',
117 'callerName' => htmlspecialcharsback($name),
118 'callerAvatar' => $avatar ??
'',
119 'call' => $this->call->toArray($toUserId),
122 'isLegacyMobile' => $isLegacyMobile,
123 'senderId' => $senderId,
124 'senderEmail' => $email,
125 'senderPhone' => $phone,
126 'logToken' => $this->call->getLogToken($toUserId),
130 'advanced_params' => [
132 'notificationsToCancel' => [$pushTag],
133 'androidHighPriority' =>
true,
134 'useVibration' =>
true,
138 'sound' =>
'call.aif',
139 'send_immediately' =>
'Y'
148 'call' => $this->call->toArray(),
149 'users' => $joinedUsers,
151 'senderId' => $senderId,
152 'publicIds' => $this->getPublicIds($joinedUsers),
155 return $this->
send(
'Call::usersJoined', $this->call->getUsers(), $config);
162 'call' => $this->call->toArray(),
165 'senderId' => $senderId,
166 'publicIds' => $this->getPublicIds($users),
169 return $this->
send(
'Call::usersInvited', $toUserIds, $config);
175 'call' => $this->call->toArray(),
176 'senderId' => $senderId,
179 $toUserIds = $this->call->getUsers();
181 return $this->
send(
'Call::associatedEntityReplaced', $toUserIds, $config);
184 public function sendAnswer(
int $senderId, $callInstanceId, $isLegacyMobile)
187 'call' => $this->call->toArray(),
188 'senderId' => $senderId,
189 'callInstanceId' => $callInstanceId,
190 'isLegacyMobile' => $isLegacyMobile,
193 $toUserIds = array_diff($this->call->getUsers(), [$senderId]);
194 $this->
send(
'Call::answer', $toUserIds, $config,
null, 3600);
197 'send_immediately' =>
'Y',
200 'advanced_params' => [
201 'id' =>
'IM_CALL_'.$this->call->getId().
'_ANSWER',
202 'notificationsToCancel' => [
'IM_CALL_'.$this->call->getId()],
205 'filterCallback' => [static::class,
'filterPushesForApple'],
209 $this->
send(
'Call::answer', $senderId, $config, $push, 3600);
212 public function sendPing(
int $senderId, $requestId)
215 'requestId' => $requestId,
216 'callId' => $this->call->getId(),
217 'senderId' => $senderId
220 $toUserIds = $this->call->getUsers();
221 $toUserIds = array_filter($toUserIds,
function ($value) use ($senderId) {
222 return $value != $senderId;
224 return $this->
send(
'Call::ping', $toUserIds, $config,
null, 0);
229 return $this->
send(
'Call::negotiationNeeded', $toUserId, array(
230 'senderId' => $senderId,
231 'restart' => $restart
235 public function sendConnectionOffer(
int $senderId,
int $toUserId,
string $connectionId,
string $offerSdp,
string $userAgent)
237 return $this->
send(
'Call::connectionOffer', $toUserId, array(
238 'senderId' => $senderId,
239 'connectionId' => $connectionId,
241 'userAgent' => $userAgent
245 public function sendConnectionAnswer(
int $senderId,
int $toUserId,
string $connectionId,
string $answerSdp,
string $userAgent)
247 return $this->
send(
'Call::connectionAnswer', $toUserId, array(
248 'senderId' => $senderId,
249 'connectionId' => $connectionId,
251 'userAgent' => $userAgent
255 public function sendIceCandidates(
int $senderId,
int $toUserId,
string $connectionId, array $iceCandidates)
257 return $this->
send(
'Call::iceCandidate', $toUserId, array(
258 'senderId' => $senderId,
259 'connectionId' => $connectionId,
260 'candidates' => $iceCandidates
264 public function sendHangup(
int $senderId, array $toUserIds, ?
string $callInstanceId, $code = 200)
267 'senderId' => $senderId,
268 'callInstanceId' => $callInstanceId,
273 'send_immediately' =>
'Y',
276 'advanced_params' => [
277 'id' =>
'IM_CALL_'.$this->call->getId().
'_FINISH',
278 'notificationsToCancel' => [
'IM_CALL_'.$this->call->getId()],
280 'filterCallback' => [static::class,
'filterPushesForApple'],
284 return $this->
send(
'Call::hangup', $toUserIds, $config, $push, 3600);
290 'send_immediately' =>
'Y',
293 'advanced_params' => [
294 'id' =>
'IM_CALL_'.$this->call->getId().
'_FINISH',
295 'notificationsToCancel' => [
'IM_CALL_'.$this->call->getId()],
297 'filterCallback' => [static::class,
'filterPushesForApple'],
301 return $this->
send(
'Call::finish', $this->call->getUsers(), [], $push, 3600);
306 if (!Loader::includeModule(
'pull'))
313 \CPushDescription::TYPE_APPLE,
314 \CPushDescription::TYPE_APPLE_VOIP,
323 if (!Loader::includeModule(
'pull'))
328 return \Bitrix\Pull\Channel::getPublicIds([
334 protected function send(
string $command, $users, array $params = [], $push =
null, $ttl = 5)
336 if (!Loader::includeModule(
'pull'))
339 if (!isset($params[
'call']))
340 $params[
'call'] = [
'ID' => $this->call->getId()];
342 if (!isset($params[
'callId']))
343 $params[
'callId'] = $this->call->getId();
345 \Bitrix\Pull\Event::add($users, array(
347 'command' => $command,
sendHangup(int $senderId, array $toUserIds, ?string $callInstanceId, $code=200)
getPublicIds(array $userIds)
getInvitePush(int $senderId, int $toUserId, $isLegacyMobile, $video)
static filterPushesForApple($message, $deviceType, $deviceToken)
sendUsersInvited(int $senderId, array $toUserIds, array $users)
sendAnswer(int $senderId, $callInstanceId, $isLegacyMobile)
sendConnectionOffer(int $senderId, int $toUserId, string $connectionId, string $offerSdp, string $userAgent)
sendAssociatedEntityReplaced(int $senderId)
send(string $command, $users, array $params=[], $push=null, $ttl=5)
sendInviteToUser(int $senderId, int $toUserId, $invitedUsers, $isLegacyMobile, bool $video=false, bool $sendPush=true)
sendPing(int $senderId, $requestId)
sendUsersJoined(int $senderId, array $joinedUsers)
sendInvite(int $senderId, array $toUserIds, $isLegacyMobile, bool $video=false, bool $sendPush=true)
sendConnectionAnswer(int $senderId, int $toUserId, string $connectionId, string $answerSdp, string $userAgent)
sendIceCandidates(int $senderId, int $toUserId, string $connectionId, array $iceCandidates)
sendNegotiationNeeded(int $senderId, int $toUserId, $restart)
static getUsers(array $idList)
static getMessage($code, $replace=null, $language=null)