Skip to content

Commit 1d24de0

Browse files
committed
Immediate: the fix to the annoying camera and mic bug, plus notification updates for chat messages.
1 parent 70133b3 commit 1d24de0

9 files changed

Lines changed: 106 additions & 36 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,44 @@ Want to run your own instance? Follow these steps.
3131

3232
### 1. Prerequisites: Supabase
3333
**Do not skip this.** You must create a Supabase project to run the server.
34+
35+
_(Create a .env file if you don't want to add enviroment variables to your machine)_
36+
3437
Create a project at [supabase.com](https://supabase.com) and gather the following environment variables:
3538

3639
* `sbBucket`: Your Supabase storage bucket name.
3740
* `sbAPIKey`: Your Supabase Secret Key (recommended) or API Key.
3841
* `sbURL`: Your Supabase project URL (e.g., `https://projectid.supabase.co`).
3942

43+
**DO NOT SHARE SUPABASE STORAGE API KEYS AND URLS**, these must remain private so that people don't sneak in and change the account data.
44+
45+
#### 1.2 Enviroment variables for Push Notifications.
46+
47+
This step is optional but highly recommended now. If skipped, push notificiations will not work:
48+
49+
Run the terminal command (tested only in github codespaces) to generate the keys: `npm run webpush` or `yarn webpush`.
50+
51+
Example output:
52+
```
53+
=======================================
54+
55+
Public Key:
56+
<YOUR PUSH NOTIFICATIONS PUBLIC KEY>
57+
58+
Private Key:
59+
<YOUR PUSH NOTIFICATIONS PRIVATE KEY>
60+
61+
=======================================
62+
```
63+
64+
Add these enviroment variables:
65+
66+
* `pushWebsite`: The website the server is accesible on. (OPTIONAL, defaults to the random rants + website)
67+
68+
* `publicPushKey`: The public push notifcations key that was in the output of the command above.
69+
70+
* `privatePushKey`: The private push notifcations key that was in the output of the command above. (DO NOT SHARE THE KEY)
71+
4072
### 2. Local Setup
4173
I recommend using **Node.js 16.x**.
4274

server-src/server.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,20 +2276,20 @@ async function startRoomWSS(roomid) {
22762276
wss._rrPeopleCount += 1;
22772277
ws.on("close", () => {
22782278
wss.clients.forEach((cli) => {
2279-
if (!cli._rrIsReady) {
2280-
return;
2281-
}
2282-
cli.send(
2283-
JSON.stringify({
2284-
type: "userLeft",
2285-
username: ws._rrUsername,
2286-
displayName: displayName,
2287-
color: ws._rrUserColor,
2288-
font: ws._rrUserFont,
2289-
id: ws._rrConnectionID,
2290-
}),
2291-
);
2292-
});
2279+
if (!cli._rrIsReady) {
2280+
return;
2281+
}
2282+
cli.send(
2283+
JSON.stringify({
2284+
type: "userLeft",
2285+
username: ws._rrUsername,
2286+
displayName: displayName,
2287+
color: ws._rrUserColor,
2288+
font: ws._rrUserFont,
2289+
id: ws._rrConnectionID,
2290+
}),
2291+
);
2292+
});
22932293
clearTimeout(ws._rrkeepAliveTimeout);
22942294
clearInterval(roomCheckInterval);
22952295
wss._rrPeopleCount -= 1;
@@ -5472,14 +5472,15 @@ setInterval(() => {
54725472
debugLogOnlineSockets();
54735473
}, 2000);*/
54745474

5475-
/*setInterval(() => {
5476-
for (var username of Object.keys(notificationsForUsers)) {
5477-
sendNotify(username, {
5475+
/*
5476+
setInterval(() => {
5477+
var username = "gvbvdxx";
5478+
sendNotify(username, {
54785479
type: "test",
54795480
});
54805481
console.log("Send to: " + username);
5481-
}
5482-
}, 5000);*/
5482+
}, 5000);
5483+
*/
54835484

54845485
var serverPort = 3000;
54855486
if (process.env.serverPort) {

src/botcheckinterface.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class BotCheckDiv {
55
constructor() {
66
var _this = this;
77
this.created = false;
8+
this.verified = false;
9+
this.onVerifyScreen = false;
810
this.jsonElement = {
911
element: "div",
1012
children: [
@@ -25,6 +27,8 @@ class BotCheckDiv {
2527
}
2628

2729
_botVerificationPassedScreen() {
30+
this.verified = true;
31+
this.onVerifyScreen = false;
2832
var divElm = this.divElm;
2933
var _this = this;
3034

@@ -54,6 +58,7 @@ class BotCheckDiv {
5458
}
5559

5660
_botVerificationFailedScreen() {
61+
this.onVerifyScreen = false;
5762
var divElm = this.divElm;
5863
var _this = this;
5964

@@ -76,9 +81,11 @@ class BotCheckDiv {
7681
}
7782

7883
_botVerificationScreen() {
84+
this.onVerifyScreen = true;
7985
var divElm = this.divElm;
8086
var _this = this;
8187
var checkID = this.checkID;
88+
this.verified = false;
8289

8390
var codeInput = null;
8491
var buttonElement = null;
@@ -218,7 +225,10 @@ class BotCheckDiv {
218225
}
219226

220227
async _loadID() {
228+
this.onVerifyScreen = false;
221229
var divElm = this.divElm;
230+
divElm.onclick = function () {};
231+
divElm.className = "botCheckDiv";
222232
elements.setInnerJSON(divElm, [
223233
{
224234
element: "div",
@@ -265,14 +275,20 @@ class BotCheckDiv {
265275
}
266276
}
267277

278+
handleTabTo() {
279+
if (!this.onVerifyScreen && !this.verified) {
280+
this.divElm.focus();
281+
this._loadID();
282+
}
283+
}
284+
268285
reset() {
286+
this.onVerifyScreen = false;
287+
this.verified = false;
269288
var divElm = this.divElm;
270289
var _this = this;
271290

272291
divElm.onclick = async function () {
273-
divElm.onclick = function () {};
274-
divElm.className = "botCheckDiv";
275-
276292
await _this._loadID();
277293
};
278294
elements.setInnerJSON(divElm, [
@@ -292,12 +308,6 @@ class BotCheckDiv {
292308
this.reset();
293309
}
294310

295-
click() {
296-
if (this.created) {
297-
this.divElm.click();
298-
}
299-
}
300-
301311
getCheckID() {
302312
return this.checkID;
303313
}

src/chat/interface/chatinterface.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,11 @@ require("./darktheme.js");
541541
}
542542
if (clientSettings.getSetting("CHAT_NOTIFY")) {
543543
notify.sendIfNotOnScreen(
544-
"New message",
544+
`new-message-${json.username || "unknown"}`,
545545
`${json.displayName}: ${shtml.bracketCodeRemoval(json.message)}`,
546-
"New message",
546+
json.username
547+
? "New message from @" + json.username
548+
: "New message",
547549
);
548550
}
549551
}

src/chat/interface/notify.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ notify.sendIfNotOnScreen = function (tag, body, title = "Random Rants +") {
2525
title,
2626
body,
2727
tag,
28+
data: {
29+
targetURL: window.location.href,
30+
},
2831
},
2932
});
3033
} else {

src/pages/signin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ usernameInput.addEventListener("keydown", function (e) {
118118

119119
passwordInput.addEventListener("keydown", function (e) {
120120
if (e.key == "Enter") {
121-
botCheck.click();
121+
botCheck.handleTabTo();
122122
}
123123
});

src/pages/signup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ usernameInput.addEventListener("keydown", function (e) {
157157

158158
passwordInput.addEventListener("keydown", function (e) {
159159
if (e.key == "Enter") {
160-
botCheck.click();
160+
botCheck.handleTabTo();
161161
}
162162
});

src/serviceworker/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const CHAT_PATH = "/chat";
22
const APP_NAME = "Random Rants +";
3-
const DEFAULT_TAG = "randomrants-plus";
3+
const DEFAULT_TAG_PREFIX = "randomrants-plus";
44

55
var origin = "" + self.location.origin;
66
origin = origin.trim();
@@ -21,9 +21,12 @@ async function sendPushNotification({
2121
title = APP_NAME,
2222
body = "",
2323
icon = "/images/push-notify-icon.png",
24-
tag = DEFAULT_TAG,
24+
tag = DEFAULT_TAG_PREFIX,
2525
data = {},
2626
}) {
27+
if (tag == DEFAULT_TAG_PREFIX) {
28+
tag += "-" + Date.now();
29+
}
2730
await self.registration.showNotification(title, {
2831
body: body,
2932
icon: icon,
@@ -156,7 +159,9 @@ self.addEventListener("message", async (event) => {
156159
// Save the current timestamp
157160
await cache.put("last-seen-online", new Response(Date.now().toString()));
158161
} else if (event.data && event.data.type === "NOTIFY") {
159-
await sendPushNotification(event.data.payload);
162+
if (await isUserSubscribed()) {
163+
await sendPushNotification(event.data.payload);
164+
}
160165
}
161166
});
162167

@@ -191,6 +196,23 @@ self.addEventListener("activate", (event) => {
191196
event.waitUntil(async () => {
192197
await clients.claim();
193198

199+
// Check for "Ghost" registrations
200+
const registrations = (await self.registration.navigationPreload.getState())
201+
? [] // Preload check
202+
: await self.registration.scope;
203+
204+
const allRegs = (await self.registration.getRegistrations)
205+
? await self.registration.getRegistrations()
206+
: [];
207+
208+
for (let reg of allRegs) {
209+
// If there is another worker with a different scope, kill it
210+
if (reg.scope !== self.registration.scope) {
211+
console.warn("Killing duplicate worker at scope:", reg.scope);
212+
await reg.unregister();
213+
}
214+
}
215+
194216
if (!(await isUserSubscribed())) {
195217
return;
196218
}

wpstatic/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"timestamp":"1770907446166"}
1+
{"timestamp":"1770911428376"}

0 commit comments

Comments
 (0)