A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
idk how to make reverb work
aminnausinde7eb085584c
diff --git a/.env.example b/.env.exampleindex 683a19aa..809bef9c 100755--- a/.env.example+++ b/.env.example@@ -3,11 +3,12 @@ APP_ENV=localAPP_KEY=APP_DEBUG=trueAPP_TIMEZONE=UTC-APP_URL=http://localhost+APP_URL=https://app.test:8080+SANCTUM_STATEFUL_DOMAINS=app.test:8080,0.0.0.0:6001,app.test:6001APP_LOCALE=enAPP_FALLBACK_LOCALE=en-APP_FAKER_LOCALE=en_US+APP_FAKER_LOCALE=en_CAAPP_MAINTENANCE_DRIVER=file# APP_MAINTENANCE_STORE=database@@ -24,7 +25,7 @@ LOG_LEVEL=debugDB_CONNECTION=pgsqlDB_HOST=127.0.0.1DB_PORT=5432-DB_DATABASE=mediaserveru+DB_DATABASE=mediaServerDB_USERNAME=rootDB_PASSWORD=@@ -32,12 +33,13 @@ SESSION_DRIVER=databaseSESSION_LIFETIME=120SESSION_ENCRYPT=falseSESSION_PATH=/-SESSION_DOMAIN=null+SESSION_DOMAIN=app.test-BROADCAST_CONNECTION=log+BROADCAST_CONNECTION=reverbFILESYSTEM_DISK=localQUEUE_CONNECTION=database+CACHE_DRIVER=fileCACHE_STORE=databaseCACHE_PREFIX=@@ -64,3 +66,24 @@ AWS_BUCKET=AWS_USE_PATH_STYLE_ENDPOINT=falseVITE_APP_NAME="${APP_NAME}"+VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"+VITE_PUSHER_HOST="${PUSHER_HOST}"+VITE_PUSHER_PORT="${PUSHER_PORT}"+VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"+VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"+VITE_BASE_URL="${APP_URL}"++PULSE_SERVER_NAME="DEV"+PULSE_SERVER_DIRECTORIES="/"++REVERB_APP_ID=355744+REVERB_APP_KEY=+REVERB_APP_SECRET=+REVERB_HOST="app.test"+REVERB_PORT=6001+REVERB_SCHEME=https++VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"+VITE_REVERB_HOST="${REVERB_HOST}"+VITE_REVERB_PORT="${REVERB_PORT}"+VITE_REVERB_SCHEME="${REVERB_SCHEME}"diff --git a/app/Events/TaskEnded.php b/app/Events/TaskEnded.phpnew file mode 100644index 00000000..8be3c3da--- /dev/null+++ b/app/Events/TaskEnded.php@@ -0,0 +1,45 @@+<?php++namespace App\Events;++use App\Models\Task;+use Illuminate\Broadcasting\Channel;+use Illuminate\Broadcasting\InteractsWithSockets;+use Illuminate\Broadcasting\PresenceChannel;+use Illuminate\Broadcasting\PrivateChannel;+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;+use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;+use Illuminate\Foundation\Events\Dispatchable;+use Illuminate\Queue\SerializesModels;++class TaskEnded implements ShouldBroadcast {+ use Dispatchable, InteractsWithSockets, SerializesModels;+++ /**+ * Create a new event instance.+ */+ public function __construct(public Task $task) {+ //+ }++ /**+ * Get the channels the event should broadcast on.+ *+ * @return array<int, \Illuminate\Broadcasting\Channel>+ */+ public function broadcastOn(): array {+ // $task = Task::where('id', $this->taskId)->first();+ // dump("hhhhh{$this->task->userId}");+ try {+ //code...+ return [+ new PrivateChannel("tasks.{$this->task->userId}"),+ new Channel('dashboard'),+ ];+ } catch (\Throwable $th) {+ //throw $th;+ dump($th->getMessage());+ }+ }+}diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.phpindex be3bc14f..dd90a416 100755--- a/app/Http/Controllers/DirectoryController.php+++ b/app/Http/Controllers/DirectoryController.php@@ -3,6 +3,7 @@namespace App\Http\Controllers;use App\Enums\TaskStatus;+use App\Events\TaskEnded;use App\Http\Resources\FolderResource;use App\Http\Resources\SeriesResource;use App\Http\Resources\VideoResource;@@ -157,9 +158,6 @@ class DirectoryController extends Controller {$task = $this->setupTask($userId, 'Sync Files', 'Syncs local file structure with database.', 1);try {- if (! isset($task->id)) {- throw ('waaa');- }$chain = [new SyncFiles($task->id),];@@ -351,6 +349,8 @@ class DirectoryController extends Controller {'ended_at' => $ended_at,'duration' => $duration < 0 ? $duration * -1 : $duration,]);++ broadcast(new TaskEnded($task));})->before(function (Batch $batch) use ($task) {$task->update(['status' => TaskStatus::PROCESSING,diff --git a/bootstrap/app.php b/bootstrap/app.phpindex 486a3ad2..f7d3668e 100755--- a/bootstrap/app.php+++ b/bootstrap/app.php@@ -11,6 +11,7 @@ return Application::configure(basePath: dirname(__DIR__))web: __DIR__ . '/../routes/web.php',api: __DIR__ . '/../routes/api.php',commands: __DIR__ . '/../routes/console.php',+ channels: __DIR__ . '/../routes/channels.php',health: '/up',)->withBroadcasting(diff --git a/config/sanctum.php b/config/sanctum.phpindex e78a0c8f..c9c5251f 100755--- a/config/sanctum.php+++ b/config/sanctum.php@@ -18,10 +18,10 @@ return ['stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf('%s%s',// 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',- 'localhost:443','app.test:8080',- 'localhost:8080',- '0.0.0.0:8080',+ 'app.test:6001',+ 'localhost:6001',+ '0.0.0.0:6001',Sanctum::currentApplicationUrlWithPort()))),diff --git a/package.json b/package.jsonindex 936664fe..62bc9cd4 100755--- a/package.json+++ b/package.json@@ -8,9 +8,13 @@"php:queue": "php artisan queue:listen","php:pulse": "php artisan pulse:check","php:scheduler": "php artisan schedule:work",+ "php:reverb": "php artisan reverb:start --host=\"0.0.0.0\" --port=6001 --hostname=\"app.test\"",+ "php:reverb-debug": "php artisan reverb:start --host=\"0.0.0.0\" --port=6001 --hostname=\"app.test\" --debug","vite:dev": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold\" \"npm:php:serve\" \"npm:php:queue\" \"npm:dev\"","vite:dev2": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold\" \"npm:php:serve\" \"npm:php:pail\" \"npm:dev\"","vite:cron": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\"",+ "vite:cronws": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold,magenta.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\" \"npm:php:reverb\"",+ "vite:cronwsd": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold,magenta.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\" \"npm:php:reverb-debug\"","vite:php": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,white.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:php:pulse\"","build": "npm run pint && npm run type-check && npm run build-only","build-only": "vite build",diff --git a/resources/js/bootstrap.ts b/resources/js/bootstrap.tsindex 2b59fb3f..c4bb7cde 100644--- a/resources/js/bootstrap.ts+++ b/resources/js/bootstrap.ts@@ -4,13 +4,7 @@* CSRF token as a header based on the value of the "XSRF" token cookie.*/-import axios, { type AxiosStatic } from 'axios';--declare global {- interface Window {- axios: AxiosStatic;- }-}+import axios from 'axios';window.axios = axios;@@ -22,18 +16,4 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';* allows your team to easily build robust real-time web applications.*/-// import Echo from 'laravel-echo';--// import Pusher from 'pusher-js';-// window.Pusher = Pusher;--// window.Echo = new Echo({-// broadcaster: 'pusher',-// key: import.meta.env.VITE_PUSHER_APP_KEY,-// cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',-// wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,-// wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,-// wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,-// forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',-// enabledTransports: ['ws', 'wss'],-// });+import './echo';diff --git a/resources/js/echo.js b/resources/js/echo.jsindex 9349afae..608fb7bc 100644--- a/resources/js/echo.js+++ b/resources/js/echo.js@@ -5,6 +5,23 @@ window.Pusher = Pusher;window.Echo = new Echo({broadcaster: 'reverb',+ // authorizer: (channel, options) => {+ // return {+ // authorize: (socketId, callback) => {+ // axios+ // .post('/api/broadcasting/auth', {+ // socket_id: socketId,+ // channel_name: channel.name,+ // })+ // .then((response) => {+ // callback(false, response.data);+ // })+ // .catch((error) => {+ // callback(true, error.response);+ // });+ // },+ // };+ // },key: import.meta.env.VITE_REVERB_APP_KEY,wsHost: import.meta.env.VITE_REVERB_HOST,wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,diff --git a/resources/js/global.d.ts b/resources/js/global.d.tsnew file mode 100644index 00000000..af0d9f0a--- /dev/null+++ b/resources/js/global.d.ts@@ -0,0 +1,10 @@+import Echo from 'laravel-echo';+import Pusher from 'pusher-js';++declare global {+ interface Window {+ axios: AxiosStatic;+ Pusher: typeof Pusher;+ Echo: Echo<'reverb'>;+ }+}diff --git a/resources/js/layouts/LayoutBase.vue b/resources/js/layouts/LayoutBase.vueindex 3534eb15..41bd8437 100755--- a/resources/js/layouts/LayoutBase.vue+++ b/resources/js/layouts/LayoutBase.vue@@ -1,19 +1,43 @@-<script setup>-import NavBar from '../components/panels/NavBar.vue';--// import { useScrollLock } from '@vueuse/core'-import { useAppStore } from '../stores/AppStore';+<script setup lang="ts">+import { useAppStore } from '@/stores/AppStore';import { storeToRefs } from 'pinia';-// import { ref, watch } from 'vue';-import { ref } from 'vue';+import { toast } from '@/service/toaster/toastService';+import { onMounted, ref, watch } from 'vue';++import NavBar from '@/components/panels/NavBar.vue';+import { useAuthStore } from '@/stores/AuthStore';const appStore = useAppStore();+const authStore = useAuthStore();+const { userData } = storeToRefs(authStore);const { selectedSideBar, sideBarTarget, scrollLock } = storeToRefs(appStore);const scrollBody = ref(null);-// const scrollLocked = useScrollLock(scrollBody);+const userInit = ref(false);++onMounted(() => {+ window.Echo.channel(`dashboard`).listen('TaskEnded', (event: any) => {+ console.log(event);++ // toast('Hi2');+ });+});++watch(+ () => userData.value,+ () => {+ if (!userData.value?.id || userInit.value) return;+ userInit.value = true;+ // console.log('window.echo', `tasks.${userData.value.id}`);++ window.Echo.private(`tasks.${userData.value.id}`).listen('TaskEnded', (event: any) => {+ console.log('window.echo2');+ console.log(event);-// watch(() => scrollLock.value, () => scrollLocked.value = scrollLock.value);+ toast('Hi');+ });+ },+);</script><template>diff --git a/routes/api.php b/routes/api.phpindex 94badcb4..0bb4ab51 100755--- a/routes/api.php+++ b/routes/api.php@@ -62,8 +62,8 @@ Route::prefix('pulse')->group(function () {// public-Route::post('/login', [AuthController::class, 'login']); // Deprecate?-Route::post('/register', [AuthController::class, 'register']); // Deprecate?+Route::post('/login', [AuthController::class, 'login']);+Route::post('/register', [AuthController::class, 'register']);Route::patch('/videos/watch/{video}', [VideoController::class, 'watch']);Route::get('/folders', [FolderController::class, 'getFrom']);Route::get('/videos', [VideoController::class, 'getFrom']);diff --git a/routes/channels.php b/routes/channels.phpindex df2ad287..3c733b2f 100644--- a/routes/channels.php+++ b/routes/channels.php@@ -2,6 +2,16 @@use Illuminate\Support\Facades\Broadcast;-Broadcast::channel('App.Models.User.{id}', function ($user, $id) {+Broadcast::channel('tasks.{id}', function ($user, $id) {+ dump('dam');return (int) $user->id === (int) $id;});++Broadcast::channel('management.{id}', function ($user, $id) {+ dump('dam');+ return (int) $user->id === (int) $id;+});+++Broadcast::channel('dashboard', function () {+});diff --git a/routes/web.php b/routes/web.phpindex d4443fc3..8f9463a7 100755--- a/routes/web.php+++ b/routes/web.php@@ -1,7 +1,9 @@<?php+use App\Events\TaskEnded;use App\Http\Controllers\DirectoryController;use App\Http\Controllers\MediaController;+use App\Models\Task;use Illuminate\Support\Facades\Route;use Illuminate\Support\Facades\URL;@@ -30,6 +32,12 @@ Route::get('/signed-url/{path}', function ($path) {);})->middleware('auth')->where('path', '.*');+Route::get('/broadcast', function () {+ $task = Task::where('id', 165)->first();+ dump($task);+ broadcast(new TaskEnded($task));+});+Route::middleware(['web'])->group(function () {Route::get('/pulse', function () {