【问题标题】:How do I trigger an event to an individual only using Pusher?如何仅使用 Pusher 向个人触发事件?
【发布时间】:2014-04-19 12:28:41
【问题描述】:

我使用 PHP 和 Pusher API 编写聊天程序。 现在,我正在尝试向单个用户触发事件,但我不知道该怎么做。 每个用户都由一个会话(用户名)标识。 这就是我触发消息的方式:

$pusher->trigger(
        'presence-nettuts', //the channel
        'new_message', //the event
        array('message' => $message) //the data to send
);

//echo the success array for the ajax call
echo json_encode(array(
        'message' => $message,
        'success' => true
));
exit();

我只想将事件定向到在线用户,该用户使用会话由他的用户名标识。

你能指导我怎么做吗?

谢谢。

【问题讨论】:

标签: php chat pusher


【解决方案1】:

您的频道名称对于该用户应该是唯一的。 因此,一种可能性是使用用户名等独特的东西创建频道:

$pusher->trigger(
 'presence-nettuts-'.$username, //the channel
 'new_message', //the event
 array('message' => $message) //the data to send
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多