我是Laravel广播的新手,目前正在使用5.4。我要更新帐户仪表板,当其他人创建新帖子时,我正在使用私人渠道,该仪表板按他们的兴趣包含相关帖子。我成功广播了另一个用户在当前登录的用户仪表板中发布的每个新帖子,我需要检查新帖子是否相关,如果不发布则进行广播。
我想我可以在内部BroadcastServiceProvider编写授权事件中的过滤来实现。
public function boot(){
Broadcast::routes();
Broadcast::channel('discovery.post', function ($user) {
return true;
});
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了有关可以与通道名称一起传递数据的文档,例如
Broadcast::channel('discovery.post.{postId}', function ($user, $postId) {
// get post category, tags, etc compare with user interest
return $isInterest;
});
Run Code Online (Sandbox Code Playgroud)
但是这种方法也必须在laravel Echo中传递新的帖子ID
window.Echo.private('discovery.post.{how-i-get-this-id?}')
.listen('NewPostDashboard', (data) => {
// add new update to dom
});
Run Code Online (Sandbox Code Playgroud)
我如何解决此问题,我想保留我的频道名称discovery.post,我只想发送给具有相关兴趣的用户,我需要Post实例来检查登录的用户是否对此帖子感兴趣。
如果我的问题不清楚,请让我投票。谢谢。
大家好,我使用 Laravel Echo 和 SocketIO 而没有仅使用 Vue 的 jquery,但是我在这里的私人频道有问题我向您展示我有两个事件正常和私人频道正常频道(我的事件 HolaEvent 的 todocanales)在我午餐时工作正常事件
use App\Events\HolaEvent;
Route::get('/fire', function () {
$data = [
'type' => 'erhelloror',
'title' => 'new article has been published',
'message' => 'check it out',
'url' => 'url',
];
event(new HolaEvent($data));
return 'done';
});
Run Code Online (Sandbox Code Playgroud)
并在我的 Laravel 回声服务器控制台中向我展示:
[03:04:47] - 5s6214Rlv51NUgnDAAAA joined channel: todocanales
[03:04:48] - QpxGvCjmaezgHn3aAAAB authenticated for: private-like-received.2jzwpAg1
[03:04:48] - QpxGvCjmaezgHn3aAAAB joined channel: private-like-received.2jzwpAg1
Channel: todocanales
Event: App\Events\HolaEvent
CHANNEL todocanales
Run Code Online (Sandbox Code Playgroud)
在浏览器控制台中,我得到
~~~对象{数据:对象,套接字:空}~~~
一切都很完美,但是使用 privateChannel 我遇到了问题 Laravel Echo 服务器没有做任何事情,并且我的用户控制台上没有任何记录,当然,我已经运行 …
我正在尝试使用专用通道对laravel回声进行身份验证。每当我收到“无法通过private-basket_details.1进行身份验证”时。“ basket_details”是通道名称,1是参数。
当我使用公共频道时,一切正常。因此,我认为auth部分存在一些问题。
这是我的错误日志
? [14:42:55] - 5eKrT28nX7uLHEkLAAAG could not be authenticated to private-basket_details.1
{
"message": "",
"exception": "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",
"file": "/var/www/html/Laravel/uneek_clothing/trunk/public_html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 179,
"trace": [
{
"file": "/var/www/html/Laravel/uneek_clothing/trunk/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 612,
"function": "match",
"class": "Illuminate\Routing\RouteCollection",
"type": "->"
},
{
"file": "/var/www/html/Laravel/uneek_clothing/trunk/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 601,
"function": "findRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
Run Code Online (Sandbox Code Playgroud)
这是我的事件文件。
<?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;
use App\Basket;
use App\User;
class UpdateWebOrderDetailsToBasket implements ShouldBroadcastNow
{
use …Run Code Online (Sandbox Code Playgroud) npm -v 6.4.1 nvm --version 0.33.11
当我安装laravel-echo(在ubuntu16.04中)
npm i --save socket.io-client
Run Code Online (Sandbox Code Playgroud)
我收到了错误警告
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN img-loader@3.0.0 requires a peer of imagemin@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ socket.io-client@2.1.1
added 26 packages from 21 contributors and audited …Run Code Online (Sandbox Code Playgroud) 我正在使用 Pusher 和 Laravel Echo 为我的应用程序中的某些区域创建在线频道。我所有的前端路由都是使用 Vue Router 完成的。
在路由之间切换时,Vue router 会根据我的路由设置加载某些组件。效果很好,但是,Pusher 不会自动断开用户与这些频道的连接。只有当我运行整页刷新时才会发生这种情况,这不是我想要的。
在我的组件中,加入 Pusher 频道的 js 代码在里面mounted,像这样:
data() {
return {
users: [],
}
},
mounted() {
Echo.join('transaction.' + this.tid)
.here(users => {
this.users = users;
}
})
.joining(user => {
this.users.push(user);
})
.leaving(user => {
this.users.splice(this.users.indexOf(user), 1);
});
},
methods: {
// ...
},
Run Code Online (Sandbox Code Playgroud)
如何使用 Vue Router 路由断开用户与频道的连接,而不刷新页面?
谢谢你。
我在文档中或通过搜索找不到此内容,也许有人提供了一些提示。我正在尝试检查后端的状态通道上有多少个连接。
我可以像这样用Echo在前端检查罚款:
Echo.join('chat')
.here((users) => {
// users.length is the proper count of connections
})
Run Code Online (Sandbox Code Playgroud)
但是有什么办法可以让我获得相同数量的连接,但是在Laravel中某个地方的后端代码中?
祝你今天过得愉快 !
我有一个问题:我设置了 Laravel Echo & Pusher,但遇到了这个错误,不知道如何解决 :(
我检查了我的 app-key、app-cluster,但都是正确的。
有人能帮我吗?
应用程序.js
const app = new Vue({
el: '#app',
data: {
messages: []
},
methods:{
addMessage(message){
this.messages.push(message);
axios.post('/messages', message).then(response => {
console.log(response);
});
}
},
created(){
axios.get('/messages').then(response => {
this.messages = response.data;
});
Echo.channel('chatroom')
.listen('MessageEvent', (e) => {
console.log(e);
});
}
})
Run Code Online (Sandbox Code Playgroud)
引导程序.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: '************',
cluster: 'ap1',
encrypted: false
});
Run Code Online (Sandbox Code Playgroud)
消息事件
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message, …Run Code Online (Sandbox Code Playgroud) 有谁知道如何处理 Laravel Echo 上的连接、断开、重新连接等?
我正在使用 VueJS 顺便说一句
我开发了一个仪表板,它通过自定义事件获取实时通知。我想实现的是能够在频道之间切换。我使用 Vue(x) 作为前端。
created() {
this.setTeam(this.$router.currentRoute.name);
this.clearFastlanes();
this.getSprintInfo('getSprintInfo');
window.Echo.channel(this.getTeam)
.listen('.jira.issue', this.jiraIssue)
.listen('.jira.fastlane', this.jiraFastlane);
},
Run Code Online (Sandbox Code Playgroud)
这是我订阅自定义事件的主要组件。唯一的问题是,这个组件也被另一个团队使用。所以我想将我的频道更改为当前团队(离开当前频道并加入新团队的频道)。我真的无法在互联网上找到如何做到这一点。
这是我的连接方式:
window.Echo = new Echo({
broadcaster: 'pusher',
key: '29564c255fe1dae3654b',
cluster: 'eu',
encrypted: true,
});
Run Code Online (Sandbox Code Playgroud)
所以基本上我想问 laravel echo 我当前是否已连接,如果是,请离开频道并连接到新团队。
有没有人知道如何实现这一目标?
我正在用 Laravel 开发实时应用程序。由于我不想使用 Pusher,我正在尝试使用Laravel Echo Server、Redis 和 Socket.IO使 websockets 工作。但是,我对这个堆栈有问题。客户端(浏览器)似乎无法从事件接收数据。我还在前端使用 Intertia 和 Vue。还值得注意的是,我使用Laragon作为我的本地开发环境。
我的.env,有些被省略了:
APP_URL=http://malbe.test
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
MIX_APP_URL="${APP_URL}"
Run Code Online (Sandbox Code Playgroud)
我的laravel-echo-server.json:
APP_URL=http://malbe.test
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
MIX_APP_URL="${APP_URL}"
Run Code Online (Sandbox Code Playgroud)
我的 redis 配置database.php:注意:我使用predis是因为phpredis即使我在 PHP 扩展上安装了 dll,我似乎也无法工作。
{
"authHost": "http://malbe.test",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "omitted",
"key": "omitted"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": …Run Code Online (Sandbox Code Playgroud) laravel-echo ×10
laravel ×7
php ×4
pusher ×4
socket.io ×3
broadcast ×2
javascript ×2
laravel-5 ×2
vue.js ×2
vuejs2 ×2
imagemin ×1
laravel-5.4 ×1
laravel-8 ×1
npm-install ×1
redis ×1
sockets ×1
ubuntu-16.04 ×1