不幸的是,我安装了laravel 5和socket.io,但在浏览器的控制台中我对监听器没有任何回答。
我尝试了网络上的所有技巧。很多人有同样的问题,但是我没有看到解决方案,或者对我来说这是不对的
bootstrap.js
import Echo from 'laravel-echo'
window.io = require('socket.io-client');
let e = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
})
e.channel('orders')
.listen('DashboardEvent', function(e) {
console.log('DashboardEvent', 'test') <- not listening in my console
})
路线
Route::get('/test',function (){
broadcast (new DashboardEvent('route'));
return 'broadcasted' ;
});
事件/仪表板事件
class DashboardEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $orders;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($orders)
{
$this->orders = $orders;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('orders');
}
vue.blade
<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>
<script src="{{ mix ('js/app.js') }}"defer></script>
laravelechoserver.json
"devMode": true,
"host": null,
"port": "6001",
"protocol": "redis",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": true,
"allowOrigin": "y",
"allowMethods": "GET, POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}