From eb56edc1dc0e4c1d39c39bb1e93aa3cf9f1310df Mon Sep 17 00:00:00 2001 From: Alexander Tim Hobelsberger <alexander_tim.hobelsberger@student.reutlingen-university.de> Date: Sun, 18 Dec 2022 17:08:10 +0100 Subject: [PATCH] socket.emit --- index.js | 7 ++++--- nginx/nginx.conf | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e867d23..1cb0393 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ const io = new Server(server, { cors: { origin: "*", methods: ["GET", "POST"], + transports: ['websocket', 'polling'], credentials: true } }); @@ -36,7 +37,7 @@ const redis = require('socket.io-redis'); const { createAdapter } = require('@socket.io/redis-adapter'); const { createClient } = require('redis'); -const pubClient = createClient({ host: '127.0.0.1', port: 6379 }); +const pubClient = createClient({ url: "redis://192.168.0.230:6379" }); const subClient = pubClient.duplicate(); io.adapter(createAdapter(pubClient, subClient)); @@ -236,7 +237,7 @@ async function addUserToActiveUsers(response, socket) { var userArr = Array.from(activeUsers.values()); //console.log(userArr); - io.emit('updateUserlist', { + socket.emit('updateUserlist', { userList : userArr }); }); @@ -264,7 +265,7 @@ async function deleteUserFromActiveUsers(response, socket) { clientActiveUsers.set(activeUsers.size); var userArr = Array.from(activeUsers.values()); - io.emit('updateUserlist', { + socket.emit('updateUserlist', { userList : userArr }); }); diff --git a/nginx/nginx.conf b/nginx/nginx.conf index cdcc278..514d398 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -26,7 +26,7 @@ http { upstream nodes { # enable sticky session with either "hash" (uses the complete IP address) - #hash $remote_addr consistent; + hash $remote_addr consistent; # least_conn; # or "ip_hash" (uses the first three octets of the client IPv4 address, or the entire IPv6 address) # ip_hash; -- GitLab