-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathProxyService.php
117 lines (108 loc) · 3.25 KB
/
ProxyService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
declare(strict_types=1);
/**
*
* This is my open source code, please do not use it for commercial applications.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code
*
* @author CodingHePing<847050412@qq.com>
* @link https://github.com/Hyperf-Glory/socket-io
*/
namespace App\JsonRpc;
use App\JsonRpc\Contract\InterfaceProxyService;
use App\Task\CloudTask;
use Hyperf\Logger\LoggerFactory;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Utils\Coroutine;
use Psr\Container\ContainerInterface;
/**
* 该类暂时废弃.
* @deprecated
* Class Cloud
* @RpcService(name="ProxyService", protocol="jsonrpc-tcp-length-check", server="jsonrpc", publishTo="consul")
*/
class ProxyService implements InterfaceProxyService
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->logger = $container->get(LoggerFactory::class)->get();
}
/**
* @deprecated
* 单点推送
* Message:
*{"event":"event_talk","data":{"send_user":4166,"receive_user":"4167","source_type":"1","text_message":"1"}}
*
* @param int $uid 用户的唯一ID
*
* @return mixed|void
*/
public function pushMessage(int $uid, string $message)
{
$this->logger->debug('cloud node: pushmsg');
if (empty($keys) || empty($message)) {
$this->logger->error('cloud json-rpc pushmsg keys message is empty raw data');
return;
}
di(CloudTask::class)->push((string) $uid, $message);
}
/**
* 广播.
* @deprecated
*/
public function broadcast(string $message)
{
if (empty($message)) {
$this->logger->error('cloud json-rpc broadcast message is empty raw data');
return;
}
$this->logger->debug(sprintf('cloud json-rpc broadcast message:%s', $message));
Coroutine::create(function () use ($message) {
di(CloudTask::class)->broadcast($message);
});
}
/**
* @deprecated
* 群聊推送
* Message:
* {"event":"event_talk","data":{"send_user":4166,"receive_user":"117","source_type":"2","text_message":"2"}}
*
* @param int $groupId 群聊ID
*/
public function group(int $groupId, string $message)
{
if (empty($message)) {
$this->logger->error('cloud json-rpc broadcast message is empty raw data');
return;
}
$this->logger->debug(sprintf('cloud json-rpc broadcast message:%s', $message));
Coroutine::create(function () use ($groupId, $message) {
di(CloudTask::class)->group($groupId, $message);
});
}
/**
* @deprecated
*/
public function publish(string $channel, string $message)
{
if (empty($message)) {
$this->logger->error('cloud json-rpc publish message is empty raw data');
return;
}
if (empty($channel)) {
$this->logger->error('cloud json-rpc publish channel is empty raw data');
return;
}
}
}