14 public static function get(array $params = [])
16 if (!\CPullOptions::GetQueueServerStatus())
19 $userId = (int)($params[
'USER_ID'] ?? 0);
20 if (isset($params[
'CHANNEL']) && !($params[
'CHANNEL'] instanceof \Bitrix\Pull\Model\Channel))
22 throw new ArgumentException(
'$params["CHANNEL"] should be instance of \Bitrix\Pull\Model\Channel');
25 if ($userId === 0 && !isset($params[
'CHANNEL']))
28 $userId = (int)$USER->GetID();
35 $params[
'CACHE'] = (bool)($params[
'CACHE'] ??
true);
36 $params[
'REOPEN'] = (bool)($params[
'REOPEN'] ??
false);
38 $cache = $params[
'CACHE'] !==
false;
39 $reopen = $params[
'REOPEN'] !==
false;
43 $privateChannelType = $params[
'CUSTOM_TYPE'] ?? \CPullChannel::TYPE_PRIVATE;
44 $privateChannel = \CPullChannel::Get($userId, $cache, $reopen, $privateChannelType);
45 $sharedChannelType = $params[
'CUSTOM_TYPE'] ?? \CPullChannel::TYPE_SHARED;
46 $sharedChannel = \CPullChannel::GetShared($cache, $reopen, $sharedChannelType);
51 'CHANNEL_ID' => $params[
'CHANNEL']->getPrivateId(),
52 'CHANNEL_PUBLIC_ID' => $params[
'CHANNEL']->getPublicId(),
53 'CHANNEL_DT' => $params[
'CHANNEL']->getDateCreate()->getTimestamp(),
54 'CHANNEL_DT_END' => $params[
'CHANNEL']->getDateCreate()->getTimestamp() + static::ONE_YEAR,
56 $sharedChannel =
null;
59 $domain = defined(
'BX24_HOST_NAME')? BX24_HOST_NAME: $_SERVER[
'SERVER_NAME'];
61 $isSharedMode = \CPullOptions::IsServerShared();
63 'VERSION' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getServerVersion(): \CPullOptions::GetQueueServerVersion(),
64 'SERVER_ENABLED' => \CPullOptions::GetQueueServerStatus(),
65 'MODE' => \CPullOptions::GetQueueServerMode(),
66 'LONG_POLLING' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getLongPollingUrl(): \CPullOptions::GetListenUrl(),
67 'LONG_POOLING_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getLongPollingUrl() : \CPullOptions::GetListenSecureUrl(),
68 'WEBSOCKET_ENABLED' => $isSharedMode ? true : \CPullOptions::GetWebSocket(),
69 'WEBSOCKET' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebSocketUrl() : \CPullOptions::GetWebSocketUrl(),
70 'WEBSOCKET_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebSocketUrl() : \CPullOptions::GetWebSocketSecureUrl(),
71 'PUBLISH_ENABLED' => $isSharedMode ? true : \CPullOptions::GetPublishWebEnabled(),
72 'PUBLISH' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebPublishUrl() : \CPullOptions::GetPublishWebUrl(),
73 'PUBLISH_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebPublishUrl() : \CPullOptions::GetPublishWebSecureUrl(),
74 'CONFIG_TIMESTAMP' => \CPullOptions::GetConfigTimestamp(),
76 foreach ($serverConfig as $key => $value)
78 if(is_string($value) && mb_strpos($value,
'#DOMAIN#') !==
false)
80 $serverConfig[$key] = str_replace(
'#DOMAIN#', $domain, $value);
83 $config[
'SERVER'] = $serverConfig;
86 $config[
'CLIENT_ID'] = Client::getPublicLicenseCode();
89 $config[
'API'] = Array(
90 'REVISION_WEB' => PULL_REVISION_WEB,
91 'REVISION_MOBILE' => PULL_REVISION_MOBILE,
94 $config[
'CHANNELS'] = [];
97 $config[
'CHANNELS'][
'SHARED'] = [
98 'ID' => \CPullChannel::SignChannel($sharedChannel[
"CHANNEL_ID"]),
99 'START' => $sharedChannel[
'CHANNEL_DT'],
100 'END' => $sharedChannel[
'CHANNEL_DT']+\CPullChannel::CHANNEL_TTL,
105 if (\CPullOptions::GetQueueServerVersion() > 3)
107 $privateId = $privateChannel[
'CHANNEL_PUBLIC_ID']
108 ?
"{$privateChannel['CHANNEL_ID']}:{$privateChannel['CHANNEL_PUBLIC_ID']}"
109 : $privateChannel[
'CHANNEL_ID']
111 $privateId = \CPullChannel::SignChannel($privateId);
113 $publicId = \CPullChannel::SignPublicChannel($privateChannel[
'CHANNEL_PUBLIC_ID']);
117 $privateId = \CPullChannel::SignChannel($privateChannel[
'CHANNEL_ID']);
121 $config[
'CHANNELS'][
'PRIVATE'] = [
123 'PUBLIC_ID' => $publicId,
124 'START' => $privateChannel[
'CHANNEL_DT'],
125 'END' => $privateChannel[
'CHANNEL_DT_END'] ?? $privateChannel[
'CHANNEL_DT']+\CPullChannel::CHANNEL_TTL,
129 $params[
'JSON'] = (bool)($params[
'JSON'] ??
false);
131 $config[
'PUBLIC_CHANNELS'] = \Bitrix\Pull\Channel::getPublicIds([
'JSON' => $params[
'JSON']]);
132 if (\CPullOptions::GetQueueServerVersion() >= 5)
134 $channelsForToken = [];
137 $channelsForToken[] = $sharedChannel[
'CHANNEL_ID'];
139 if ($privateChannel && $userId == 0)
141 $channelsForToken[] = $privateChannel[
'CHANNEL_ID'];
142 if ($privateChannel[
'CHANNEL_PUBLIC_ID'] !=
'')
144 $channelsForToken[] = $privateChannel[
'CHANNEL_PUBLIC_ID'];
147 [$config[
'JWT'], $config[
'EXP']] = \Bitrix\Pull\Auth\Jwt::create($channelsForToken, $userId, [
148 'ttl' => \CPullOptions::GetConfigTtl()
151 if (\CPullOptions::GetConfigTtl() > 0 && !isset($config[
'EXP']))
153 $config[
'EXP'] = time() + \CPullOptions::GetConfigTtl();
158 $result[
'server'] = array_change_key_case($config[
'SERVER'], CASE_LOWER);
159 $result[
'api'] = array_change_key_case($config[
'API'], CASE_LOWER);
161 foreach ($config[
'CHANNELS'] as $type => $channel)
163 $type = mb_strtolower($type);
164 $result[
'channels'][$type] = array_change_key_case($channel, CASE_LOWER);
165 $result[
'channels'][$type][
'type'] = $type;
166 $result[
'channels'][$type][
'start'] = date(
'c', $channel[
'START']);
167 $result[
'channels'][$type][
'end'] = date(
'c', $channel[
'END']);
172 $result[
'clientId'] = $config[
'CLIENT_ID'];
174 if (isset($config[
'JWT']))
176 $result[
'jwt'] = $config[
'JWT'];
178 if (isset($config[
'EXP']))
180 $result[
'exp'] = $config[
'EXP'];
183 $result[
'publicChannels'] = $config[
'PUBLIC_CHANNELS'];