Skip to content

Commit 205848b

Browse files
Merge pull request #1 from tekno-HMTC/make-event
Make event
2 parents 7175a2c + c793ce7 commit 205848b

11 files changed

+553
-70
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Homestead.json
99
Homestead.yaml
1010
npm-debug.log
1111
yarn-error.log
12+
/.idea

.idea/workspace.xml

+253-66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Events/RoomStart.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Room;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Broadcasting\PrivateChannel;
9+
use Illuminate\Broadcasting\PresenceChannel;
10+
use Illuminate\Foundation\Events\Dispatchable;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
12+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
13+
14+
class RoomStart implements ShouldBroadcast
15+
{
16+
use Dispatchable, InteractsWithSockets, SerializesModels;
17+
18+
/**
19+
* Create a new event instance.
20+
*
21+
* @return void
22+
*/
23+
public $room;
24+
public function __construct(Room $room)
25+
{
26+
$this->room = $room;
27+
}
28+
29+
30+
31+
/**
32+
* Get the channels the event should broadcast on.
33+
*
34+
* @return \Illuminate\Broadcasting\Channel|array
35+
*/
36+
public function broadcastOn()
37+
{
38+
return new Channel('rooms.'.$this->room->id);
39+
}
40+
41+
public function broadcastAs()
42+
{
43+
return 'room.start';
44+
}
45+
46+
public function broadcastWith()
47+
{
48+
return ['status' => $this->room->status];
49+
}
50+
}

app/Events/ScoreboardUpdate.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Skor;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Broadcasting\PrivateChannel;
9+
use Illuminate\Broadcasting\PresenceChannel;
10+
use Illuminate\Foundation\Events\Dispatchable;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
12+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
13+
use Illuminate\Support\Facades\DB;
14+
15+
class ScoreboardUpdate implements ShouldBroadcast
16+
{
17+
use Dispatchable, InteractsWithSockets, SerializesModels;
18+
19+
/**
20+
* Create a new event instance.
21+
*
22+
* @return void
23+
*/
24+
public $skor;
25+
26+
public function __construct(Skor $skor)
27+
{
28+
$this->skor = $skor;
29+
}
30+
31+
/**
32+
* Get the channels the event should broadcast on.
33+
*
34+
* @return \Illuminate\Broadcasting\Channel|array
35+
*/
36+
public function broadcastOn()
37+
{
38+
return new Channel('rooms.' . $this->skor->room_id);
39+
}
40+
41+
public function broadcastWith()
42+
{
43+
// return scoreboard data
44+
// $scoreboard = DB::table('skors')
45+
// ->where('room_id', '=', $this->skor->room_id)
46+
// ->join('users', function ($join){
47+
// $join->on('skors.user_id', '=', 'users.id');
48+
// })
49+
// ->select('users.username', 'skors.*')
50+
// ->orderBy('skors.skor_user', 'desc')
51+
// ->get();
52+
// return $scoreboard;
53+
return ['scoreboard' => 'scoreboard'];
54+
}
55+
}

app/Events/UserJoin.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Room;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Broadcasting\PrivateChannel;
9+
use Illuminate\Broadcasting\PresenceChannel;
10+
use Illuminate\Foundation\Events\Dispatchable;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
12+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
13+
14+
class UserJoin implements ShouldBroadcast
15+
{
16+
use Dispatchable, InteractsWithSockets, SerializesModels;
17+
18+
/**
19+
* Create a new event instance.
20+
*
21+
* @return void
22+
*/
23+
public $room;
24+
public function __construct(Room $room)
25+
{
26+
$this->room = $room;
27+
}
28+
29+
/**
30+
* Get the channels the event should broadcast on.
31+
*
32+
* @return \Illuminate\Broadcasting\Channel|array
33+
*/
34+
public function broadcastOn()
35+
{
36+
return new Channel('rooms.'.$this->room->id);
37+
}
38+
39+
public function broadcastAs()
40+
{
41+
return 'user.join';
42+
}
43+
44+
public function broadcastWith()
45+
{
46+
$current_player = unserialize($this->room->player_id);
47+
return ['count' => count($current_player)];
48+
}
49+
}

app/Room.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
class Room extends Model
88
{
99
protected $fillable = ['soals_id', 'master_id', 'player_id', 'status', 'kode'];
10+
// protected $casts = [
11+
// 'player_id' => 'array',
12+
// ];
1013
}

app/Skor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
class Skor extends Model
88
{
9-
protected $fillable = ['users_id', 'rooms_id', 'skor_user'];
9+
protected $fillable = ['user_id', 'room_id', 'skor_user'];
1010
}

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"fideloper/proxy": "^4.0",
1313
"laravel/framework": "5.8.*",
1414
"laravel/tinker": "^1.0",
15+
"pusher/pusher-php-server": "^3.4"
1516
"laravelcollective/html": "^5.8"
1617
},
1718
"require-dev": {

composer.lock

+138-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
*/
172172
App\Providers\AppServiceProvider::class,
173173
App\Providers\AuthServiceProvider::class,
174-
// App\Providers\BroadcastServiceProvider::class,
174+
App\Providers\BroadcastServiceProvider::class,
175175
App\Providers\EventServiceProvider::class,
176176
App\Providers\RouteServiceProvider::class,
177177

config/broadcasting.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
'app_id' => env('PUSHER_APP_ID'),
3838
'options' => [
3939
'cluster' => env('PUSHER_APP_CLUSTER'),
40-
'encrypted' => true,
40+
'encrypted' => false,
4141
],
4242
],
4343

0 commit comments

Comments
 (0)