ws guard against undefined

This commit is contained in:
Nour Alharithi
2023-12-07 10:32:54 -08:00
parent a6dd60255c
commit 3fa8f35a0b

View File

@@ -97,9 +97,11 @@ async function main() {
redisClient.client.on('message', (subscribedChannel, message) => {
const subscribers = channelSubscribers.get(subscribedChannel);
subscribers.forEach((ws) => {
ws.send(JSON.stringify({ channel: subscribedChannel, data: message }));
});
if (subscribers) {
subscribers.forEach((ws) => {
ws.send(JSON.stringify({ channel: subscribedChannel, data: message }));
});
}
});
redisClient.client.on('error', (error) => {
@@ -180,7 +182,7 @@ async function main() {
lastUpdateChannel
);
if (lastMessage !== null) {
if (lastMessage) {
ws.send(
JSON.stringify({
channel: lastUpdateChannel,