1.我在用laravle的laravle-echo配置的时候完的时候没有在console中看到输出的内容
-.下面的是我的我写的事件的代码
<?php
namespace App\Events;
use App\UserInput;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserInputSaveEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $body;
public function __construct(UserInput $input)
{
return $this->body = $input;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new Channel('server.created');
// return new PrivateChannel('user.' . $this->body->id);
}
public function broadcastAs()
{
return 'server.created';
}
public function broadcastWith()
{
return ['user_id' => $this->body];
}
}
路由的配置文件信息
Route::get('/show', function() {
return view('show');
});
Route::post('userInput', 'HomeController@userinput');
这个是我的laravel-echo-server.json的配置文件
{
"authHost": "http://localhost",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": ""
}
这是我的env的配置文件
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
我在控制台运行laravel-echo-serverd的控制台的提示信息的
我运行redis服务器的时候控制的提示信息是
在的我show.blade.php中的代码是
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Document</title>
</head>
<body>
<script src="{{asset('js/app.js')}}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
// var socket = io('http://localhost:3000');
// var socketId = Echo.socketId();
Echo.channel('server.created').listen('server.created', (e) => {
console.log('weqweq');
});
</script>
</body>
</html>
app.js中的文件信息是
import Echo from "laravel-echo";
window.Echo = new Echo({
broadcaster: 'socket.io',
host : 'http://localhost:6001'
});
已经解决了
这个问题是作用域错误了。。。。。。无语