rename client to app

This commit is contained in:
freek 2018-12-01 14:17:32 +01:00
parent 279deeeb7c
commit 46d7334067
9 changed files with 30 additions and 32 deletions

View File

@ -6,7 +6,7 @@ return [
/** /**
* This package comes with multi tenancy out of the box. Here you can * This package comes with multi tenancy out of the box. Here you can
* configure the different clients that can use the webSockets server. * configure the different apps that can use the webSockets server.
* *
* You should make sure that the app id is numeric. * You should make sure that the app id is numeric.
*/ */
@ -20,13 +20,13 @@ return [
], ],
/** /**
* This class is responsible for finding the clients. The default provider * This class is responsible for finding the apps. The default provider
* will use the clients defined in this config file. * will use the apps defined in this config file.
* *
* You can create a custom provider by implementing the * You can create a custom provider by implementing the
* `ClientProvier` interface. * `appProvier` interface.
*/ */
'client_provider' => ConfigAppProvider::class, 'app_provider' => ConfigAppProvider::class,
/* /*
* This array contains the hosts of which you want to allow incoming requests. * This array contains the hosts of which you want to allow incoming requests.

View File

@ -17,11 +17,11 @@
<div class="card col-xs-12 mt-4"> <div class="card col-xs-12 mt-4">
<div class="card-header"> <div class="card-header">
<form id="connect" class="form-inline" role="form"> <form id="connect" class="form-inline" role="form">
<label class="my-1 mr-2" for="client">Client:</label> <label class="my-1 mr-2" for="app">app:</label>
<select class="form-control form-control-sm mr-2" name="client" id="client" v-model="client"> <select class="form-control form-control-sm mr-2" name="app" id="app" v-model="app">
<option v-for="client in clients" :value="client">@{{ client.name }}</option> <option v-for="app in apps" :value="app">@{{ app.name }}</option>
</select> </select>
<label class="my-1 mr-2" for="client">Port:</label> <label class="my-1 mr-2" for="app">Port:</label>
<input class="form-control form-control-sm mr-2" v-model="port" placeholder="Port"> <input class="form-control form-control-sm mr-2" v-model="port" placeholder="Port">
<button v-if="! connected" type="submit" @click.prevent="connect" class="mr-2 btn btn-sm btn-primary"> <button v-if="! connected" type="submit" @click.prevent="connect" class="mr-2 btn btn-sm btn-primary">
Connect Connect
@ -90,8 +90,8 @@
connected: false, connected: false,
pusher: null, pusher: null,
port: 6001, port: 6001,
client: null, app: null,
clients: {!! json_encode($clients) !!}, apps: {!! json_encode($apps) !!},
form: { form: {
channel: null, channel: null,
event: null, event: null,
@ -102,7 +102,7 @@
methods: { methods: {
connect() { connect() {
this.pusher = new Pusher(this.client.appKey, { this.pusher = new Pusher(this.app.appKey, {
wsHost: window.location.hostname, wsHost: window.location.hostname,
wsPort: this.port, wsPort: this.port,
disableStats: true, disableStats: true,
@ -173,9 +173,9 @@
sendEvent() { sendEvent() {
$.post('/{{ request()->path() }}/event', { $.post('/{{ request()->path() }}/event', {
_token: '{{ csrf_token() }}', _token: '{{ csrf_token() }}',
key: this.client.appKey, key: this.app.key,
secret: this.client.appSecret, secret: this.app.secret,
appId: this.client.appId, appId: this.app.id,
channel: this.form.channel, channel: this.form.channel,
event: this.form.event, event: this.form.event,
data: this.form.data, data: this.form.data,

View File

@ -4,7 +4,7 @@ namespace BeyondCode\LaravelWebSockets\Apps;
interface AppProvider interface AppProvider
{ {
/** @return array[BeyondCode\LaravelWebSockets\ClientProviders\Client] */ /** @return array[BeyondCode\LaravelWebSockets\AppProviders\App] */
public function all(): array; public function all(): array;
public function findById(int $appId): ?App; public function findById(int $appId): ?App;

View File

@ -11,10 +11,10 @@ class ConfigAppProvider implements AppProvider
public function __construct() public function __construct()
{ {
$this->apps = collect(config('websockets.clients')); $this->apps = collect(config('websockets.apps'));
} }
/** @return array[\BeyondCode\LaravelWebSockets\ClientProviders\Client] */ /** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */
public function all(): array public function all(): array
{ {
return $this->apps return $this->apps

View File

@ -7,10 +7,10 @@ use BeyondCode\LaravelWebSockets\Apps\AppProvider;
class ShowDashboard class ShowDashboard
{ {
public function __invoke(Request $request, AppProvider $clients) public function __invoke(Request $request, AppProvider $apps)
{ {
return view('websockets::dashboard', [ return view('websockets::dashboard', [
'clients' => $clients->all(), 'apps' => $apps->all(),
]); ]);
} }
} }

View File

@ -77,7 +77,7 @@ abstract class Controller implements HttpServerInterface
public function ensureValidAppId(string $appId) public function ensureValidAppId(string $appId)
{ {
if (!$client = App::findById($appId)) { if (! App::findById($appId)) {
throw new HttpException(401, "Unknown app id `{$appId}` provided."); throw new HttpException(401, "Unknown app id `{$appId}` provided.");
} }

View File

@ -45,7 +45,7 @@ class WebSocketsServiceProvider extends ServiceProvider
}); });
$this->app->singleton(AppProvider::class, function() { $this->app->singleton(AppProvider::class, function() {
return app(config('websockets.client_provider')); return app(config('websockets.app_provider'));
}); });
} }

View File

@ -18,20 +18,18 @@ class ConfigAppProviderTest extends TestCase
} }
/** @test */ /** @test */
public function it_can_get_client_from_the_config_file() public function it_can_get_apps_from_the_config_file()
{ {
$apps = $this->configAppProvider->all(); $apps = $this->configAppProvider->all();
$this->assertCount(1, $apps); $this->assertCount(1, $apps);
/** @var $client */ /** @var $app */
$client = $apps[0]; $app = $apps[0];
$this->assertEquals('Test App', $client->name);
$this->assertEquals(1234, $client->id);
$this->assertEquals('TestKey', $client->key);
$this->assertEquals('TestSecret', $client->secret);
$this->assertEquals('Test App', $app->name);
$this->assertEquals(1234, $app->id);
$this->assertEquals('TestKey', $app->key);
$this->assertEquals('TestSecret', $app->secret);
} }
} }

View File

@ -34,7 +34,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
protected function getEnvironmentSetUp($app) protected function getEnvironmentSetUp($app)
{ {
$app['config']->set('websockets.clients', [ $app['config']->set('websockets.apps', [
[ [
'name' => 'Test App', 'name' => 'Test App',
'id' => 1234, 'id' => 1234,