Hello i am using laravel broadcasting
and pusher
to send some info.
I can successfully send message to pusher but cant receive that.
Here is my codes, Please help me guys:(
App.js
require('./bootstrap');
window.Vue = require('vue');
const app = new Vue({
el: "#app",
created() {
Echo.private('gameRoom')
.listen('RequestsEvent', (e) => {
console.log(e);
});
}
});
Bootstrap.js
window._ = require('lodash');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
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,
forceTLS: true
});
RequestsEvent.php
class RequestsEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $type;
public $room_manager;
/**
* Create a new event instance.
*
* @param $type
* @param $room_manager
*/
public function __construct($type, $room_manager)
{
$this->type = $type;
$this->room_manager = $room_manager;
}
/**
* Get the channels the event should broadcast on.
*
* @return PrivateChannel
*/
public function broadcastOn()
{
return new PrivateChannel('gameRoom');
}
}
Channels.php
Broadcast::channel('gameRoom', function () {
return true;
});
Html :
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Listen</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="{{ asset('css/app.css') }}"/>
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</body>
</html>
I already installed pusher
and laravel echo
and I have following things in my console
:
Download the Vue Devtools extension for a better development experience: https://github.com/vuejs/vue-devtools app.js:38040
You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html
It was about Vue
. I run npm install vue
in cmd although i did that and every thing went ok.