I want to use pusher for realtime chat and it works properly with public channel but when I use private channel I got this error :
pusher.js:1333 Cross-Origin Read Blocking (CORB) blocked cross-origin response http://20.30.0.236:8000/login with MIME type text/html
Run Code Online (Sandbox Code Playgroud)
this is laravel code :
Event :
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $user;
public $message;
public function __construct(User $user, Message $message)
{
$this->user = $user;
$this->message = $message;
} …Run Code Online (Sandbox Code Playgroud) 我想触发一个推送器专用通道事件,而我的服务器端语言是laravel,我检查了很多资源,但是我没有找到涵盖服务器端和前端的全面方法。最后,我在第一个解决方案中步 :
export const SendChat = () => {
try {
var pusher = new Pusher('YOUR_APP_KEY', {
cluster: 'ap2',
forceTLS: true,
authTransport: 'jsonp',
authEndpoint: `${baseUrl}pusher/auth`,
});
var channel = pusher.subscribe('private-channel');
channel.bind('pusher:subscription_succeeded', function() {
var triggered = channel.trigger('client-EVENT_NAME', { 'message': 'Hi ....' });
console.log(triggered)
});
} catch (error) {
console.error(error);
}
}
Run Code Online (Sandbox Code Playgroud)
叫它到某个地方
<Button onClick={this.props.SendChat} waves='light' >Send</Button>
Run Code Online (Sandbox Code Playgroud)
您必须在推送器帐户设置中启用客户端事件
login to your pusher account -> select the channel ->App Settings -> select Enable client events -> update
Run Code Online (Sandbox Code Playgroud)
添加您的应用程序密钥,通道名称和事件名称之后,我们需要在服务器端进行授权,这是示例laravel代码,首先在web.php中添加此路由
Route::get('pusher/auth', 'PusherController@pusherAuth');
Run Code Online (Sandbox Code Playgroud)
使PusherController.php像这样:
public …Run Code Online (Sandbox Code Playgroud)