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