broadcasting/auth 500 pusher in laravel - laravel

In my app i using from pusher to send notification for typists.but i giving this error:
Couldn't get auth info from your webapp : 500
javascript codes of pusher placed in footer:
<script src="https://js.pusher.com/4.1/pusher.min.js"></script>
<script>
Pusher.logToConsole = true;
var pusher = new Pusher('xxxxxxxxxxxxxxxxx', {
cluster: 'ap2',
encrypted: true,
authEndpoint: "/broadcasting/auth",
auth: {
params: {
'X-CSRF-Token': $('meta[name="csrf-token"]')
.attr('content')
}
}
});
var channel = pusher.subscribe(
'private-App.Typist.' + {{$typistId}}
);
channel.bind('NewTypeOrder', function(data) {
alert('hi');
});
in channels.php
Broadcast::channel('App.Typist.{id}', function (Typist $typist, $id) {
return true;
});
and in Events/EventTypeOrder.php
class NewTypeOrder implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $typist;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(Typist $typist)
{
$this->typist = $typist;
}
/**
* Get the channels the event should broadcast on.
*
* #return Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('App.Typist.' . $this->typist->id);
}
}
my typists table is quite from users table and laravel authentication for typist not used because laravel authentication just used for users only.
in laravel.log
[2018-07-22 20:27:38] local.ERROR: ErrorException: Key file
"file://C:\xampp\htdocs\samane_typax_5.4\storage\oauth-public.key"
permissions are not correct, should be 600 or 660 instead of 666 in
C:\xampp\htdocs\samane_typax_5.4\vendor\league\oauth2-
server\src\CryptKey.php:57
Stack trace:
Now what can i do for this issue?

On the commandline, type: php artisan tinker
Then paste the following:
chmod(storage_path('oauth-public.key'), 0660)
This should set the right file permissions, the error should vanish/change once enter is pressed :)

Related

Pusher returns no data with laravel 8 event

I'm using laravel 8, and I'm having a hard time getting the data from the event using pusher. I'm want to broadcast the event, i want to receive the data when the data is successfully inserted in the database. hope someone can help me with this. here are my codes
config/app.php
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class
Events\Chat.php
class Chat implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* #return void
*/
public $data;
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('chat');
}
public function broadcastAs()
{
return 'get-chat';
}
}
chat.blade.php
var pusher = new Pusher('dec355f1ff67f51f5784', {
cluster: 'ap1',
forceTLS: true
});
Pusher.logToConsole = true;
$('.chat-send').click(function(){
var msg = $('.chat-msg').val();
$.ajax({
url: add_url,
type: 'POST',
data: {'msg' : msg},
dataType: 'json',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success: function(data) {
if (data.msg == 'success') {
var channel = pusher.subscribe('chat');
channel.bind('pusher:subscription_succeeded', function(data) {
//alert('successfully subscribed!');
console.log(data);
});
channel.bind('get-chat', function(data) {
//console.log(JSON.stringify(data));
alert(data);
});
}
},
error : function(request, status, error) {
//swal("Oops!", "Seems like there is an error. Please try again", "error");
}
});
});
MessageController
public function create(Request $request, Messages $messages)
{
$request->merge([
'teacher_id' => 2,
'student_id' => 1,
'message' => 'test msg'
]);
$data = $messages::create($request->all());
if ($data->exists) {
$msg = 'success';
$cars = ['hey', 'yow'];
broadcast(new Chat($cars));
}
return json_encode(['msg'=>$msg]);
}
This is what I get in the pusher.log
Pusher : : ["Event sent",{"event":"pusher:subscribe","data":{"auth":"","channel":"chat"}}]
Pusher : : ["Event recd",{"event":"pusher_internal:subscription_succeeded","channel":"chat","data":{}}]

Laravel pusher/echo getting broadcast error 500 and 403

