Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent committed Nov 22, 2023
1 parent d924a62 commit 71f0a62
Show file tree
Hide file tree
Showing 25 changed files with 873 additions and 87 deletions.
44 changes: 3 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,7 @@
[![Total Downloads](https://img.shields.io/packagist/dt/seatplus/broadcast-hub.svg?style=flat-square)](https://packagist.org/packages/seatplus/broadcast-hub)

---
This repo can be used as to scaffold a Laravel package. Follow these steps to get started:

1. Press the "Use template" button at the top of this repo to create a new repo with the contents of this broadcast-hub
2. Run "./configure-broadcast-hub.sh" to run a script that will replace all placeholders throughout all the files
3. Remove this block of text.
4. Have fun creating your package.
5. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/broadcast-hub.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/broadcast-hub)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

Expand All @@ -33,36 +16,15 @@ You can install the package via composer:
composer require seatplus/broadcast-hub
```

You can publish and run the migrations with:

```bash
php artisan vendor:publish --provider="Seatplus\BroadcastHub\BroadcastHubServiceProvider" --tag="broadcast-hub-migrations"
php artisan migrate
```

You can publish the config file with:
```bash
php artisan vendor:publish --provider="Seatplus\BroadcastHub\BroadcastHubServiceProvider" --tag="broadcast-hub-config"
```

This is the contents of the published config file:

```php
return [
];
```

## Usage

```php
$broadcast-hub = new Seatplus\BroadcastHub();
echo $broadcast-hub->echoPhrase('Hello, Spatie!');
```
...

## Testing

```bash
composer test
composer test #for tests
composer test-coverage #for tests with coverage
```

## Changelog
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
],
"require": {
"php": "^8.1",
"seatplus/web": "^3.1",
"seatplus/web": "^4.0",
"illuminate/contracts": "^10.0",
"seatplus/connector": "^1.1"
"seatplus/connector": "^1.2"
},
"require-dev": {
"nunomaduro/collision": "^7.0",
Expand All @@ -45,7 +45,7 @@
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "./vendor/bin/pest",
"test": "./vendor/bin/pest --retry",
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage",
"test-parallel": "XDEBUG_MODE=coverage ./vendor/bin/testbench package:test --parallel",
"test-parallel-coverage": "XDEBUG_MODE=coverage ./vendor/bin/testbench package:test --coverage --parallel",
Expand Down
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</testsuites>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<!-- <env name="APP_ENV" value="testing"/>-->
<!-- <env name="APP_ENV" value="testing"/>-->
<env name="REDIS_CLIENT" value="phpredis"/>
<env name="REDIS_HOST" value="127.0.0.1"/>
<env name="REDIS_PASSWORD" value="null"/>
Expand All @@ -21,10 +21,10 @@
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="mysql"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="3308"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_DATABASE" value="testbench"/>
<env name="DB_USERNAME" value="default"/>
<env name="DB_PASSWORD" value="secret"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value="AG"/>
</php>
<logging/>
<source>
Expand Down
8 changes: 1 addition & 7 deletions resources/js/Pages/BroadcastHub/BroadcastHubIndex.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<template>
<div class="space-y-3">
<teleport to="#head">
<title>{{ title(pageTitle) }}</title>
</teleport>

<PageHeader>
{{ pageTitle }}
</PageHeader>
<PageHeader :page-title="pageTitle" />

<BroadcastImplementation
v-for="broadcaster in broadcasters"
Expand Down
14 changes: 10 additions & 4 deletions resources/js/Pages/BroadcastHub/EnabledBroadcast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
@update:recipient="(e) => recipient = e"
/>

<GlobalBroadcasts
:key="recipient.recipient_id + broadcaster.id"
:broadcaster-id="broadcaster.id"
:recipient-id="recipient.recipient_id"
v-if="entities.length > 0 && recipient"
/>

<Entities
:entities="entities"
:activeEntity="recipient"
Expand All @@ -18,6 +25,9 @@
import { ref, computed, onMounted, watch } from 'vue'
import axios from 'axios'
import { chain } from 'lodash'
import Entities from "./Entities/Entities.vue";
import Recipients from "./Recipients.vue";
import GlobalBroadcasts from "./Globals/GlobalBroadcasts.vue";
const props = defineProps({
broadcaster: {
Expand Down Expand Up @@ -117,8 +127,4 @@ onMounted(async () => {
await buildEndpoints()
})
import Recipients from "./Recipients.vue";
</script>
2 changes: 1 addition & 1 deletion resources/js/Pages/BroadcastHub/Entities/Entities.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Card class="max-h-screen hover:overflow-auto">
<dl class="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
<dl class="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
<div v-for="item in entities" :key="item.entity_id" class="relative overflow-hidden rounded-lg bg-white px-4 pb-12 pt-5 shadow sm:px-6 sm:pt-6">
<dt>
<EntityByIdBlock :id="parseInt(item.entity_id)" />
Expand Down
71 changes: 71 additions & 0 deletions resources/js/Pages/BroadcastHub/Globals/GlobalBroadcasts.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script setup>
import Card from "@/Shared/Layout/Cards/Card.vue";
import { ref, onMounted } from "vue";
import axios from 'axios'
import GlobalNotification from "./GlobalNotification.vue";
const props = defineProps({
broadcasterId: {
type: String,
required: true
},
recipientId: {
type: String,
required: true
}
})
const hasGlobals = ref(false)
const isLoaded = ref(false)
const notifications = ref([])
onMounted(() => {
axios.get(route('global-subscriptions.index', [props.broadcasterId, props.recipientId])).then(response => {
notifications.value = response.data
hasGlobals.value = response.data.length > 0
}).finally(() => {
isLoaded.value = true
})
})
</script>

<template>
<Card>
<div v-if="!isLoaded"
class="relative block w-full border-2 border-gray-300 border-dashed rounded-lg p-12 text-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
<svg
class="animate-spin mx-auto h-12 w-12 text-gray-400"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
class="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
/>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
/>
</svg>
<span class="mt-2 block text-sm font-medium text-gray-900">
loading global subscriptions...
</span>
</div>
<dl class="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
<GlobalNotification v-for="notification in notifications" :key="notification.notification" :notification="notification" />
</dl>

</Card>

</template>
75 changes: 75 additions & 0 deletions resources/js/Pages/BroadcastHub/Globals/GlobalNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script setup>
import {ref, watch} from 'vue'
import { Switch, SwitchDescription, SwitchGroup, SwitchLabel } from '@headlessui/vue'
import {useToasts} from "@/Functions/useToasts.js";
const props = defineProps({
notification: {
type: Object,
required: true
}
})
const enabled = ref(props.notification.is_subscribed)
const processing = ref(false)
const toasts = useToasts()
const subscribe = async (notification) => {
await axios.post(route('subscriptions.store'), notification)
.catch(error => {
console.log(error)
}).then((response) => {
props.notification.subscription_id = response.data.subscription_id
props.notification.is_subscribed = true
toasts.addToast('Subscribed to ' + props.notification.title, {appearance: 'success'})
})
}
const unsubscribe = async (notification) => {
await axios.delete(route('subscriptions.destroy', notification.subscription_id)).then(() => {
props.notification.is_subscribed = false
props.notification.subscription_id = null
toasts.addToast('Unsubscribed from ' + props.notification.title, {appearance: 'success'})
}).catch(error => {
console.log(error)
})
}
watch(() => enabled.value, async (newShow) => {
flipProcessing()
if(newShow) {
await subscribe(props.notification)
} else {
await unsubscribe(props.notification)
}
flipProcessing()
})
const flipProcessing = () => {
processing.value = !processing.value
}
</script>

<template>
<div class="bg-white shadow sm:rounded-lg">
<SwitchGroup as="div" class="px-4 py-5 sm:p-6">
<SwitchLabel as="h2" class="text-lg font-medium leading-6 text-gray-900 sm:truncate sm:tracking-tight" passive>{{ notification.title }}</SwitchLabel>
<div class="mt-2 sm:flex sm:items-start sm:justify-between">
<div class="max-w-xl text-sm font-medium text-gray-500">
<SwitchDescription>{{ notification.description }}</SwitchDescription>
</div>
<div class="mt-5 sm:ml-6 sm:mt-0 sm:flex sm:flex-shrink-0 sm:items-center">
<Switch v-if="!processing" v-model="enabled" :class="[enabled ? 'bg-indigo-600' : 'bg-gray-200', 'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2']">
<span aria-hidden="true" :class="[enabled ? 'translate-x-5' : 'translate-x-0', 'inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out']" />
</Switch>
</div>
</div>
</SwitchGroup>
</div>
</template>
10 changes: 10 additions & 0 deletions routes/broadcast_hub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Support\Facades\Route;
use Seatplus\BroadcastHub\Http\Controllers\BroadcastController;
use Seatplus\BroadcastHub\Http\Controllers\ChannelController;
use Seatplus\BroadcastHub\Http\Controllers\GlobalSubscriptionController;
use Seatplus\BroadcastHub\Http\Controllers\RecipientController;
use Seatplus\BroadcastHub\Http\Controllers\SubscriptionController;

Expand Down Expand Up @@ -64,4 +65,13 @@
Route::delete('/{subscription_id}', 'destroy')
->name('destroy');
});

Route::controller(GlobalSubscriptionController::class)
->name('global-subscriptions.')
->prefix('global-subscriptions')
->group(function () {

Route::get('/broadcaster/{broadcaster_id}/recipient/{recipient_id}', 'index')
->name('index');
});
});
16 changes: 16 additions & 0 deletions src/BroadcastHubServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Seatplus\BroadcastHub\Commands\CorporationTracking\CorporationTrackingCommand;
use Seatplus\BroadcastHub\Commands\CorporationTracking\NewCorporationMemberCommand;
use Seatplus\BroadcastHub\Events\NotificationFailed;
use Seatplus\BroadcastHub\Listeners\NotificationFailedListener;

Expand All @@ -28,6 +30,9 @@ public function boot()
// Add translations
//$this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'web');

// Add commands
$this->addCommands();

// Add Event Listeners
Event::listen(NotificationFailed::class, NotificationFailedListener::class.'@handle');

Expand Down Expand Up @@ -66,4 +71,15 @@ private function addPublications()
__DIR__.'/../resources/js' => resource_path('js'),
], 'web');
}

private function addCommands()
{
if($this->app->runningInConsole()) {
$this->commands([
CorporationTrackingCommand::class,
NewCorporationMemberCommand::class
]);
}

}
}
17 changes: 0 additions & 17 deletions src/Commands/BroadcastHubCommand.php

This file was deleted.

0 comments on commit 71f0a62

Please sign in to comment.