u-wave-announce 0.6.0-alpha.2 → 0.6.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/plugin.js +63 -28
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "u-wave-announce",
|
|
3
3
|
"description": "Announce your üWave server's existence to the world.",
|
|
4
|
-
"version": "0.6.0-alpha.
|
|
4
|
+
"version": "0.6.0-alpha.4",
|
|
5
5
|
"author": "Renée Kooi <renee@kooi.me>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"libsodium-wrappers": "^0.8.
|
|
9
|
-
"node-fetch": "^3.3.1",
|
|
8
|
+
"libsodium-wrappers": "^0.8.4",
|
|
10
9
|
"strip-indent": "^4.0.0"
|
|
11
10
|
},
|
|
12
11
|
"engines": {
|
package/src/plugin.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
2
|
import stripIndent from 'strip-indent';
|
|
4
3
|
import pkg from '../package.json' with { type: 'json' };
|
|
5
4
|
import * as sodium from './signatures.js';
|
|
@@ -7,7 +6,8 @@ import * as sodium from './signatures.js';
|
|
|
7
6
|
const optionsSchema = {
|
|
8
7
|
type: 'object',
|
|
9
8
|
title: 'Announce',
|
|
10
|
-
description:
|
|
9
|
+
description:
|
|
10
|
+
'Options for publically announcing this server. Announcing allows users to find this server on "Hubs", such as https://hub.u-wave.net.',
|
|
11
11
|
'uw:key': 'u-wave:announce',
|
|
12
12
|
properties: {
|
|
13
13
|
enabled: {
|
|
@@ -31,7 +31,7 @@ const optionsSchema = {
|
|
|
31
31
|
subtitle: {
|
|
32
32
|
type: 'string',
|
|
33
33
|
title: 'Tagline',
|
|
34
|
-
description:
|
|
34
|
+
description: "A short description of the server's purpose, up to about 30 characters.",
|
|
35
35
|
examples: [
|
|
36
36
|
'EDM and more!',
|
|
37
37
|
'International K-Pop Community',
|
|
@@ -56,19 +56,22 @@ const optionsSchema = {
|
|
|
56
56
|
type: 'string',
|
|
57
57
|
format: 'uri',
|
|
58
58
|
title: 'WebSocket URL',
|
|
59
|
-
description:
|
|
59
|
+
description:
|
|
60
|
+
'A WebSocket endpoint URL for your server. This defaults to `url` with the ws:// or wss:// protocol, so this almost never has to be set.',
|
|
60
61
|
},
|
|
61
62
|
apiUrl: {
|
|
62
63
|
type: 'string',
|
|
63
64
|
format: 'uri',
|
|
64
65
|
title: 'API URL',
|
|
65
|
-
description:
|
|
66
|
+
description:
|
|
67
|
+
'The base URL for the HTTP API your server. This defaults to `url` + /v1, so this almost never has to be set.',
|
|
66
68
|
},
|
|
67
69
|
hub: {
|
|
68
70
|
type: 'string',
|
|
69
71
|
format: 'uri',
|
|
70
72
|
title: 'Hub URL',
|
|
71
|
-
description:
|
|
73
|
+
description:
|
|
74
|
+
'The announce server to announce to. Uses https://announce.u-wave.net, the server behind https://hub.u-wave.net, by default.',
|
|
72
75
|
default: 'https://announce.u-wave.net',
|
|
73
76
|
},
|
|
74
77
|
},
|
|
@@ -91,31 +94,57 @@ async function getAnnounceData(uw, options) {
|
|
|
91
94
|
|
|
92
95
|
const entry = await uw.booth.getCurrentEntry();
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
let usersCount = 0;
|
|
98
|
+
let booth = null;
|
|
99
|
+
|
|
100
|
+
if (uw.redis) {
|
|
101
|
+
const onlineUserIDs = await uw.redis.lrange('users', 0, -1);
|
|
102
|
+
usersCount = new Set(onlineUserIDs).size;
|
|
103
|
+
|
|
104
|
+
if (entry != null) {
|
|
105
|
+
booth = {
|
|
106
|
+
media: {
|
|
107
|
+
artist: entry.media.artist,
|
|
108
|
+
title: entry.media.title,
|
|
109
|
+
thumbnail: entry.media.media.thumbnail,
|
|
110
|
+
},
|
|
111
|
+
dj: entry.user
|
|
112
|
+
? {
|
|
113
|
+
username: entry.user.username,
|
|
114
|
+
}
|
|
115
|
+
: null,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
// TODO add something to üWave Core so we don't have to manually ask
|
|
120
|
+
// Redis/SQLite for this information. Currently üWave Core may register
|
|
121
|
+
// duplicates in this list, too, which is a bit annoying!
|
|
122
|
+
// TODO add guest users here too.
|
|
123
|
+
const onlineUserIDs = await uw.keyv.get('users');
|
|
124
|
+
usersCount = new Set(onlineUserIDs).size;
|
|
125
|
+
|
|
126
|
+
if (entry != null) {
|
|
127
|
+
booth = {
|
|
128
|
+
media: {
|
|
129
|
+
artist: entry.historyEntry.artist,
|
|
130
|
+
title: entry.historyEntry.title,
|
|
131
|
+
thumbnail: entry.media.thumbnail,
|
|
132
|
+
},
|
|
133
|
+
dj: entry.user
|
|
134
|
+
? {
|
|
135
|
+
username: entry.user.username,
|
|
136
|
+
}
|
|
137
|
+
: null,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
100
141
|
|
|
101
142
|
return {
|
|
102
143
|
name: options.name,
|
|
103
144
|
subtitle: options.subtitle,
|
|
104
145
|
description: options.description ? stripIndent(options.description) : null,
|
|
105
|
-
|
|
106
|
-
booth: entry ? {
|
|
107
|
-
media: {
|
|
108
|
-
artist: entry.media.artist,
|
|
109
|
-
title: entry.media.title,
|
|
110
|
-
thumbnail: entry.media.media.thumbnail,
|
|
111
|
-
},
|
|
112
|
-
dj: entry.user ? {
|
|
113
|
-
username: entry.user.username,
|
|
114
|
-
} : null,
|
|
115
|
-
} : null,
|
|
116
|
-
|
|
146
|
+
booth,
|
|
117
147
|
usersCount,
|
|
118
|
-
|
|
119
148
|
url,
|
|
120
149
|
// Derive URLs if not given.
|
|
121
150
|
apiUrl: options.apiUrl || `${url}/v1`,
|
|
@@ -193,9 +222,15 @@ async function announcePlugin(uw, staticOptions) {
|
|
|
193
222
|
});
|
|
194
223
|
|
|
195
224
|
// Announce again every time the song changes.
|
|
196
|
-
uw.
|
|
197
|
-
|
|
198
|
-
|
|
225
|
+
if (uw.events) {
|
|
226
|
+
uw.events.on('advance:complete', () => {
|
|
227
|
+
announce().catch(onError);
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
uw.on('advance', () => {
|
|
231
|
+
announce().catch(onError);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
199
234
|
|
|
200
235
|
uw.onClose(() => {
|
|
201
236
|
clearInterval(interval);
|