Skip to content

Commit bf94c7d

Browse files
committed
Immediate: fix annoying bug that causes cameras and microphones to stay visible to other users.
1 parent 0318493 commit bf94c7d

6 files changed

Lines changed: 42 additions & 18 deletions

File tree

server-src/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,21 @@ async function startRoomWSS(roomid) {
22752275
}
22762276
wss._rrPeopleCount += 1;
22772277
ws.on("close", () => {
2278+
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+
});
22782293
clearTimeout(ws._rrkeepAliveTimeout);
22792294
clearInterval(roomCheckInterval);
22802295
wss._rrPeopleCount -= 1;

src/chat/interface/chatinterface.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ require("./darktheme.js");
453453
microphones.end(json.id);
454454
}
455455
}
456+
if (json.type == "userLeft") {
457+
microphones.end(json.id);
458+
cameras.hide(json.id);
459+
}
456460
if (json.type == "ready") {
457461
loadingScreen.hidden = true;
458462
mainScreen.hidden = false;

src/chat/interface/microphones.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,7 @@ microphones.end = function (id) {
9696
//Dispose of the userMicrophone.
9797
userMicrophones[id] = undefined;
9898

99-
//Just to make sure its actually disposed, filter out any empty values in userMicrophones.
100-
var newObjects = {};
101-
for (var id of Object.keys(userMicrophones)) {
102-
if (userMicrophones[id]) {
103-
newObjects[id] = userMicrophones[id];
104-
}
105-
}
106-
userMicrophones = newObjects;
99+
delete userMicrophones[id];
107100
}
108101
};
109102

src/chat/interface/notify.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,31 @@ notify.requestPermission = async function () {
1010
} catch (e) {}
1111
};
1212

13-
notify.sendIfNotOnScreen = function (tag, message, title = "Random Rants +") {
14-
if (!asked) {
15-
return;
16-
}
13+
notify.sendIfNotOnScreen = function (tag, body, title = "Random Rants +") {
1714
if (document.visibilityState !== "visible") {
1815
if (lastNotifcation) {
1916
try {
2017
lastNotifcation.close();
2118
} catch (e) {}
2219
}
23-
lastNotifcation = new Notification(title, {
24-
icon: "favicon.png",
25-
tag: tag,
26-
body: message,
27-
});
20+
try {
21+
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
22+
navigator.serviceWorker.controller.postMessage({
23+
type: "NOTIFY",
24+
payload: {
25+
title,
26+
body,
27+
tag,
28+
},
29+
});
30+
} else {
31+
lastNotifcation = new Notification(title, {
32+
icon: "favicon.png",
33+
tag: tag,
34+
body: message,
35+
});
36+
}
37+
} catch (e) {}
2838
}
2939
};
3040

src/serviceworker/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ self.addEventListener("message", async (event) => {
155155
var cache = await caches.open("rr-meta");
156156
// Save the current timestamp
157157
await cache.put("last-seen-online", new Response(Date.now().toString()));
158+
} else if (event.data && event.data.type === "NOTIFY") {
159+
await sendPushNotification(event.data.payload);
158160
}
159161
});
160162

wpstatic/version.json

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

0 commit comments

Comments
 (0)