推动器接收数据,但在回声回调功能(Laravel)中未接收数据
我正在使用Laravel和Pusher进行应用内通知。我所做的是在推动器中创建帐户,然后进行这样的混音。
Bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true
});
Events/comment.php
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class Comment implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $username;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($username)
{
//
$this->username = $username;
$this->message = "{$username} liked your status";
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('channel-name');
return new Channel('comments-channal');
}
}
script.js
$(function() {
const Http = window.axios;
const Echo = window.Echo;
let channal = Echo.channel('comments-channel');
channal.listen('Comment', function(data) {
alert(data);
console.log(data)
})
})
在控制器中
Comment::dispatch('fatima');
,然后我在Pusher调试控制台中收到了API消息,但是在我的控制台中,我得到了此
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"comments-channel"}
Pusher : No callbacks on comments-channel for pusher:subscription_succeeded
fyi,我将.env .env
.env for groadcast_driver double sheck = Pusher
如果有任何帮助,我将非常感谢。
I am using laravel and pusher for in-app notification . What I did is create account in the pusher and do the congifration like this.
bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true
});
Events/Comment.php
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class Comment implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $username;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($username)
{
//
$this->username = $username;
$this->message = "{$username} liked your status";
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('channel-name');
return new Channel('comments-channal');
}
}
script.js
$(function() {
const Http = window.axios;
const Echo = window.Echo;
let channal = Echo.channel('comments-channel');
channal.listen('Comment', function(data) {
alert(data);
console.log(data)
})
})
in the controller
Comment::dispatch('fatima');
Then I got the API message in Pusher debug console but in my console I got this
Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"comments-channel"}
Pusher : No callbacks on comments-channel for pusher:subscription_succeeded
FYI I double sheck the .env
for BROADCAST_DRIVER=pusher
If there is any help I will be very thankful .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的评论广播课上,您可以使用此功能格式化数据:
To your Comment broadcast Class You could format your data using this function: