102 return isset($this->users[$userId]) ? $this->users[$userId] :
null;
112 return array_keys($this->users);
124 return isset($this->users[$userId]);
136 if($this->users[$newUserId])
138 return $this->users[$newUserId];
147 'CALL_ID' => $this->
id,
148 'USER_ID' => $newUserId,
152 $this->users[$newUserId]->save();
154 if($this->associatedEntity)
156 $this->associatedEntity->onUserAdd($newUserId);
159 return $this->users[$newUserId];
165 if($this->users[$userId])
168 unset($this->users[$userId]);
183 foreach ($this->users as $userId => $user)
185 $userState = $user->getState();
186 $states[$userState] = isset($states[$userState]) ? $states[$userState] + 1 : 1;
188 if($this->type == static::TYPE_PERMANENT || !$strict)
200 if(is_null($this->signaling))
225 $this->associatedEntity = $entity;
241 return in_array($userId, $this->
getUsers());
305 public function inviteUsers(
int $senderId, array $toUserIds, $isLegacyMobile, $video =
false, $sendPush =
true)
321 if($this->state ==
$state)
327 $updateResult = CallTable::updateState($this->
getId(),
$state);
333 if($this->associatedEntity)
335 $this->associatedEntity->onStateChange(
$state, $prevState);
352 if($this->endDate instanceof
DateTime)
362 foreach ($this->users as $callUser)
379 public function toArray($currentUserId = 0, $withSecrets =
false)
385 'IS_PUBLIC' => $this->isPublic ?
'Y' :
'N',
410 $fields = $this->
toArray(0,
true);
411 unset($fields[
'ID']);
415 $insertResult = CallTable::add($fields);
416 $this->
id = $insertResult->getId();
420 $updateResult = CallTable::update($this->
id, $fields);
426 $callFields = $this->
toArray();
427 $callFields[
'ID'] =
null;
428 $callFields[
'PUBLIC_ID'] = randString(10);
429 $callFields[
'STATE'] = static::STATE_NEW;
430 $callFields[
'PROVIDER'] = $newProvider ?? $callFields[
'PROVIDER'];
433 $instance = CallFactory::createWithArray($callFields[
'PROVIDER'], $callFields);
436 $instance->users = [];
437 foreach ($this->
getUsers() as $userId)
440 'CALL_ID' => $instance->id,
441 'USER_ID' => $userId,
442 'STATE' => $instance->users[$userId] ? $instance->users[$userId]->getState() :
CallUser::STATE_IDLE,
445 $instance->users[$userId]->save();
453 if(is_array($this->users))
456 $this->users = array();
458 $cursor = CallUserTable::getList(array(
460 '=CALL_ID' => $this->
id
464 while($row = $cursor->fetch())
473 if ($this->startDate instanceof
DateTime && $this->endDate instanceof
DateTime)
475 $callLength = $this->endDate->getTimestamp() - $this->startDate->getTimestamp();
477 $userCountChat = count($this->users);
482 $screenShared =
false;
484 $authTypes = UserTable::getList([
485 'select' => [
'ID',
'EXTERNAL_AUTH_ID'],
486 'filter' => [
'=ID' => $this->
getUsers()]
488 $authTypes = array_column($authTypes,
'EXTERNAL_AUTH_ID',
'ID');
489 foreach ($this->users as $userId => $user)
491 if ($user->getLastSeen() !=
null)
495 if ($user->isUaMobile())
502 if ($user->getFirstJoined())
504 $userLateness = $user->getFirstJoined()->getTimestamp() - $this->startDate->getTimestamp();
505 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $userLateness,
"user_lateness", $userId);
508 if ($user->wasRecorded())
512 if ($user->wasRecorded())
514 $screenShared =
true;
519 $finishStatus =
'normal';
522 if(is_numeric($this->entityId))
524 $chatType =
'private';
527 $this->
getUser($this->entityId)
528 ? $this->
getUser($this->entityId)->getState()
534 $finishStatus =
'declined';
538 $finishStatus =
'busy';
542 $finishStatus =
'unavailable';
548 $isVideoConf = (bool)AliasTable::getRow([
555 if ($callLength > 30 && $finishStatus ===
'normal')
560 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $userCountChat,
"user_count_chat", 0);
561 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $usersActive,
"user_count_call", 0);
562 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $mobileUsers,
"user_count_mobile", 0);
563 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $externalUsers,
"user_count_external", 0);
564 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $callLength,
"call_length", 0);
565 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($screenShared ?
"Y" :
"N"),
"screen_shared", 0);
566 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($recorded ?
"Y" :
"N"),
"recorded", 0);
569 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $chatType,
"chat_type", 0);
571 if (isset($isVideoConf))
573 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, ($isVideoConf ?
"Y" :
"N"),
"is_videoconf", 0);
575 AddEventToStatFile(
"im",
"im_call_finish", $this->
id, $finishStatus,
"status", 0);
580 if (Loader::includeModule(
'bitrix24'))
582 return \CBitrix24::getPortalZone() ==
'ru';
585 return Option::get(
'im',
'allow_call_feedback',
'N') ===
'Y';
590 if ($this->provider == static::PROVIDER_VOXIMPLANT)
592 return static::getMaxCallServerParticipants();
595 return (
int)Option::get(
'im',
'turn_server_max_users');
598 public function getLogToken(
int $userId = 0,
int $ttl = 3600) : string
606 if (Loader::includeModule(
"bitrix24") && defined(
'BX24_HOST_NAME'))
608 $portalId = BX24_HOST_NAME;
610 else if (defined(
'IM_CALL_LOG_HOST'))
612 $portalId = IM_CALL_LOG_HOST;
619 $secret = Option::get(
'im',
'call_log_secret');
628 'call' => $this->
getId(),
630 'exp' => (
new DateTime())->getTimestamp() + $ttl
638 return (
string)Option::get(
'im',
'call_log_service');
643 if (static::isCallServerEnabled())
645 return static::getMaxCallServerParticipants();
649 return (
int)Option::get(
'im',
'turn_server_max_users');
655 if(Loader::includeModule(
'bitrix24'))
657 return (
int)\Bitrix\Bitrix24\Feature::getVariable(
'im_max_call_participants');
659 return (
int)Option::get(
'im',
'call_server_max_users');
667 $instance =
new static();
668 $instance->type =
$type;
673 $instance->startDate =
new DateTime();
674 $instance->publicId = randString(10);
675 $instance->state = static::STATE_NEW;
677 $instance->associatedEntity = Integration\EntityFactory::createEntity($instance,
$entityType,
$entityId);
678 $instance->chatId = $instance->associatedEntity->getChatId();
683 $instance->associatedEntity->onCallCreate();
685 $instance->users = [];
686 foreach ($instance->associatedEntity->getUsers() as $userId)
689 'CALL_ID' => $instance->id,
690 'USER_ID' => $userId,
694 $instance->users[$userId]->save();
697 $instance->initCall();
703 'id' => $instance->id,
704 'type' => $instance->type,
705 'initiatorId' => $instance->initiatorId,
706 'provider' => $instance->provider,
707 'entityType' => $instance->entityType,
708 'entityId' => $instance->entityId,
709 'startDate' => $instance->startDate,
710 'publicId' => $instance->publicId,
711 'chatId' => $instance->chatId,
740 $currentUserId = \Bitrix\Im\User::getInstance()->getId();
742 $query = CallTable::query()
744 ->where(
"TYPE",
$type)
747 ->whereNull(
"END_DATE")
748 ->setOrder([
"ID" =>
"DESC"])
753 $query->where(
"INITIATOR_ID",
$entityId);
754 $query->where(
"ENTITY_ID", $currentUserId);
761 $callFields = $query->exec()->fetch();
768 $instance = static::createWithArray($callFields);
769 if($instance->hasActiveUsers(
false))
778 $callFields = CallTable::query()
780 ->where(
"UUID",
$uuid)
791 return static::createWithArray($callFields);
802 $instance =
new static();
804 $instance->id = $fields[
'ID'];
805 $instance->type = (int)$fields[
'TYPE'];
806 $instance->initiatorId = $fields[
'INITIATOR_ID'];
807 $instance->isPublic = $fields[
'IS_PUBLIC'];
808 $instance->publicId = $fields[
'PUBLIC_ID'];
809 $instance->provider = $fields[
'PROVIDER'];
810 $instance->entityType = $fields[
'ENTITY_TYPE'];
811 $instance->entityId = $fields[
'ENTITY_ID'];
812 $instance->startDate = isset ($fields[
'START_DATE']) && $fields[
'START_DATE'] instanceof
DateTime ? $fields[
'START_DATE'] :
null;
813 $instance->endDate = isset ($fields[
'END_DATE']) && $fields[
'END_DATE'] instanceof
DateTime ? $fields[
'END_DATE'] :
null;
814 $instance->parentId = (int)$fields[
'PARENT_ID'] ?:
null;
815 $instance->state = $fields[
'STATE'];
816 $instance->logUrl = $fields[
'LOG_URL'];
817 $instance->chatId = $fields[
'CHAT_ID'];
818 $instance->uuid = $fields[
'UUID'];
819 $instance->secretKey = $fields[
'SECRET_KEY'];
820 $instance->endpoint = $fields[
'ENDPOINT'];
822 if($instance->entityType && $instance->entityId)
824 $instance->associatedEntity = Integration\EntityFactory::createEntity($instance, $instance->entityType, $instance->entityId);
827 $instance->initCall();
843 $row = CallTable::getRow([
851 return static::createWithArray($row);
861 $row = CallTable::getRowById(
$id);
865 return static::createWithArray($row);
875 if (Loader::includeModule(
"bitrix24"))
884 return (
bool)Option::get(
"im",
"call_server_enabled");
897 $isEnabled = Option::get(
'im',
'bitrix_call_enabled',
'N');
899 return $isEnabled ===
'Y';
const ENTITY_TYPE_VIDEOCONF
inviteUsers(int $senderId, array $toUserIds, $isLegacyMobile, $video=false, $sendPush=true)
static createWithArray(array $fields)
static isBitrixCallEnabled()
setLogUrl(string $logUrl)
getLogToken(int $userId=0, int $ttl=3600)
static getMaxCallServerParticipants()
hasActiveUsers(bool $strict=true)
static searchActiveByUuid(string $uuid)
static createWithPublicId($publicId)
static isFeedbackAllowed()
makeClone($newProvider=null)
toArray($currentUserId=0, $withSecrets=false)
setAssociatedEntity($entityType, $entityId)
static getMaxParticipants()
static onVoximplantConferenceFinished(Event $event)
static createWithEntity($type, $provider, $entityType, $entityId, $initiatorId)
static isBitrixCallServerEnabled()
static searchActive($type, $provider, $entityType, $entityId, $currentUserId=0)
getConnectionData(int $userId)
const PROVIDER_VOXIMPLANT
static isVoximplantCallServerEnabled()
static isCallServerEnabled()
static delete($callId, $userId)
static create(array $fields)
static getChatId($dialogId, $userId=null)
const COUNTER_CALL_SUCCESS
static isModuleInstalled($moduleName)
static encode($payload, $key, $alg='HS256', $keyId=null, $head=null)
$GLOBALS['____1444769544']