diff --git a/extensions/pusher/extend.php b/extensions/pusher/extend.php index b90a3053b1..a31b5438ef 100644 --- a/extensions/pusher/extend.php +++ b/extensions/pusher/extend.php @@ -32,7 +32,8 @@ (new Extend\Settings()) ->serializeToForum('pusherKey', 'flarum-pusher.app_key') - ->serializeToForum('pusherCluster', 'flarum-pusher.app_cluster'), + ->serializeToForum('pusherCluster', 'flarum-pusher.app_cluster') + ->serializeToForum('pusherHostname', 'flarum-pusher.server_hostname'), (new Extend\Event()) ->listen(Posted::class, Listener\PushNewPost::class), diff --git a/extensions/pusher/js/dist-typings/forum/index.d.ts b/extensions/pusher/js/dist-typings/forum/index.d.ts index 76988b4d98..78e2f2810f 100644 --- a/extensions/pusher/js/dist-typings/forum/index.d.ts +++ b/extensions/pusher/js/dist-typings/forum/index.d.ts @@ -1,8 +1,8 @@ -import * as PusherTypes from 'pusher-js'; +import Pusher, { Channel } from 'pusher-js'; export type PusherBinding = { channels: { - main: PusherTypes.Channel; - user: PusherTypes.Channel | null; + main: Channel; + user: Channel | null; }; - pusher: PusherTypes.default; + pusher: Pusher; }; diff --git a/extensions/pusher/js/package.json b/extensions/pusher/js/package.json index 81beb618ea..f9e94d355a 100644 --- a/extensions/pusher/js/package.json +++ b/extensions/pusher/js/package.json @@ -25,5 +25,8 @@ "typescript-coverage-report": "^0.6.1", "webpack": "^5.76.0", "webpack-cli": "^4.9.1" + }, + "dependencies": { + "pusher-js": "^8.4.0" } } diff --git a/extensions/pusher/js/src/admin/extend.tsx b/extensions/pusher/js/src/admin/extend.tsx index e87eb4fd3f..5edc97f26e 100644 --- a/extensions/pusher/js/src/admin/extend.tsx +++ b/extensions/pusher/js/src/admin/extend.tsx @@ -9,7 +9,7 @@ export default [ label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_id_label'), type: 'text', }), - 30 + 40 ) .setting( () => ({ @@ -17,7 +17,7 @@ export default [ label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_key_label'), type: 'text', }), - 20 + 30 ) .setting( () => ({ @@ -25,7 +25,7 @@ export default [ label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_secret_label'), type: 'text', }), - 10 + 20 ) .setting( () => ({ @@ -33,6 +33,14 @@ export default [ label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_cluster_label'), type: 'text', }), + 10 + ) + .setting( + () => ({ + setting: 'flarum-pusher.server_hostname', + label: app.translator.trans('flarum-pusher.admin.pusher_settings.server_hostname_label'), + type: 'text', + }), 0 ), ]; diff --git a/extensions/pusher/js/src/forum/index.tsx b/extensions/pusher/js/src/forum/index.tsx index 4bced072f0..7d784d06c9 100644 --- a/extensions/pusher/js/src/forum/index.tsx +++ b/extensions/pusher/js/src/forum/index.tsx @@ -1,4 +1,4 @@ -import * as PusherTypes from 'pusher-js'; +import Pusher, { Channel } from 'pusher-js'; import app from 'flarum/forum/app'; import { extend } from 'flarum/common/extend'; import DiscussionList from 'flarum/forum/components/DiscussionList'; @@ -11,19 +11,15 @@ import type Tag from 'ext:flarum/tags/common/models/Tag'; export type PusherBinding = { channels: { - main: PusherTypes.Channel; - user: PusherTypes.Channel | null; + main: Channel; + user: Channel | null; }; - pusher: PusherTypes.default; + pusher: Pusher; }; app.initializers.add('flarum-pusher', () => { app.pusher = (async () => { - // @ts-expect-error - await import('//cdn.jsdelivr.net/npm/pusher-js@7.0.3/dist/web/pusher.min.js' /* webpackIgnore: true, webpackPrefetch: true */); - - // @ts-expect-error Imported dynamically - const socket: PusherTypes.default = new Pusher(app.forum.attribute('pusherKey'), { + const socket: Pusher = new Pusher(app.forum.attribute('pusherKey'), { authEndpoint: `${app.forum.attribute('apiUrl')}/pusher/auth`, cluster: app.forum.attribute('pusherCluster'), auth: { @@ -31,6 +27,8 @@ app.initializers.add('flarum-pusher', () => { 'X-CSRF-Token': app.session.csrfToken, }, }, + httpHost: app.forum.attribute('pusherHostname'), + wsHost: app.forum.attribute('pusherHostname') }); return { diff --git a/extensions/pusher/js/src/forum/shims.d.ts b/extensions/pusher/js/src/forum/shims.d.ts index 72c9790ebd..c4fabe9d52 100644 --- a/extensions/pusher/js/src/forum/shims.d.ts +++ b/extensions/pusher/js/src/forum/shims.d.ts @@ -1,13 +1,13 @@ -import * as PusherTypes from 'pusher-js'; +import Pusher, { Channel } from 'pusher-js'; declare module 'flarum/forum/ForumApplication' { export default interface ForumApplication { pusher: Promise<{ channels: { - main: PusherTypes.Channel; - user: PusherTypes.Channel | null; + main: Channel; + user: Channel | null; }; - pusher: PusherTypes.default; + pusher: Pusher; }>; pushedUpdates: Array; diff --git a/extensions/pusher/src/Api/Controller/AuthController.php b/extensions/pusher/src/Api/Controller/AuthController.php index ce1432a500..956ad645fe 100644 --- a/extensions/pusher/src/Api/Controller/AuthController.php +++ b/extensions/pusher/src/Api/Controller/AuthController.php @@ -36,7 +36,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface $this->settings->get('flarum-pusher.app_key'), $this->settings->get('flarum-pusher.app_secret'), $this->settings->get('flarum-pusher.app_id'), - ['cluster' => $this->settings->get('flarum-pusher.app_cluster')] + [ + 'cluster' => $this->settings->get('flarum-pusher.app_cluster'), + 'host' => $this->settings->get('flarum-pusher.server_hostname'), + ] ); $payload = json_decode($pusher->socket_auth($userChannel, Arr::get($body, 'socket_id')), true); diff --git a/extensions/pusher/src/Provider/PusherProvider.php b/extensions/pusher/src/Provider/PusherProvider.php index 60e5a51aab..38ce61907f 100644 --- a/extensions/pusher/src/Provider/PusherProvider.php +++ b/extensions/pusher/src/Provider/PusherProvider.php @@ -25,6 +25,9 @@ public function register(): void if ($cluster = $settings->get('flarum-pusher.app_cluster')) { $options['cluster'] = $cluster; } + if ($host = $settings->get('flarum-pusher.server_hostname')) { + $options['host'] = $host; + } return new Pusher( $settings->get('flarum-pusher.app_key'),