【问题标题】:Laravel Pusher Not Receiving Data at Front EndLaravel Pusher 未在前端接收数据
【发布时间】:2016-11-13 20:03:14
【问题描述】:

这是我第一次使用 Pusher。我正在尝试制作一个测试 App Laravel 5.2 和 Pusher。

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

按照上面的教程,我配置了我的 Laravel,并成功地从 pusher Debug Console 中获取了“Channel”、“Event”和“Data”。

问题: 当我尝试从 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:状态改变:初始化 -> 连接

(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);
});

什么都不扔。

【问题讨论】:

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


    【解决方案1】:

    您的日志中有错误:

    (索引):10 推杆:错误: {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":4000,"message":"App 已加密(仅限 SSL)"}}}

    您的 Pusher 应用似乎要求您启用 SSL 进行连接。您可以在 Pusher 仪表板上找到此设置:

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

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

    【讨论】:

    • 谢谢。我已经解决了这个问题。但是忘记在这里重播了。再次感谢。
    猜你喜欢
    • 2021-07-11
    • 2020-09-05
    • 2018-04-08
    • 2020-10-14
    • 1970-01-01
    • 2017-05-03
    • 2019-02-25
    • 2020-04-14
    • 2020-03-21
    相关资源
    最近更新 更多