我计划使用棘轮和拉拉创建一个即时通讯服务(我发现了一个名为latchet的项目,它将棘轮集成到laravel中)。
我的问题是。
发布于 2016-05-26 15:35:16
要回答你的第一个问题:
public function onSubscribe(ConnectionInterface $conn, $topic, $userKey) {
//check if the userKey is correct for that user, ...
}我自己和APIKey一起使用它,每次用户订阅时,他们都会使用它发送$userKey对象。
该对象只包含userId、apiKey、.(验证用户所需的一切)
第二个问题是:
//来自socketo.me的代码给出一个例子
protected $subscribedTopics = array();
public function onSubscribe(ConnectionInterface $conn, $topic) {
$this->subscribedTopics[$topic->getId()] = $topic;
}
/**
* @param string JSON'ified string we'll receive from ZeroMQ
*/
public function onBlogEntry($entry) {
$entryData = json_decode($entry, true);
// If the lookup topic object isn't set there is no one to publish to
if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
return;
}
$topic = $this->subscribedTopics[$entryData['category']];
// re-send the data to all the clients subscribed to that category
$topic->broadcast($entryData);
}在这里,您将将onSubscribe($conn, $topic)更改为onSubscribe($conn, $topicArray)。
然后,将所有的“通道”从数组中分离出来,并将它们添加到$subscribedTopics中。
当您尝试向这些“通道”/“主题”发送某些内容时,它将发送给所有在其$topicArray中具有特定通道的连接客户端。
我希望这能帮到你。
https://stackoverflow.com/questions/37462391
复制相似问题