首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >龙骨棘轮

龙骨棘轮
EN

Stack Overflow用户
提问于 2016-05-26 13:33:13
回答 1查看 502关注 0票数 2

我计划使用棘轮和拉拉创建一个即时通讯服务(我发现了一个名为latchet的项目,它将棘轮集成到laravel中)。

我的问题是。

  1. 如何在允许客户端启动web套接字连接之前验证客户端。
  2. 一个用户可以是多个组的一部分,所以我想创建像Poll_grp_id这样的通道,并获得所有用户组的列表,然后订阅所有这些Poll_Grp_id通道。我不知道该怎么做
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-26 15:35:16

要回答你的第一个问题:

代码语言:javascript
复制
public function onSubscribe(ConnectionInterface $conn, $topic, $userKey) {
    //check if the userKey is correct for that user, ...
}

我自己和APIKey一起使用它,每次用户订阅时,他们都会使用它发送$userKey对象。

该对象只包含userId、apiKey、.(验证用户所需的一切)

第二个问题是:

//来自socketo.me的代码给出一个例子

代码语言:javascript
复制
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中具有特定通道的连接客户端。

我希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37462391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档