我已经在我的Laravel应用程序中配置了Larvel Echo Server。我需要将Laravel部署在任何其他位置上,直接使用外部Socket.io客户端库。我已经成功地将Socket Client与Echo Server连接了,但是我无法在Client Screen上打印有效负载/ console.log(数据)。请帮忙!
这是我的客户端测试脚本:
<script src="http://localhost:6001/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function () {
var options = {
auth: {
headers: { 'Authorization': 'Bearer eyJ0eXAiOi' }
}
}
var socket = io('http://localhost:6001', options);
socket.emit('subscribe', {
channel: 'auction.1',
auth: options.auth
}).on('App\Events\Bid', function (channel, data) {
console.log(data)
});
});
</script>
这是我的活动代码:
class Bid implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $bid;
public function __construct($bid)
{
$this->bid = $bid;
}
public function broadcastOn()
{
return new Channel('auction.1');
}
public function broadcastWith()
{
return "Test";
}
}
这是我的频道路由代码:
<?php
Broadcast::channel('auction.{auctionId}', function ($user, $auctionId) {
return true;
});
Laravel Echo Server事件侦听: