0

我在 laravel websockets 中使用不带 laravel-echo 的 pusher sdk 我能够订阅频道但监听事件功能不起作用 下面是我用于前端的代码

<script>var module = { };</script>
<script src="https://js.pusher.com/4.3/pusher.min.js"></script>
<script>
    var pusher = new Pusher("123123", {
        wsHost: window.location.hostname,
        wsPort: 6001,
        disableStats: true,
    });
    var channel = pusher.subscribe('DemoChannel');
    channel.bind('DemoChannel', function(data) {
        alert('An event was triggered with message: ' + data.message);
    });
    channel.bind('WebsocketDemoEvent', (data) => {
           console.log(data);
        });

</script>

在 laravel websockets 管理面板上,这一切都很好 在此处输入图像描述

4

0 回答 0