Skip to content
Snippets Groups Projects
Commit 5391c08a authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Improve active user count handling

parent 1445b6e9
No related merge requests found
...@@ -56,8 +56,6 @@ public class ARSnovaSocketIOServer { ...@@ -56,8 +56,6 @@ public class ARSnovaSocketIOServer {
private final Configuration config; private final Configuration config;
private SocketIOServer server; private SocketIOServer server;
private int lastActiveUserCount = 0;
public ARSnovaSocketIOServer() { public ARSnovaSocketIOServer() {
config = new Configuration(); config = new Configuration();
} }
...@@ -112,6 +110,15 @@ public class ARSnovaSocketIOServer { ...@@ -112,6 +110,15 @@ public class ARSnovaSocketIOServer {
server.addEventListener("setSession", Session.class, new DataListener<Session>() { server.addEventListener("setSession", Session.class, new DataListener<Session>() {
@Override @Override
public void onData(SocketIOClient client, Session session, AckRequest ackSender) { public void onData(SocketIOClient client, Session session, AckRequest ackSender) {
User u = userService.getUser2SocketId(client.getSessionId());
String oldSessionKey = userService.getSessionForUser(u.getUsername());
if (session.getKeyword() == oldSessionKey) {
return;
}
if (null != oldSessionKey) {
reportActiveUserCountForSession(oldSessionKey);
}
if (null != sessionService.joinSession(session.getKeyword(), client.getSessionId())) { if (null != sessionService.joinSession(session.getKeyword(), client.getSessionId())) {
/* active user count has to be sent to the client since the broadcast is /* active user count has to be sent to the client since the broadcast is
* not always sent as long as the polling solution is active simultaneously */ * not always sent as long as the polling solution is active simultaneously */
...@@ -282,10 +289,6 @@ public class ARSnovaSocketIOServer { ...@@ -282,10 +289,6 @@ public class ARSnovaSocketIOServer {
public void reportActiveUserCountForSession(String sessionKey) { public void reportActiveUserCountForSession(String sessionKey) {
/* This check is needed as long as the HTTP polling solution is active simultaneously. */ /* This check is needed as long as the HTTP polling solution is active simultaneously. */
int count = userService.getUsersInSessionCount(sessionKey); int count = userService.getUsersInSessionCount(sessionKey);
if (count == lastActiveUserCount) {
return;
}
lastActiveUserCount = count;
broadcastInSession(sessionKey, "activeUserCountData", count); broadcastInSession(sessionKey, "activeUserCountData", count);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment