我正在尝试使用Laravel 5.3和Pusher为我的Web-Applicatin构建实时通知。我能够将消息推送到Pusher调试控制台。 我的服务器端脚本:
$options = array(
'cluster' => 'ap2',
'encrypted' => true
);
$pusher = new Pusher(
'xxxxxxxxxx', // removed for safety
'xxxxxxxxxx', // removed for safety
'xxxxx', // removed for safety
$options
);
$data['message'] = ($user->name)." like your status";
$pusher->trigger('my-channel', 'PusherEvent', $data);
我的客户端脚本:
<script src="https://js.pusher.com/4.0/pusher.min.js"></script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('xxxxxxxxx', {
cluster: 'ap2',
encrypted: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('PusherEvent', function(data) {
alert(data.message);
});
我希望在我的网页上获得提醒。我的浏览器启用了JavaScript。我的浏览器控制台显示如下内容:
Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"my-channel"}} pusher.min.js:8:2594
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"my-channel"}
Pusher : No callbacks on my-channel for pusher:subscription_succeeded
这可能是什么原因??
答案 0 :(得分:0)
您对名为pusher_internal:subscription_succeeded
的活动没有任何约束力。这很正常,无需担心。当您订阅频道时,会触发您不会收听的事件。
如果您收到了一个名为PusherEvent
的事件并收到了该回调消息,那么您应该关注它。