我正在尝试创建在线聊天,首先我尝试吸引在线用户。 我使用了predis,laravel echo,yarn,socket.io-client和laravel-echo-server。 这是我的app.js代码:
require('./bootstrap');
import Echo from "laravel-echo"
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
console.log("ok ");
window.Echo.join('online')
.here((users) => {
console.log('ok here');
})
.joining((user) => {
console.log(user.name);
})
.leaving((user) => {
console.log(user.name);
});
我的频道:
Broadcast::channel('online', function ($user) {
return $user;
});
运行我的浏览器后: here
laravel回显服务器: here
我在{p>中添加了App\Providers\BroadcastServiceProvider::class,
config / app.php 并更改 .env BROADCAST_DRIVER = redis
答案 0 :(得分:1)
当您的Laravel应用程序位于http://localhost
上时,您的回显服务器似乎正在尝试针对http://localhost:8000
进行身份验证
您可能想将authHost
配置文件中的http://localhost:8000
配置设置为laravel-echo-server.json