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
* 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.
*/
@ -20,13 +20,13 @@ return [
],
/**
* This class is responsible for finding the clients. The default provider
* will use the clients defined in this config file.
* This class is responsible for finding the apps. The default provider
* will use the apps defined in this config file.
*
* 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.

View File

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

View File

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

View File

@ -11,10 +11,10 @@ class ConfigAppProvider implements AppProvider
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
{
return $this->apps

View File

@ -7,10 +7,10 @@ use BeyondCode\LaravelWebSockets\Apps\AppProvider;
class ShowDashboard
{
public function __invoke(Request $request, AppProvider $clients)
public function __invoke(Request $request, AppProvider $apps)
{
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)
{
if (!$client = App::findById($appId)) {
if (! App::findById($appId)) {
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() {
return app(config('websockets.client_provider'));
return app(config('websockets.app_provider'));
});
}

View File

@ -18,20 +18,18 @@ class ConfigAppProviderTest extends TestCase
}
/** @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();
$this->assertCount(1, $apps);
/** @var $client */
$client = $apps[0];
$this->assertEquals('Test App', $client->name);
$this->assertEquals(1234, $client->id);
$this->assertEquals('TestKey', $client->key);
$this->assertEquals('TestSecret', $client->secret);
/** @var $app */
$app = $apps[0];
$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)
{
$app['config']->set('websockets.clients', [
$app['config']->set('websockets.apps', [
[
'name' => 'Test App',
'id' => 1234,