Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#37 Updated echo server configuration, added ability to switch colors…
… and have it be live updated. Fixed an issue where anonymous users couldn't view any routes.
- Loading branch information
Showing
33 changed files
with
457 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\DungeonRoute; | ||
use App\User; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PresenceChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class UserColorChangedEvent implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
/** @var DungeonRoute $_dungeonroute */ | ||
private $_dungeonroute; | ||
|
||
/** @var User $_user */ | ||
private $_user; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param $dungeonroute DungeonRoute | ||
* @param User $user | ||
* @return void | ||
*/ | ||
public function __construct(DungeonRoute $dungeonroute, User $user) | ||
{ | ||
$this->_dungeonroute = $dungeonroute; | ||
$this->_user = $user; | ||
} | ||
|
||
/** | ||
* Get the channels the event should broadcast on. | ||
* | ||
* @return \Illuminate\Broadcasting\Channel|array | ||
*/ | ||
public function broadcastOn() | ||
{ | ||
return new PresenceChannel(sprintf('route-edit.%s', $this->_dungeonroute->public_key)); | ||
} | ||
|
||
public function broadcastAs() | ||
{ | ||
return 'user-color-changed'; | ||
} | ||
|
||
public function broadcastWith() | ||
{ | ||
return [ | ||
'name' => $this->_user->name, | ||
'color' => $this->_user->echo_color | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class EchoServerServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// Bind the interface to the actual service | ||
$this->app->bind('App\Service\EchoServerConfigServiceInterface', 'App\Service\EchoServerConfigService'); | ||
$this->app->bind('App\Service\EchoServerHttpApiServiceInterface', 'App\Service\EchoServerHttpApiService'); | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
|
||
/** | ||
* This service provides functionality for reading the current laravel echo service and parsing its contents. | ||
* @package App\Service | ||
* @author Wouter | ||
* @since 30/05/2019 | ||
*/ | ||
class EchoServerConfigService implements EchoServerConfigServiceInterface | ||
{ | ||
/** | ||
* @return \stdClass | ||
* @throws \Exception | ||
*/ | ||
public function getConfig() | ||
{ | ||
$json = file_get_contents( | ||
base_path( | ||
sprintf('config/echo/%s/laravel-echo-server.json', env('APP_TYPE')) | ||
) | ||
); | ||
|
||
if ($json === false) { | ||
throw new \Exception('Unable to read echo server configuration, is APP_TYPE set?'); | ||
} else { | ||
return json_decode($json); | ||
} | ||
} | ||
|
||
/** | ||
* @return \stdClass[] | ||
* @throws \Exception | ||
*/ | ||
public function getClients() | ||
{ | ||
return ($this->getConfig())->clients; | ||
} | ||
|
||
/** | ||
* @param $appId string | ||
* @return \stdClass | ||
* @throws \Exception | ||
*/ | ||
public function getClient($appId) | ||
{ | ||
$result = false; | ||
foreach ($this->getConfig()->clients as $client) { | ||
if ($client->appId === $appId) { | ||
$result = $client; | ||
break; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param $index int | ||
* @return \stdClass | ||
* @throws \Exception | ||
*/ | ||
public function getClientAt($index) | ||
{ | ||
return ($this->getConfig())->clients[$index]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
|
||
namespace App\Service; | ||
|
||
interface EchoServerConfigServiceInterface { | ||
public function getConfig(); | ||
|
||
public function getClients(); | ||
|
||
public function getClient($appId); | ||
|
||
public function getClientAt($index); | ||
} |
Oops, something went wrong.