Laravel Pusher未在前端接收数据

时间:2016-11-13 20:03:15

标签: javascript laravel-5 push-notification push pusher

这是我对 Pusher 的第一次体验。我正在尝试测试App Laravel 5.2和Pusher。

  

https://pusher-community.github.io/real-time-laravel/

按照上面的教程我配置了我的Laravel并成功获得了#34;频道","事件"和"数据"来自pusher Debug Console。

问题: 当我试图从JavaScript获取推送通知然后面临一些问题。

<script>
            Pusher.log = function (msg) {
//                console.log(msg);
            };
            var pusher = new Pusher("{{env("PUSHER_KEY")}}")
            var channel = pusher.subscribe('test-channel');
            channel.bind('test-event', function (data) {
//                console.log(data);
            });
    </script>

1。

console.log(msg);***抛出这样的信息。

  

Pusher:状态已更改:已初始化 - &gt;连接

(index):10 Pusher : Connecting : {"transport":"ws","url":"ws://ws.pusherapp.com:80/app/78b26f324ef425bcd2ca?protocol=7&client=js&version=3.0.0&flash=false"}

(index):10 Pusher : Connecting : {"transport":"ws","url":"ws://ws.pusherapp.com:80/app/78b26f324ef425bcd2ca?protocol=7&client=js&version=3.0.0&flash=false"}
(index):1 WebSocket connection to 'ws://ws.pusherapp.com/app/78b26f324ef425bcd2ca?protocol=7&client=js&version=3.0.0&flash=false' failed: WebSocket is closed before the connection is established.
pusher.min.js:12 Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4000,"message":"App is encrypted (SSL only)"}}}b.warn @ pusher.min.js:12(anonymous function) @ pusher.min.js:12a.emit @ pusher.min.js:30(anonymous function) @ pusher.min.js:85b @ pusher.min.js:80s @ pusher.min.js:46l @ pusher.min.js:49(anonymous function) @ pusher.min.js:50(anonymous function) @ pusher.min.js:52c.finish @ pusher.min.js:77a.onClosed @ pusher.min.js:77a.emit @ pusher.min.js:30c.changeState @ pusher.min.js:59c.onClose @ pusher.min.js:58a.socket.onclose @ pusher.min.js:59

(index):10 Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4000,"message":"App is encrypted (SSL only)"}}}

(index):10 Pusher : Connecting : {"transport":"ws","url":"wss://ws.pusherapp.com:443/app/78b26f324ef425bcd2ca?protocol=7&client=js&version=3.0.0&flash=false"}

(index):10 Pusher : State changed : connecting -> connected

(index):10 Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"test-channel"}}

(index):10 Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"test-channel"}

(index):10 Pusher : No callbacks on test-channel for pusher:subscription_succeeded

2

channel.bind('test-event', function (data) { 
    console.log(data);
});

什么也没扔。

1 个答案:

答案 0 :(得分:1)

您的日志中出现错误:

  

(index):10 Pusher:错误:   { “类型”: “WebSocketError”, “错误”:{ “类型”: “PusherError”, “数据”:{ “代码”:4000, “消息”:“应用程序   已加密(仅限SSL)“}}}

看起来您的Pusher应用程序要求您连接启用SSL。您可以在Pusher仪表板上找到此设置:

Pusher Dashboard encryption

要解决此问题,您需要像这样连接到Pusher:

var pusher = new Pusher("{{env("PUSHER_KEY")}}", { encrypted: true })