From 17deff4d861b9eb1e3db7584117f35321424a8b0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 4 Dec 2023 15:42:08 +0100 Subject: [PATCH] wip --- .../Project/Application/DeploymentNavbar.php | 5 +- .../ApplicationDeploymentFinished.php | 4 +- composer.lock | 149 +++++++++++++++++- config/broadcasting.php | 10 +- docker-compose.dev.yml | 7 + docker-compose.yml | 6 + package-lock.json | 26 +++ package.json | 2 + resources/js/app.js | 23 ++- 9 files changed, 222 insertions(+), 10 deletions(-) diff --git a/app/Http/Livewire/Project/Application/DeploymentNavbar.php b/app/Http/Livewire/Project/Application/DeploymentNavbar.php index 0cdb895c8..830a24fab 100644 --- a/app/Http/Livewire/Project/Application/DeploymentNavbar.php +++ b/app/Http/Livewire/Project/Application/DeploymentNavbar.php @@ -17,8 +17,11 @@ class DeploymentNavbar extends Component public Application $application; public Server $server; public bool $is_debug_enabled = false; - protected $listeners = ['deploymentFinished']; + protected $listeners = ['deploymentFinished','echo:custom-channel,ApplicationDeploymentFinished' => 'notifyNewOrder']; + public function notifyNewOrder() { + ray('New order received'); + } public function mount() { $this->application = Application::find($this->application_deployment_queue->application_id); diff --git a/app/Providers/ApplicationDeploymentFinished.php b/app/Providers/ApplicationDeploymentFinished.php index a87dc06b8..627ae03a1 100644 --- a/app/Providers/ApplicationDeploymentFinished.php +++ b/app/Providers/ApplicationDeploymentFinished.php @@ -10,7 +10,7 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class ApplicationDeploymentFinished +class ApplicationDeploymentFinished implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; @@ -21,7 +21,7 @@ class ApplicationDeploymentFinished public function broadcastOn(): array { return [ - new PrivateChannel('application-deployment-finished'), + new Channel('custom-channel'), ]; } } diff --git a/composer.lock b/composer.lock index 18ce42444..82140f50a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "21ed976753483557403be75318585442", + "content-hash": "2fdb48eb84a31346d8396443b34b0cb0", "packages": [ { "name": "aws/aws-crt-php", @@ -4156,6 +4156,92 @@ }, "time": "2020-10-15T08:29:30+00:00" }, + { + "name": "paragonie/sodium_compat", + "version": "v1.20.0", + "source": { + "type": "git", + "url": "https://github.com/paragonie/sodium_compat.git", + "reference": "e592a3e06d1fa0d43988c7c7d9948ca836f644b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/e592a3e06d1fa0d43988c7c7d9948ca836f644b6", + "reference": "e592a3e06d1fa0d43988c7c7d9948ca836f644b6", + "shasum": "" + }, + "require": { + "paragonie/random_compat": ">=1", + "php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7|^8" + }, + "require-dev": { + "phpunit/phpunit": "^3|^4|^5|^6|^7|^8|^9" + }, + "suggest": { + "ext-libsodium": "PHP < 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security.", + "ext-sodium": "PHP >= 7.0: Better performance, password hashing (Argon2i), secure memory management (memzero), and better security." + }, + "type": "library", + "autoload": { + "files": [ + "autoload.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "ISC" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com" + }, + { + "name": "Frank Denis", + "email": "jedisct1@pureftpd.org" + } + ], + "description": "Pure PHP implementation of libsodium; uses the PHP extension if it exists", + "keywords": [ + "Authentication", + "BLAKE2b", + "ChaCha20", + "ChaCha20-Poly1305", + "Chapoly", + "Curve25519", + "Ed25519", + "EdDSA", + "Edwards-curve Digital Signature Algorithm", + "Elliptic Curve Diffie-Hellman", + "Poly1305", + "Pure-PHP cryptography", + "RFC 7748", + "RFC 8032", + "Salpoly", + "Salsa20", + "X25519", + "XChaCha20-Poly1305", + "XSalsa20-Poly1305", + "Xchacha20", + "Xsalsa20", + "aead", + "cryptography", + "ecdh", + "elliptic curve", + "elliptic curve cryptography", + "encryption", + "libsodium", + "php", + "public-key cryptography", + "secret-key cryptography", + "side-channel resistant" + ], + "support": { + "issues": "https://github.com/paragonie/sodium_compat/issues", + "source": "https://github.com/paragonie/sodium_compat/tree/v1.20.0" + }, + "time": "2023-04-30T00:54:53+00:00" + }, { "name": "php-http/client-common", "version": "2.7.0", @@ -5569,6 +5655,67 @@ }, "time": "2023-10-14T21:56:36+00:00" }, + { + "name": "pusher/pusher-php-server", + "version": "7.2.3", + "source": { + "type": "git", + "url": "https://github.com/pusher/pusher-http-php.git", + "reference": "416e68dd5f640175ad5982131c42a7a666d1d8e9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/pusher/pusher-http-php/zipball/416e68dd5f640175ad5982131c42a7a666d1d8e9", + "reference": "416e68dd5f640175ad5982131c42a7a666d1d8e9", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "guzzlehttp/guzzle": "^7.2", + "paragonie/sodium_compat": "^1.6", + "php": "^7.3|^8.0", + "psr/log": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "overtrue/phplint": "^2.3", + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Pusher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Library for interacting with the Pusher REST API", + "keywords": [ + "events", + "messaging", + "php-pusher-server", + "publish", + "push", + "pusher", + "real time", + "real-time", + "realtime", + "rest", + "trigger" + ], + "support": { + "issues": "https://github.com/pusher/pusher-http-php/issues", + "source": "https://github.com/pusher/pusher-http-php/tree/7.2.3" + }, + "time": "2023-05-17T16:00:06+00:00" + }, { "name": "ralouphie/getallheaders", "version": "3.0.3", diff --git a/config/broadcasting.php b/config/broadcasting.php index 4dbd22c7e..2a8b9a387 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -15,7 +15,7 @@ return [ | */ - 'default' => env('BROADCAST_DRIVER', 'null'), + 'default' => env('BROADCAST_DRIVER', 'log'), /* |-------------------------------------------------------------------------- @@ -36,10 +36,10 @@ return [ 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ - 'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com', - 'port' => env('PUSHER_PORT', 443), - 'scheme' => env('PUSHER_SCHEME', 'https'), - 'encrypted' => true, + 'host' => 'coolify-soketi', + 'port' => env('PUSHER_PORT', 6001), + 'scheme' => env('PUSHER_SCHEME', 'http'), + 'encrypted' => false, 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', ], 'client_options' => [ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ebd0c7a82..25f3d5a7b 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -44,6 +44,13 @@ services: volumes: - /data/coolify/_volumes/redis/:/data # - coolify-redis-data-dev:/data + soketi: + ports: + - "${FORWARD_SOKETI_PORT:-6001}:6001" + - "${FORWARD_SOKETI_METRICS_SERVER_PORT:-9601}:9601" + environment: + SOKETI_DEBUG: "true" + SOKETI_METRICS_SERVER_PORT: "${SOKETI_METRICS_SERVER_PORT:-9601}" vite: image: node:20 working_dir: /var/www/html diff --git a/docker-compose.yml b/docker-compose.yml index 001b1b212..2509f6fc8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,12 @@ services: restart: always networks: - coolify + soketi: + image: 'quay.io/soketi/soketi:latest-16-alpine' + container_name: coolify-soketi + restart: always + networks: + - coolify networks: coolify: name: coolify diff --git a/package-lock.json b/package-lock.json index 1e5ebd523..05d25a5d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,10 @@ "@vitejs/plugin-vue": "4.5.0", "autoprefixer": "10.4.16", "axios": "1.6.2", + "laravel-echo": "^1.15.3", "laravel-vite-plugin": "0.8.1", "postcss": "8.4.31", + "pusher-js": "^8.4.0-rc2", "tailwindcss": "3.3.5", "vite": "4.5.0", "vue": "3.3.8" @@ -1290,6 +1292,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/laravel-echo": { + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/laravel-echo/-/laravel-echo-1.15.3.tgz", + "integrity": "sha512-SRXzccaat6w4qKgZ4/rjFKr3nJfVxB+ly4V0MEJNIF1/TpERNXepo3uk7NnOjBGsiV/np1fl2XitAzW4Sa1s/w==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/laravel-vite-plugin": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/laravel-vite-plugin/-/laravel-vite-plugin-0.8.1.tgz", @@ -1647,6 +1658,15 @@ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", "dev": true }, + "node_modules/pusher-js": { + "version": "8.4.0-rc2", + "resolved": "https://registry.npmjs.org/pusher-js/-/pusher-js-8.4.0-rc2.tgz", + "integrity": "sha512-d87GjOEEl9QgO5BWmViSqW0LOzPvybvX6WA9zLUstNdB57jVJuR27zHkRnrav2a3+zAMlHbP2Og8wug+rG8T+g==", + "dev": true, + "dependencies": { + "tweetnacl": "^1.0.3" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -1886,6 +1906,12 @@ "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==" }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", diff --git a/package.json b/package.json index 2ddf60c7a..f06d6e28e 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "@vitejs/plugin-vue": "4.5.0", "autoprefixer": "10.4.16", "axios": "1.6.2", + "laravel-echo": "^1.15.3", "laravel-vite-plugin": "0.8.1", "postcss": "8.4.31", + "pusher-js": "^8.4.0-rc2", "tailwindcss": "3.3.5", "vite": "4.5.0", "vue": "3.3.8" diff --git a/resources/js/app.js b/resources/js/app.js index ccfeee5c2..d7fb2541d 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,9 +1,25 @@ import Alpine from "alpinejs"; - +import Echo from 'laravel-echo'; +import Pusher from 'pusher-js'; import { createApp } from "vue"; import MagicBar from "./components/MagicBar.vue"; import Toaster from "../../vendor/masmerise/livewire-toaster/resources/js"; +window.Pusher = Pusher; + +window.Echo = new Echo({ + broadcaster: 'pusher', + cluster: import.meta.env.VITE_PUSHER_HOST, + key: import.meta.env.VITE_PUSHER_APP_KEY, + wsHost: import.meta.env.VITE_PUSHER_HOST, + wsPort: import.meta.env.VITE_PUSHER_PORT, + wssPort: import.meta.env.VITE_PUSHER_PORT, + forceTLS: false, + encrypted: false, + disableStats: true, + enabledTransports: ['ws', 'wss'], +}); + Alpine.plugin(Toaster); window.Alpine = Alpine; @@ -12,3 +28,8 @@ Alpine.start(); const app = createApp({}); app.component("magic-bar", MagicBar); app.mount("#vue"); + + +window.Echo.channel("custom-channel").listen("ApplicationDeploymentFinished", (e) => { + console.log(e); +});