You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
971 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace websocket;
use GatewayClient\Gateway;
class Websocket extends Base
{
/**
* 向所有客户端发消息
* @param array $message 消息
* @param string $data_transfer 数据转换 json--转成json格式 ''--不做任何转换
* @date 2022-05-17
*/
public function sendToAll($message = [], $data_transfer = 'json')
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
if ($data_transfer == 'json') {
$message = json_encode($message);
}
// 发送消息
$result = Gateway::sendToAll($message);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'message' => $message
], $result, 'getaway_worker_send_to_all_uid_' . $uid);
return $result;
}
}