laravel - Laravel 与 Vuejs 和 Redis , laravel-echo , socketio-client
问题描述
我正在将 laravel 8 与 vuejs 3 (SPA) 一起使用,并希望通过 redis、laravel echo 和 socketio 客户端实时使用应用程序。
如果我没记错 laravel server <-> redis server <-> laravel-sech-server<-> socketio-client-server,流程是这样的。
但是当我运行 laravel-eacho-server start 它给出了这个错误我认为 redis 配置文件有问题。 这是它显示的错误,但控制台 应用程序/事件文件中没有错误我有 TestEvent
<?php
namespace App\Events;
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;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class TestEvent implements ShouldBroadcastNow
{
use InteractsWithSockets, SerializesModels;
public function __construct()
{
}
public function broadcastAs()
{
return 'UserEvent';
}
public function broadcastWith()
{
return ['title'=>'some notification'];
}
public function broadcastOn()
{
return new Channel('test');
}
}
在主 vuejs 文件中,它是 root 的子级。在创造它的功能
created(){
Echo.channel('test')
.listen('TestEvent', e => {
console.log(e)
});
},
在 bootstrap.js 文件中(laravel-echo 服务器和 socketio-client 服务器之间的连接~right)
import Echo from "laravel-echo"
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001' // this is laravel-echo-server host
});
在 .evn 文件中
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
QUEUE_DRIVER=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
LARAVEL_ECHO_PORT=6001
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
最后是 laravel-echo-server.json
{
"authHost": "http://localhost",
"authEndpoint": "/api/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
我也在运行 redis 服务器 redis-server.exe
如果可能的话,如果有任何关于此事的材料可以分享,我们将不胜感激。它也可以运行
laravel 服务器 <-> redis 服务器 <-> nodejs-server (socketio-server) <-> socketio-client-server. (找不到这种流程的任何示例)。
解决方案
推荐阅读
- node.js - 如何根据来自 mongodb 的 2 个文档打印多级列表?
- python - AttributeError:“NoneType”对象没有属性“find_all”Beautifulsoup
- python - 指定错误类型时如何打印异常?
- php - php-fpm 访问日志应包含从 php 应用程序设置的自定义变量
- c# - 如何反序列化一个json数据数组
- django - 如何像这样获取 API 数据。道具?
- c# - C#如何在位图中保留1个颜色范围?
- react-native - Expo React Native - 使用相同的代码库部署多个应用程序
- r - 有没有办法在 R 的固定效应模型中同时包含 PCSE 和 Prais-Winsten 校正(类似于 Stata 中的 xtpcse 函数)?
- python-3.x - 使用数据框值作为列表的索引