diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index a568c205f769714702e9f81420de2c623842fd9f..52343f340ec87dcba53cfbc308487bc8eabc4426 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -38,6 +38,7 @@ import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.ForbiddenException; +import de.thm.arsnova.socket.ARSnovaSocketIOServer; @Service public class SessionService implements ISessionService { @@ -49,7 +50,10 @@ public class SessionService implements ISessionService { @Autowired private IUserService userService; - + + @Autowired + private ARSnovaSocketIOServer socketIoServer; + @Autowired(required=false) private ConnectorClient connectorClient; @@ -61,15 +65,16 @@ public class SessionService implements ISessionService { @Authenticated public final Session joinSession(final String keyword) { userService.addCurrentUserToSessionMap(keyword); + socketIoServer.reportActiveUserCountForSession(keyword); + Session session = databaseDao.getSession(keyword); - if (connectorClient != null && session.isCourseSession()) { String courseid = session.getCourseId(); if (!connectorClient.getMembership(userService.getCurrentUser().getUsername(), courseid).isMember()) { throw new ForbiddenException(); } } - + return session; } diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 456123f912b1a0c99f02ba2299caf083dafd12db..5e5eb9eea0b14429f9328a69d4ccb6e31f2751a5 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -54,6 +54,8 @@ public class ARSnovaSocketIOServer { private String storepass; private final Configuration config; private SocketIOServer server; + + private int lastActiveUserCount = 0; public ARSnovaSocketIOServer() { config = new Configuration(); @@ -221,6 +223,10 @@ public class ARSnovaSocketIOServer { public void reportActiveUserCountForSession(String sessionKey) { int count = sessionService.countActiveUsers(sessionKey); + if (count == lastActiveUserCount) { + return; + } + lastActiveUserCount = count; broadcastInSession(sessionKey, "updateActiveUserCount", count); }