public static function AddByChannel($channelId, $arParams = array()) { global $DB; if (!is_array($channelId)) { $channelId = array($channelId); } if (strlen($arParams['module_id']) > 0 || strlen($arParams['command']) > 0) { $arData = array('module_id' => $arParams['module_id'], 'command' => $arParams['command'], 'params' => is_array($arParams['params']) ? $arParams['params'] : array()); if (CPullOptions::GetQueueServerStatus()) { $command = array('MESSAGE' => array($arData), 'ERROR' => ''); if (!is_array($channelId) && CPullOptions::GetQueueServerVersion() == 1) { $command['CHANNEL_ID'] = $channelId; } $message = CUtil::PhpToJsObject($command); if (!defined('BX_UTF') || !BX_UTF) { $message = $GLOBALS['APPLICATION']->ConvertCharset($message, SITE_CHARSET, 'utf-8'); } $res = CPullChannel::Send($channelId, str_replace("\n", " ", $message)); $result = $res ? true : false; } else { foreach ($channelId as $channel) { $arParams = array('CHANNEL_ID' => $channel, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction()); $res = IntVal($DB->Add("b_pull_stack", $arParams, array("MESSAGE"))); $result = $res ? true : false; } } if (isset($arParams['push_text']) && strlen($arParams['push_text']) > 0 && isset($arParams['push_user']) && intval($arParams['push_user']) > 0) { $CPushManager = new CPushManager(); $CPushManager->AddQueue(array('USER_ID' => $arParams['push_user'], 'MESSAGE' => str_replace("\n", " ", $arParams['push_text']), 'PARAMS' => $arParams['push_params'], 'BADGE' => isset($arParams['push_badge']) ? intval($arParams['push_badge']) : '', 'TAG' => isset($arParams['push_tag']) ? $arParams['push_tag'] : '', 'SUB_TAG' => isset($arParams['push_sub_tag']) ? $arParams['push_sub_tag'] : '', 'APP_ID' => isset($arParams['push_app_id']) ? $arParams['push_app_id'] : '')); } return $result; } return false; }
public static function AddByChannel($channelId, $arParams = array()) { global $DB; if (!is_array($channelId)) { $channelId = array($channelId); } $result = false; if (strlen($arParams['module_id']) > 0 || strlen($arParams['command']) > 0) { $arData = array('module_id' => $arParams['module_id'], 'command' => $arParams['command'], 'params' => is_array($arParams['params']) ? $arParams['params'] : array()); if (CPullOptions::GetQueueServerStatus()) { $command = array('SERVER_TIME_WEB' => time(), 'SERVER_NAME' => COption::GetOptionString('main', 'server_name', $_SERVER['SERVER_NAME']), 'MESSAGE' => array($arData), 'ERROR' => ''); if (!is_array($channelId) && CPullOptions::GetQueueServerVersion() == 1) { $command['CHANNEL_ID'] = $channelId; } $message = CUtil::PhpToJsObject($command); if (!defined('BX_UTF') || !BX_UTF) { $message = $GLOBALS['APPLICATION']->ConvertCharset($message, SITE_CHARSET, 'utf-8'); } $options = isset($arParams['expiry']) ? array('expiry' => intval($arParams['expiry'])) : array(); $res = CPullChannel::Send($channelId, str_replace("\n", " ", $message), $options); $result = $res ? true : false; } else { foreach ($channelId as $channel) { $arParams = array('CHANNEL_ID' => $channel, 'MESSAGE' => str_replace("\n", " ", serialize($arData)), '~DATE_CREATE' => $DB->CurrentTimeFunction()); $res = IntVal($DB->Add("b_pull_stack", $arParams, array("MESSAGE"))); $result = $res ? true : false; } } return $result; } return false; }
/** * Return some information about P&P, such as publish url * * @since 14.5.4 * @return array */ protected static function getPullingInfo() { $result = array('enabled' => CModule::IncludeModule('pull') && CPullOptions::ModuleEnable()); if ($result['enabled']) { $result['nginx_used'] = CPullOptions::GetQueueServerStatus(); if ($result['nginx_used']) { $result['server_protocol'] = CPullOptions::GetQueueServerVersion(); $result['publish_url'] = CPullOptions::GetPublishUrl(); $result['pulling_url'] = CPullOptions::GetListenUrl(); $result['pulling_url_secure'] = CPullOptions::GetListenSecureUrl(); $result['websocket_url'] = CPullOptions::GetWebSocketUrl(); $result['websocket_url_secure'] = CPullOptions::GetWebSocketSecureUrl(); } } return $result; }
public static function Send($channelId, $message, $method = 'POST', $timeout = 5, $dont_wait_answer = true) { $result_start = '{"infos": ['; $result_end = ']}'; if (is_array($channelId) && CPullOptions::GetQueueServerVersion() == 1) { $results = Array(); foreach ($channelId as $channel) { $results[] = self::SendCommand($channel, $message, $method, $timeout, $dont_wait_answer); } $result = json_decode($result_start.implode(',', $results).$result_end); } else if (is_array($channelId)) { $commandPerHit = CPullOptions::GetCommandPerHit(); if (count($channelId) > $commandPerHit) { $arGroup = Array(); $i = 0; foreach($channelId as $channel) { if (count($arGroup[$i]) == $commandPerHit) $i++; $arGroup[$i][] = $channel; } $results = Array(); foreach($arGroup as $channels) { $result = self::SendCommand($channels, $message, $method, $timeout, $dont_wait_answer); $subresult = json_decode($result); $results = array_merge($results, $subresult->infos); } $result = json_decode('{"infos":'.json_encode($results).'}'); } else { $result = self::SendCommand($channelId, $message, $method, $timeout, $dont_wait_answer); $result = json_decode($result); } } else { $result = self::SendCommand($channelId, $message, $method, $timeout, $dont_wait_answer); $result = json_decode($result_start.$result.$result_end); } return $result; }
<td ><?=GetMessage("PULL_OPTIONS_PATH_TO_MOBILE_LISTENER_SECURE")?>:</td> <td><input id="config_path_to_mobile_listener_secure" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetListenSecureUrl("", true))?>" name="path_to_mobile_listener_secure" <?=(CPullOptions::GetQueueServerStatus()? '':'disabled="true"')?>></td> </tr> <tr> <td width="40%"></td> <td width="60%"> <?=GetMessage("PULL_OPTIONS_PATH_TO_MOBILE_LISTENER_DESC")?> </td> </tr> <tr> <td width="40%"></td> <td width="60%"></td> </tr> <tr> <td align="right" width="50%"><?=GetMessage("PULL_OPTIONS_WEBSOCKET")?>:</td> <td><input type="checkbox" size="40" value="Y" <?=(CPullOptions::GetWebSocket()?' checked':'')?> id="config_websocket" name="websocket" <?=(CPullOptions::GetQueueServerStatus() && CPullOptions::GetQueueServerVersion() > 1 ? '': 'disabled="true"')?>></td> </tr> <tr> <td ><?=GetMessage("PULL_OPTIONS_PATH_TO_WEBSOCKET")?>:</td> <td><input id="config_path_to_websocket" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetWebSocketUrl())?>" name="path_to_websocket" <?=(!CPullOptions::GetQueueServerStatus() || !CPullOptions::GetWebSocketStatus() ? 'disabled="true"': '')?></td> </tr> <tr> <td ><?=GetMessage("PULL_OPTIONS_PATH_TO_WEBSOCKET_SECURE")?>:</td> <td><input id="config_path_to_websocket_secure" type="text" size="40" value="<?=htmlspecialcharsbx(CPullOptions::GetWebSocketSecureUrl())?>" name="path_to_websocket_secure" <?=(!CPullOptions::GetQueueServerStatus() || !CPullOptions::GetWebSocketStatus() ? 'disabled="true"': '')?></td> </tr> <tr> <td width="40%"></td> <td width="60%"> <?=GetMessage("PULL_OPTIONS_WEBSOCKET_DESC")?> </td> </tr>
<tr class="heading"> <td colspan="2"><b><?php echo GetMessage('PULL_OPTIONS_HEAD_SUB_WS'); ?> </b></td> </tr> <tr> <td align="right" width="50%"><?php echo GetMessage("PULL_OPTIONS_WEBSOCKET"); ?> :</td> <td><input type="checkbox" size="40" value="Y" <?php echo CPullOptions::GetWebSocket() ? ' checked' : ''; ?> id="config_websocket" name="websocket" <?php echo CPullOptions::GetQueueServerStatus() && CPullOptions::GetQueueServerVersion() > 1 ? '' : 'disabled="true"'; ?> ></td> </tr> <tr> <td ><?php echo GetMessage("PULL_OPTIONS_PATH_TO_LISTENER"); ?> :</td> <td><input id="config_path_to_websocket" type="text" size="40" value="<?php echo htmlspecialcharsbx(CPullOptions::GetWebSocketUrl()); ?> " name="path_to_websocket" <?php echo !CPullOptions::GetQueueServerStatus() || !CPullOptions::GetWebSocketStatus() ? 'disabled="true"' : ''; ?> </td>