laravel-echo-server不广播事件

时间:2019-02-28 10:21:46

标签: laravel websocket socket.io laravel-echo

我遵循了有关使用Redis作为广播驱动程序配置laravel-echo-server的文档。

我设法加入了我创建的频道,但是在命令DEBUG=* laravel-echo-server start的输出中我得到了:

Server ready!

  engine intercepting request for path "/socket.io/" +0ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MapZmuQ" +1ms
  engine handshaking client "qu2wNp4IrLre3oJeAAAA" +7ms
  engine:socket sending packet "open" ({"sid":"qu2wNp4IrLre3oJeAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}) +0ms
  engine:socket sending packet "message" (0) +1ms
  engine:polling setting request +0ms
  engine:socket flushing buffer to transport +1ms
  engine:polling writing "96:0{"sid":"qu2wNp4IrLre3oJeAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40" +2ms
  engine:socket executing batch send callback +9ms
  socket.io:server incoming connection with id qu2wNp4IrLre3oJeAAAA +492ms
  socket.io:client connecting to namespace / +0ms
  socket.io:namespace adding socket to nsp / +0ms
  socket.io:socket socket connected - writing packet +0ms
  socket.io:socket joining room qu2wNp4IrLre3oJeAAAA +0ms
  socket.io:socket packet already sent in initial handshake +0ms
  socket.io:socket joined room qu2wNp4IrLre3oJeAAAA +1ms
  engine intercepting request for path "/socket.io/" +206ms
  engine handling "POST" http request "/socket.io/?EIO=3&transport=polling&t=MapZm-U&sid=qu2wNp4IrLre3oJeAAAA" +1ms
  engine setting new request for existing client +0ms
  engine:polling received "121:42["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]" +193ms
  engine:socket packet +186ms
  socket.io-parser decoded 2["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] as {"type":2,"nsp":"/","data":["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]} +690ms
  socket.io:socket got packet {"type":2,"nsp":"/","data":["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}]} +183ms
  socket.io:socket emitting event ["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] +0ms
  socket.io:socket dispatching an event ["subscribe",{"channel":"issueUpdates","auth":{"headers":{"X-CSRF-TOKEN":"GyZ4Z0igQp4gaMSiYgFrmXKOCsMX0zXnvOAxUZrr"}}}] +0ms
  socket.io:socket joining room issueUpdates +1ms
[10:03:27] - qu2wNp4IrLre3oJeAAAA joined channel: issueUpdates
  socket.io:socket joined room issueUpdates +6ms
  engine intercepting request for path "/socket.io/" +83ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MapZm-U.0&sid=qu2wNp4IrLre3oJeAAAA" +0ms
  engine setting new request for existing client +1ms
  engine:polling setting request +83ms
  engine upgrading existing transport +67ms
  engine:socket might upgrade socket transport from "polling" to "websocket" +149ms
  engine:ws received "2probe" +0ms
  engine:ws writing "3probe" +1ms
  engine:socket writing a noop packet to polling for fast upgrade +170ms
  engine:polling writing "1:6" +238ms
  engine:ws received "5" +185ms
  engine:socket got upgrade packet - upgrading +83ms
  engine:polling closing +84ms
  engine:polling transport discarded - closing right away +0ms
  engine:ws received "2" +25s
  engine:socket packet +25s
  engine:socket got ping +0ms
  engine:socket sending packet "pong" (undefined) +0ms
  engine:socket flushing buffer to transport +0ms
  engine:ws writing "3" +1ms

我可以看到它接收到ping并发送了pong,但是我不知道为什么我的 event(new IssueCreated($issue))永远不要扔掉频道并进行广播。

我的前端代码:

if (io !== 'undefined') {
    console.log('subscribing..');
    // Issue created code
    Echo.channel('issueUpdates')
        .listen('IssueCreated', (e) => {
            console.log('new issue');
            console.log(e);
        });
}

我知道我已成功加入会议室,但是当我触发该事件时,它在laravel-echo-server日志或控制台中都没有显示

我该怎么做调试?如果您需要更多信息,请告诉我。

1 个答案:

答案 0 :(得分:0)

好,对于面临相同问题的人:

我的问题出在队列侦听器的配置中,我使用超级用户使进程保持活动状态,并且我没有使用php artisan queue:listen正确配置command属性

请记住,您必须同时运行两件事,laravel-echo-server startphp artisan queue:listen

如果您只运行laravel-echo-server并想知道为什么事件没有触发,请按照this link来配置laravel队列。