Skip to content

Commit decae31

Browse files
author
Firas Jerbi
committed
configuring pusher
1 parent 635d4fd commit decae31

File tree

23 files changed

+11433
-381
lines changed

23 files changed

+11433
-381
lines changed

app/Events/ChatEvent.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace App\Events;
3+
use App\User;
4+
use Illuminate\Broadcasting\Channel;
5+
use Illuminate\Broadcasting\InteractsWithSockets;
6+
use Illuminate\Broadcasting\PresenceChannel;
7+
use Illuminate\Broadcasting\PrivateChannel;
8+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
9+
use Illuminate\Foundation\Events\Dispatchable;
10+
use Illuminate\Queue\SerializesModels;
11+
class ChatEvent implements ShouldBroadcast
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
public $message;
15+
public $user;
16+
/**
17+
* Create a new event instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct($message,User $user)
22+
{
23+
$this->message = $message;
24+
$this->user = $user->name;
25+
$this->dontBroadcastToCurrentUser();
26+
}
27+
/**
28+
* Get the channels the event should broadcast on.
29+
*
30+
* @return Channel|array
31+
*/
32+
public function broadcastOn()
33+
{
34+
return new PrivateChannel('chat');
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Events\ChatEvent;
6+
use App\User;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Auth;
9+
10+
class ChatController extends Controller
11+
{
12+
public function chat(){
13+
return view('chat');
14+
}
15+
16+
public function send(request $request){
17+
return $request->all();
18+
$user= User::find(Auth::id());
19+
event(new ChatEvent($request->message, $user));
20+
}
21+
22+
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class HomeController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
$this->middleware('auth');
17+
}
18+
19+
/**
20+
* Show the application dashboard.
21+
*
22+
* @return \Illuminate\Http\Response
23+
*/
24+
public function index()
25+
{
26+
return view('home');
27+
}
28+
}

app/Listeners/ChatListener.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Events\ChatEvent;
6+
use Illuminate\Queue\InteractsWithQueue;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
9+
class ChatListener
10+
{
11+
/**
12+
* Create the event listener.
13+
*
14+
* @return void
15+
*/
16+
public function __construct()
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Handle the event.
23+
*
24+
* @param ChatEvent $event
25+
* @return void
26+
*/
27+
public function handle(ChatEvent $event)
28+
{
29+
//
30+
}
31+
}

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace App\Providers;
44

55
use Illuminate\Support\ServiceProvider;
6-
6+
use Illuminate\Support\Facades\Schema;
77
class AppServiceProvider extends ServiceProvider
88
{
99
/**
@@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider
1313
*/
1414
public function boot()
1515
{
16-
//
16+
Schema::defaultStringLength(191);
1717
}
1818

1919
/**

app/Providers/EventServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class EventServiceProvider extends ServiceProvider
1313
* @var array
1414
*/
1515
protected $listen = [
16-
'App\Events\Event' => [
17-
'App\Listeners\EventListener',
16+
'App\Events\ChatEvent' => [
17+
'App\Listeners\ChatListener',
1818
],
1919
];
2020

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"php": ">=7.0.0",
99
"fideloper/proxy": "~3.3",
1010
"laravel/framework": "5.5.*",
11-
"laravel/tinker": "~1.0"
11+
"laravel/tinker": "~1.0",
12+
"pusher/pusher-php-server": "~3.0"
1213
},
1314
"require-dev": {
1415
"filp/whoops": "~2.0",

composer.lock

Lines changed: 137 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
*/
174174
App\Providers\AppServiceProvider::class,
175175
App\Providers\AuthServiceProvider::class,
176-
// App\Providers\BroadcastServiceProvider::class,
176+
App\Providers\BroadcastServiceProvider::class,
177177
App\Providers\EventServiceProvider::class,
178178
App\Providers\RouteServiceProvider::class,
179179

config/broadcasting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
'secret' => env('PUSHER_APP_SECRET'),
3737
'app_id' => env('PUSHER_APP_ID'),
3838
'options' => [
39-
'cluster' => env('PUSHER_APP_CLUSTER'),
40-
'encrypted' => true,
39+
'cluster' => 'eu',
40+
'encrypted' => true
4141
],
4242
],
4343

0 commit comments

Comments
 (0)