Hello I'm trying to make chat system for my app but I'm having problem making pusher and echo work. When I open my Chat between 2 people it does not update in real time and I have to refresh the page in order to get the updated stuff like messages and such. In console I'm getting these 2 errors
POST http://localhost/broadcasting/auth 403 (Forbidden)
POST http://localhost/broadcasting/auth 500 (Internal Server Error)
bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true,
});
ChatBroadcast.php
class ChatBroadcast implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $ticket;
/**
* Create a new event instance.
*
* #param $ticket
*/
public function __construct(Ticket $ticket)
{
$this->ticket = $ticket;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('tickets_channel.' . $this->ticket->id);
}
public function broadcastWith(){
$messages = Message::all()->where('ticket_id','=',$this->ticket->id)->sortBy('created_at');
return [
'ticket' => $this->ticket,
'messages' => $messages
];
}
}
channels.php
use App\Ticket;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Broadcast;
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('tickets_channel.{ticketID}', function ($user, $ticketID) {
Auth::check();
$ticket = Ticket::all()->where('id', '=', $ticketID)->first();
return $ticketID == $ticket->id;
});
VueComponent
mounted() {
Echo.private('tickets_channel.${ticketID}')
.listen('ChatBroadcast', (e) => {
console.log(e);
this.messagesMutable = e.messages;
this.state = e.ticket.isOpened;
});
},
This is my log for 500 error
[2020-09-08 09:25:24] local.ERROR: Invalid channel name private-tickets_channel.${ticketID} {"userId":11,"exception":"[object] (Pusher\\PusherException(code: 0): Invalid channel name private-tickets_channel.${ticketID} at /Users/miroslavjesensky/Documents/Blog/vendor/pusher/pusher-php-server/src/Pusher.php:282)
-EDIT-
I have managed to fix the 500 error by changing VueComponent code to this
mounted() {
let id = this.ticket.id;
Echo.private('tickets_channel' + id)
.listen('ChatBroadcast', (e) => {
this.messagesMutable = e.messages;
this.state = e.ticket.isOpened;
});
},
Turns out the problem was with another VueComponent I am using with the first one. After fixing the listening part of echo there aswell all works as it should

Laravel5.8 Pusher Event 500 İnternal Server Error

I tring add a chat extension to my web site , watched very much video lesson, Laravel and Pusher using user. Normally website is working
broadcasting(new MyEvent('my-event'));
but if I add line -before return line- , giving 500 Internal Server Error.
sended message is saving to DB but not return value...
Please help me
My ChatEvent.php
use App\Chat;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Broadcasting\PresenceChannel;
....
class ChatEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $chat;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct(Chat $chat)
{
$this->chat = $chat;
}
/**
* Get the channels the event should broadcast on.
*
* #return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PresenceChannel('chat');
}
}
My ChatController.php
use Illuminate\Http\Request;
use App\Chat;
use App\Events\ChatEvent;
class ChatController extends Controller
{
public function __construct(){
$this->middleware('auth');
}
public function index(){
return view('chat.chat');
}
public function fetchAllMessages(){
return Chat::with('user')->get();
}
public function sendMessage(Request $request){
$chat = auth()->user()->messages()->create([
'message' => $request->message
]);
broadcast(new ChatEvent($chat->load('user')))->toOthers();
return ['status' => 'success'];
}
}
VueJs Post And Get codes
<script>
export default {
methods: {
fetchMessages(){
axios.get('messages').then(response =>{
this.messages = response.data;
})
},
sendMessage(){
this.messages.push({
user: this.user,
message: this.newMessage
});
axios.post('messages',{message: this.newMessage});
this.newMessage='';
},
}
}
</script>
Routes and Channels
Route::get('/chats','ChatController#index');
Route::get('/messages','ChatController#fetchAllMessages');
Route::post('/messages','ChatController#sendMessage');
Broadcast::channel('chat', function ($user) {
return $user;
});
Pusher's AppKey,Secret,ID and Cluster OK,
Broadcaster-Driver: pusher Everywhere

localhost didn't send any data in laravel 5.2(socket.io )

I've already installed node.js , socket.io, predis,ioredis in laravel 5.2
When i run
node socket.js
in gitbash ,nothing is returned.
at localhost:3000, first it loads for sometime then localhost didn't send any data error is displayed.(done should be displayed)
socket.js file: http://laravel.io/bin/OeGxv
routes file: http://laravel.io/bin/d9PvY
package.json: http://laravel.io/bin/Kk5mB
I dont think can help you, but I successfull using redis with Laravel 5.1 and this is code.
composer.json
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"pusher/pusher-php-server": "^2.2",
"predis/predis": "^1.1"
routes.php
Route::get('/setredis',[
'as'=>'set.redis',
'uses'=>'TestController#index'
]);
Route::get('/getredis',[
'as'=>'get.redis',
'uses'=>'TestController#create'
]);
Route::get('fire', function () {
// this fires the event
event(new \App\Events\EventName());
return "event fired";
});
Route::get('test', function () {
// this checks for the event
return view('test');
});
TestController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Redis;
class TestController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
Redis::set('name', 'Taylor');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$user = Redis::get('name');
echo $user;
}
test.blade.php
#extends('master')
#section('content')
<p id="power">0</p>
#stop
#section('footer')
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket = io('http://testlaravel5.com:3000');
socket.on("test-channel", function(message){
console.log(message);
// increase the power everytime we load test route
$('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
});
</script>
#stop
socket.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel', function(err, count) {
});
redis.on('message', function(channel, message) {
console.log('Message Recieved: ' + message);
message = JSON.parse(message);
io.emit(channel, message.data);
});
http.listen(3000, function(){
console.log('Listening on Port 3000');
});
EventName.php
<?php
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class EventName extends Event implements ShouldBroadcast
{
use SerializesModels;
public $data;
/**
* Create a new event instance.
*
* #return void
*/
public function __construct()
{
$this->data = array(
'power'=> '10'
);
}
/**
* Get the channels the event should be broadcast on.
*
* #return array
*/
public function broadcastOn()
{
return ['test-channel'];
}
}
I hope help you!

Event broadcast is not working when queueis use in our project

I was broadcasting my event with help of pusher,it's worked fine but when i used queue implementation then pusher haven't receive any broadcast or may be event is not broadcasting.I'm not understand what the issue is.Code is given below please help me
Controller function
public function index()
{ $this->user_id=2;
Event::fire(new UpdateDeviceStatus($this->user_id));
}
Event file
class UpdateDeviceStatus extends Event implements ShouldBroadcast
{
use SerializesModels;
/**
* Create a new event instance.
*
* #return void
*/
public $devices;
public function __construct($id)
{
$this->devices=Device::with('units')->where('user_id',$id)->get();
}
/**
* Get the channels the event should be broadcast on.
*
* #return array
*/
public function broadcastOn()
{
return ['update-status'];
}
}
js file
Pusher.logToConsole = true;
var pusher = new Pusher('key', {
encrypted: true
});
var channel = pusher.subscribe('update-status');
channel.bind('App\\Events\\UpdateDeviceStatus', function (data) {
console.log(data);
});
I had the same issue and realised that I just forgot to listen to the queue: php artisan queue:listen redis

Resources