Skip to content

Commit fd18059

Browse files
author
notanothervibecoder
authored
feat: add server hostname configuration for Pusher integration (#4253)
1 parent e65ae18 commit fd18059

File tree

8 files changed

+38
-22
lines changed

8 files changed

+38
-22
lines changed

extensions/pusher/extend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
(new Extend\Settings())
3434
->serializeToForum('pusherKey', 'flarum-pusher.app_key')
35-
->serializeToForum('pusherCluster', 'flarum-pusher.app_cluster'),
35+
->serializeToForum('pusherCluster', 'flarum-pusher.app_cluster')
36+
->serializeToForum('pusherHostname', 'flarum-pusher.server_hostname'),
3637

3738
(new Extend\Event())
3839
->listen(Posted::class, Listener\PushNewPost::class),

extensions/pusher/js/dist-typings/forum/index.d.ts

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/pusher/js/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"typescript-coverage-report": "^0.6.1",
2626
"webpack": "^5.76.0",
2727
"webpack-cli": "^4.9.1"
28+
},
29+
"dependencies": {
30+
"pusher-js": "^8.4.0"
2831
}
2932
}

extensions/pusher/js/src/admin/extend.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,38 @@ export default [
99
label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_id_label'),
1010
type: 'text',
1111
}),
12-
30
12+
40
1313
)
1414
.setting(
1515
() => ({
1616
setting: 'flarum-pusher.app_key',
1717
label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_key_label'),
1818
type: 'text',
1919
}),
20-
20
20+
30
2121
)
2222
.setting(
2323
() => ({
2424
setting: 'flarum-pusher.app_secret',
2525
label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_secret_label'),
2626
type: 'text',
2727
}),
28-
10
28+
20
2929
)
3030
.setting(
3131
() => ({
3232
setting: 'flarum-pusher.app_cluster',
3333
label: app.translator.trans('flarum-pusher.admin.pusher_settings.app_cluster_label'),
3434
type: 'text',
3535
}),
36+
10
37+
)
38+
.setting(
39+
() => ({
40+
setting: 'flarum-pusher.server_hostname',
41+
label: app.translator.trans('flarum-pusher.admin.pusher_settings.server_hostname_label'),
42+
type: 'text',
43+
}),
3644
0
3745
),
3846
];

extensions/pusher/js/src/forum/index.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as PusherTypes from 'pusher-js';
1+
import Pusher, { Channel } from 'pusher-js';
22
import app from 'flarum/forum/app';
33
import { extend } from 'flarum/common/extend';
44
import DiscussionList from 'flarum/forum/components/DiscussionList';
@@ -11,26 +11,24 @@ import type Tag from 'ext:flarum/tags/common/models/Tag';
1111

1212
export type PusherBinding = {
1313
channels: {
14-
main: PusherTypes.Channel;
15-
user: PusherTypes.Channel | null;
14+
main: Channel;
15+
user: Channel | null;
1616
};
17-
pusher: PusherTypes.default;
17+
pusher: Pusher;
1818
};
1919

2020
app.initializers.add('flarum-pusher', () => {
2121
app.pusher = (async () => {
22-
// @ts-expect-error
23-
await import('//cdn.jsdelivr.net/npm/[email protected]/dist/web/pusher.min.js' /* webpackIgnore: true, webpackPrefetch: true */);
24-
25-
// @ts-expect-error Imported dynamically
26-
const socket: PusherTypes.default = new Pusher(app.forum.attribute('pusherKey'), {
22+
const socket: Pusher = new Pusher(app.forum.attribute('pusherKey'), {
2723
authEndpoint: `${app.forum.attribute('apiUrl')}/pusher/auth`,
2824
cluster: app.forum.attribute('pusherCluster'),
2925
auth: {
3026
headers: {
3127
'X-CSRF-Token': app.session.csrfToken,
3228
},
3329
},
30+
httpHost: app.forum.attribute('pusherHostname'),
31+
wsHost: app.forum.attribute('pusherHostname')
3432
});
3533

3634
return {

extensions/pusher/js/src/forum/shims.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import * as PusherTypes from 'pusher-js';
1+
import Pusher, { Channel } from 'pusher-js';
22

33
declare module 'flarum/forum/ForumApplication' {
44
export default interface ForumApplication {
55
pusher: Promise<{
66
channels: {
7-
main: PusherTypes.Channel;
8-
user: PusherTypes.Channel | null;
7+
main: Channel;
8+
user: Channel | null;
99
};
10-
pusher: PusherTypes.default;
10+
pusher: Pusher;
1111
}>;
1212

1313
pushedUpdates: Array<any>;

extensions/pusher/src/Api/Controller/AuthController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3636
$this->settings->get('flarum-pusher.app_key'),
3737
$this->settings->get('flarum-pusher.app_secret'),
3838
$this->settings->get('flarum-pusher.app_id'),
39-
['cluster' => $this->settings->get('flarum-pusher.app_cluster')]
39+
[
40+
'cluster' => $this->settings->get('flarum-pusher.app_cluster'),
41+
'host' => $this->settings->get('flarum-pusher.server_hostname'),
42+
]
4043
);
4144

4245
$payload = json_decode($pusher->socket_auth($userChannel, Arr::get($body, 'socket_id')), true);

extensions/pusher/src/Provider/PusherProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function register(): void
2525
if ($cluster = $settings->get('flarum-pusher.app_cluster')) {
2626
$options['cluster'] = $cluster;
2727
}
28+
if ($host = $settings->get('flarum-pusher.server_hostname')) {
29+
$options['host'] = $host;
30+
}
2831

2932
return new Pusher(
3033
$settings->get('flarum-pusher.app_key'),

0 commit comments

Comments
 (0)