duanhuang1967 2016-11-08 16:10
浏览 96
已采纳

推杆没有回电话

I am trying to test a basic pusher trigger event that gives me a simple alert and a console log, but it wont work. The response is received from the pusher console debug but there are no alerts. I am using laravel 5.3 and its routes and a view for this. Below is my code. I have censored the sensitive information.

route file web.php

Route::get('/bridge', function() {

    error_reporting(E_ALL);

    $options = array(
        'cluster' => 'ap1',
        'encrypted' => true
    );
    $pusher = new Pusher(
        'key censored',
        'secret censored',
        'app id censore',
        $options
    );

    $data['message'] = 'hello world';
    $pusher->trigger('test_channel', 'my_event', $data);

    return view('pusher');
});

and view pusher.blade.php

<!DOCTYPE html>
<head>
    <title>Pusher Test</title>
    <script src="https://js.pusher.com/3.2/pusher.min.js"></script>
    <script>

        // Enable pusher logging - don't include this in production
        Pusher.logToConsole = true;

        var pusher = new Pusher('e5bbf707214a6223d044', {
            cluster: 'ap1',
            encrypted: true
        });

        var channel = pusher.subscribe('test_channel');
        channel.bind('my_event', function(data) {
           alert(data);
            console.log(data);
        });
    </script>
</head>

chrome console gives me the following logs.

Pusher : State changed : initialized -> connecting
Pusher : Connecting : {"transport":"ws","url":"wss://ws-ap1.pusher.com:443/app/censored key?protocol=7&client=js&version=3.2.2&flash=false"}
Pusher : State changed : connecting -> connected with new socket ID 5034.8700909
Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"test_channel"}}
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"test_channel"}
Pusher : No callbacks on test_channel for pusher:subscription_succeeded
  • 写回答

1条回答 默认 最新

  • douqianbiao4216 2016-11-08 16:18
    关注

    You created a binding for the my_event event. This error is complaining that you don't have a callback for the pusher:subscription_succeeded event. If you want to catch that and handle it, you need to create a binding.

    https://pusher.com/docs/client_api_guide/client_presence_channels#pusher-subscription-succeeded

    channel.bind('pusher:subscription_succeeded', function(members) {
        alert('successfully subscribed!');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料