【发布时间】:2015-03-10 04:06:51
【问题描述】:
我正在使用Pusher 创建一个测试应用程序,以便在Laravel 4 上进行实时通知。
在我测试上述 API 时,我很难让它发挥作用。
我的routes.php上有这个:
Route::get('pusher-test', function(){
return View::make('pages.test');
});
Route::any('test', function(){
$pusher = new Pusher('key','sect','app_key'); //my keys are correct.
$pusher->trigger('notificationChannel', 'userRegistration', []);
});
然后是我的pusherTest.js 文件:
(function(){
var pusher = new Pusher('key');
var channel = pusher.subscribe('notificationChannel');
channel.bind('userRegistration', function(data){
$('.test').append('HEY!');
});
})();
我的查看页面:
<html>
<head>
<meta charset="utf-8">
{{ HTML::style('_/css/bootstrap.css') }}
{{ HTML::style('_/css/mystyle.css') }}
</head>
<body>
<h2>HI!</h2>
<div class="test"></div>
{{ HTML::script('_/js/bootstrap.js') }}
{{ HTML::script('_/js/jquery.js') }}
{{ HTML::script('_/js/pusher/pusher.min.js')}}
{{ HTML::script('_/js/pusherTest.js')}}
</body>
</html>
当我尝试在 Pusher.com 上观察我的应用程序的 Debug Console 时,
这是我看到的:
但是当我点击test 路由时,它不会在我的 Pusher 应用程序上发送事件,也不会向我的客户端发送 API 消息。但是,如果我将在调试控制台上使用Create new Event 测试器,那么它肯定会发送 API 消息,而我的客户端会接收并更新它。
您认为发生了什么,为什么在我的路线上它无法将事件发送到我的推送应用程序?我无法弄清楚,因为它没有异常错误。请指教。
【问题讨论】:
标签: laravel websocket push-notification real-time pusher