3namespace Bitrix\Im\Call;
5use Bitrix\Im\Call\Integration\EntityFactory;
6use Bitrix\Im\Call\Integration\EntityType;
8use Bitrix\Im\Model\AliasTable;
9use Bitrix\Im\Model\CallTable;
10use Bitrix\Im\Model\CallUserTable;
11use Bitrix\Im\V2\Call\CallFactory;
12use Bitrix\Main\ArgumentException;
13use Bitrix\Main\Config\Option;
14use Bitrix\Main\Loader;
15use Bitrix\Main\Type\DateTime;
17use Bitrix\Main\UserTable;
18use Bitrix\Main\Web\JWT;
20use Bitrix\Main\ErrorCollection;
21use Bitrix\Call\Signaling;
159 $this->errorCollection->add(
$errors);
169 return $this->errorCollection->toArray();
186 $this->errorCollection->add([
$error]);
197 return !$this->errorCollection->isEmpty();
209 $this->actionUserId = $byUserId;
220 return isset($this->users[
$userId]) ? $this->users[
$userId] :
null;
230 return array_keys($this->users);
249 if (!isset($this->userData))
292 $userRoles[
$userId] = match (
true)
294 $userId === $chatOwnerId =>
'ADMIN',
295 in_array(
$userId, $chatManagerIds,
true) =>
'MANAGER',
312 return isset($this->users[
$userId]);
324 if ($this->users[$newUserId])
326 return $this->users[$newUserId];
335 'CALL_ID' => $this->
id,
336 'USER_ID' => $newUserId,
340 $this->users[$newUserId]->save();
341 unset($this->userData);
343 if ($this->associatedEntity)
345 $this->associatedEntity->onUserAdd($newUserId);
348 return $this->users[$newUserId];
358 unset($this->userData[
$userId]);
373 foreach ($this->users as
$user)
375 $userState =
$user->getState();
376 $states[$userState] = isset($states[$userState]) ? $states[$userState] + 1 : 1;
378 if (in_array($this->type, [static::TYPE_PERMANENT, static::TYPE_LANGE]) || !$strict)
390 if (is_null($this->signaling))
420 $this->associatedEntity =
$entity;
425 $this->chatId =
$entity->getChatId();
526 if ($this->startDate)
528 $end = $this->endDate ??
new DateTime();
529 return $end->getTimestamp() - $this->startDate->getTimestamp();
543 Loader::includeModule(
'call');
552 if ($minUserCount > 0)
555 if ($userCount && $userCount >= $minUserCount)
568 if ($this->associatedEntity)
570 $userCount =
count($this->associatedEntity->getUsers());
572 if (!$userCount && $this->
id)
575 $userCount =
count($this->users);
639 public function inviteUsers(
int $senderId,
array $toUserIds, $isLegacyMobile, $video =
false, $sendPush =
true): void
656 string $sendMode = Signaling::MODE_ALL
659 foreach ($toUserIds as $toUserId)
677 if ($this->state ==
$state)
683 $updateResult = CallTable::updateState($this->
getId(),
$state);
689 if ($this->associatedEntity)
691 $this->associatedEntity->onStateChange(
$state, $prevState);
709 if ($this->endDate instanceof
DateTime)
719 foreach ($this->users as $callUser)
739 $event =
new Event(
'call',
'onCallStarted', [
'call' => $this]);
751 $event =
new Event(
'call',
'onCallFinished', [
'call' => $this]);
762 public function toArray($currentUserId = 0, $withSecrets =
false):
array
769 'IS_PUBLIC' => $this->isPublic ?
'Y' :
'N',
802 $insertResult = CallTable::add(
$fields);
803 $this->
id = $insertResult->getId();
807 CallTable::update($this->
id,
$fields);
813 $callFields = $this->
toArray();
814 $callFields[
'ID'] =
null;
816 $callFields[
'STATE'] = static::STATE_NEW;
817 $callFields[
'PROVIDER'] = $newProvider ?? $callFields[
'PROVIDER'];
820 $instance = CallFactory::createWithArray($callFields[
'PROVIDER'], $callFields);
841 string $newProvider =
null,
843 int $newInitiator =
null,
846 $callFields = $this->
toArray();
847 $callFields[
'ID'] =
null;
848 $callFields[
'UUID'] = $newUuid;
850 $callFields[
'STATE'] = static::STATE_NEW;
851 $callFields[
'PROVIDER'] = $newProvider ?? $callFields[
'PROVIDER'];
856 $callFields[
'SCHEME'] =
$scheme;
861 $callFields[
'INITIATOR_ID'] = $newInitiator;
872 $instance->associatedEntity->onCallCreate();
891 if (is_array($this->users))
898 $cursor = CallUserTable::getList(
array(
900 '=CALL_ID' => $this->
id
904 while($row = $cursor->fetch())
913 if ($this->startDate instanceof
DateTime && $this->endDate instanceof
DateTime)
915 $callLength = $this->endDate->getTimestamp() - $this->startDate->getTimestamp();
917 $userCountChat =
count($this->users);
922 $screenShared =
false;
924 $authTypes = UserTable::getList([
925 'select' => [
'ID',
'EXTERNAL_AUTH_ID'],
926 'filter' => [
'=ID' => $this->
getUsers()]
928 $authTypes = array_column($authTypes,
'EXTERNAL_AUTH_ID',
'ID');
931 if (
$user->getLastSeen() !=
null)
935 if (
$user->isUaMobile())
942 if (
$user->getFirstJoined())
944 $userLateness =
$user->getFirstJoined()->getTimestamp() - $this->startDate->getTimestamp();
948 if (
$user->wasRecorded())
952 if (
$user->wasRecorded())
954 $screenShared =
true;
959 $finishStatus =
'normal';
962 if(is_numeric($this->entityId))
964 $chatType =
'private';
967 $this->
getUser($this->entityId)
968 ? $this->
getUser($this->entityId)->getState()
974 $finishStatus =
'declined';
978 $finishStatus =
'busy';
982 $finishStatus =
'unavailable';
988 $isVideoConf = (bool)AliasTable::getRow([
995 if ($callLength > 30 && $finishStatus ===
'normal')
1000 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $userCountChat,
"user_count_chat", 0);
1001 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $usersActive,
"user_count_call", 0);
1002 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $mobileUsers,
"user_count_mobile", 0);
1003 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $externalUsers,
"user_count_external", 0);
1004 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $callLength,
"call_length", 0);
1005 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($screenShared ?
"Y" :
"N"),
"screen_shared", 0);
1006 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($recorded ?
"Y" :
"N"),
"recorded", 0);
1011 if (isset($isVideoConf))
1013 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($isVideoConf ?
"Y" :
"N"),
"is_videoconf", 0);
1020 if (Loader::includeModule(
'bitrix24'))
1022 return \CBitrix24::getPortalZone() ==
'ru';
1025 return Option::get(
'im',
'allow_call_feedback',
'N') ===
'Y';
1041 if (Loader::includeModule(
"bitrix24") && defined(
'BX24_HOST_NAME'))
1043 $portalId = BX24_HOST_NAME;
1045 else if (defined(
'IM_CALL_LOG_HOST'))
1047 $portalId = \IM_CALL_LOG_HOST;
1054 $secret = Option::get(
'im',
'call_log_secret');
1063 'call' => $this->
getId(),
1065 'exp' => (
new DateTime())->getTimestamp() + $ttl
1073 return (
string)Option::get(
'im',
'call_log_service');
1078 if (static::isCallServerEnabled())
1080 return static::getMaxCallServerParticipants();
1083 return (
int)Option::get(
'call',
'turn_server_max_users');
1088 if (Loader::includeModule(
'bitrix24'))
1090 return (
int)\Bitrix\Bitrix24\Feature::getVariable(
'im_max_call_participants');
1092 return (
int)Option::get(
'im',
'call_server_max_users');
1097 if (!\
Bitrix\
Main\Loader::includeModule(
'bitrix24'))
1102 return (
int)\Bitrix\Bitrix24\Feature::getVariable(
'im_call_extensions_limit');
1129 Loader::includeModule(
'call');
1131 if (
$scheme && in_array(
$scheme, [self::SCHEME_CLASSIC, self::SCHEME_JWT],
true))
1137 $instance->scheme = self::SCHEME_CLASSIC;
1141 $instance->provider === self::PROVIDER_BITRIX
1142 || (
$instance->provider === self::PROVIDER_PLAIN && \
Bitrix\
Call\Settings::isPlainCallsUseNewScheme())
1159 $instance->associatedEntity->onCallCreate();
1189 'initiatorId' =>
$instance->initiatorId,
1203 if (!Loader::includeModule(
'call'))
1208 if ($this->scheme === self::SCHEME_JWT)
1260 $instance->scheme = self::SCHEME_CLASSIC;
1262 Loader::includeModule(
'call');
1271 $instance->provider === self::PROVIDER_BITRIX
1272 || (
$instance->provider === self::PROVIDER_PLAIN && \
Bitrix\
Call\Settings::isPlainCallsUseNewScheme())
1284 if (isset(
$fields[
'RECORD_AUDIO']))
1293 if (isset(
$fields[
'AI_ANALYZE']))
1307 $row = CallTable::getRowById(
$id);
1310 return static::createWithArray($row);
1318 $row = CallTable::getList([
1320 'filter' => [
'=UUID' =>
$uuid],
1325 return static::createWithArray($row);
1333 if (!Loader::includeModule(
'call'))
1338 return (
bool)Option::get(
"im",
"call_server_enabled");
1343 if (Option::get(
'call',
'turn_server_self') ==
'Y')
1345 $turnServer = Option::get(
'call',
'turn_server');
1350 if (in_array(
$region, [
'ru',
'by',
'kz']))
1352 $turnServer =
'turn.bitrix24.tech';
1356 $turnServer =
'turn.calls.bitrix24.com';
1370 $isEnabled = Option::get(
'im',
'call_beta_ios',
'N');
1372 return $isEnabled ===
'Y';
1382 $callId =
$event->getParameter(
'CONFERENCE_CALL_ID');
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
const ENTITY_TYPE_VIDEOCONF
Integration AbstractEntity $associatedEntity
setActionUserId(int $byUserId)
inviteUsers(int $senderId, array $toUserIds, $isLegacyMobile, $video=false, $sendPush=true)
getUserRoles(array $users=[])
static createWithArray(array $fields)
static isIosBetaEnabled()
static isBitrixCallEnabled()
setLogUrl(string $logUrl)
getLogToken(int $userId=0, int $ttl=3600)
static getMaxCallServerParticipants()
static sendCreateCallEvent(Call $instance)
hasActiveUsers(bool $strict=true)
static createCallInstance(array $fields)
static loadWithUuid($uuid)
static isFeedbackAllowed()
createChildCall(string $newUuid, string $entityId, string $newProvider=null, int $scheme=null, int $newInitiator=null,)
static createWithEntity(int $type, string $provider, string $entityType, string $entityId, int $initiatorId, ?string $callUuid, ?int $scheme=null)
makeClone($newProvider=null)
sendInviteUsers(int $senderId, array $toUserIds, $isLegacyMobile, $video=false, $sendPush=true, string $sendMode=Signaling::MODE_ALL)
toArray($currentUserId=0, $withSecrets=false)
setAssociatedEntity($entityType, $entityId)
static getMaxParticipants()
static onVoximplantConferenceFinished(Event $event)
ErrorCollection $errorCollection
getConnectionData(int $userId)
prepareUserData(array $users)
const PROVIDER_VOXIMPLANT
static isCallServerEnabled()
static delete($callId, $userId)
static create(array $fields)
static createEntity(Call $call, $entityType, $entityId)
static getUsers(array $idList)
static getChatId($dialogId, $userId=null)
static incrementCounter(string $code)
const COUNTER_CALL_SUCCESS
static encode($payload, $key, $alg='HS256', $keyId=null, $head=null)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
AddEventToStatFile($module, $action, $tag, $label, $action_type='', $user_id=null)
randString($pass_len=10, $pass_chars=false)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</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."%"