Reputation: 173
I'm trying to learn how to work with events and pusher, I've started with something very simple
I am working with laravel 8 livewire.
From pusher to view it works fine, but when I call the event from the component I get the error :
https://flareapp.io/share/dmkzeG65#F77
View:
<div>
<div class="mt-20 col-span-2 editor mx-auto w-10/12 flex flex-col text-gray-800 border border-gray-300 p-4 shadow-lg max-w-2xl rounded">
<textarea id="mensaje" wire:model="mensaje" class="mt-4 rounded description bg-gray-100 sec p-3 h-20 border border-gray-300 outline-none" spellcheck="false" placeholder="Aqui dispones la oportunidad de argumentar tu opinión."></textarea>
<div class="buttons flex mt-2">
<div class="btn border border-gray-300 p-1 px-3 font-semibold cursor-pointer text-gray-500 ml-auto">
Cancel
</div>
<button wire:click="enviarMensaje" class="btn border border-indigo-500 p-1 px-3 font-semibold cursor-pointer text-gray-200 ml-2 bg-indigo-500" type="submit">
Comentar
</button>
</div>
@error('mensaje') <small class="text-red-600">{{$message}}</small> @enderror
</div>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('d1fc007f6e1d80963c33', {
cluster: 'eu'
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(JSON.stringify(data));
});
</script>
</div>
LIVEWIRE COMPONENT
<?php
namespace App\Http\Livewire;
use App\Events\Mensaje;
use Livewire\Component;
use App\Events\EnviarMensaje;
use App\Events\SendMessage;
class ChatForm extends Component
{
public $mensaje;
public function mount()
{
$this->mensaje = '';
}
public function enviarMensaje()
{
event(new SendMessage($this->mensaje));
}
public function render()
{
return view('livewire.chat-form');
}
}
EVENT
<?php
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class SendMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public function __construct($message)
{
$this->message = $message;
}
public function broadcastOn()
{
return ['my-channel'];
}
public function broadcastAs()
{
return 'my-event';
}
}
I look forward to your help. Thank you very much for your help.
Upvotes: 1
Views: 2406
Reputation: 4091
This error was resolved in the pusher-http-php library v5.0.1 and Laravel v8.29.0. https://github.com/pusher/pusher-http-php/issues/288
Alternatively you can use pusher-http-php v4.1
composer require pusher/pusher-php-server ^4.1
Upvotes: 3