Skip to content
Snippets Groups Projects
Commit 690d63f8 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Use event publisher to send websocket events

With this patch, websocket feedback data will be send without using
UserService arrays within ARSnovaSocketIOServer except
reportDeletedFeedback().
parent 1c3757b4
No related merge requests found
......@@ -33,6 +33,8 @@ import org.springframework.stereotype.Service;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.events.ARSnovaEvent;
import de.thm.arsnova.events.Publisher;
import de.thm.arsnova.exceptions.NoContentException;
import de.thm.arsnova.socket.ARSnovaSocketIOServer;
......
......@@ -24,6 +24,7 @@ import com.corundumstudio.socketio.listener.DisconnectListener;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.events.ARSnovaEvent;
import de.thm.arsnova.events.Publisher;
import de.thm.arsnova.exceptions.NoContentException;
import de.thm.arsnova.services.IFeedbackService;
import de.thm.arsnova.services.IQuestionService;
......@@ -46,6 +47,9 @@ public class ARSnovaSocketIOServer {
@Autowired
private ISessionService sessionService;
@Autowired
private Publisher publisher;
private static final Logger LOGGER = LoggerFactory.getLogger(ARSnovaSocketIOServer.class);
private int portNumber;
......@@ -231,12 +235,15 @@ public class ARSnovaSocketIOServer {
public void reportUpdatedFeedbackForSession(String sessionKey) {
de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey);
broadcastInSession(sessionKey, "feedbackData", fb.getValues());
publisher.publish(new ARSnovaEvent(this, sessionKey, "feedbackData", fb.getValues()));
//broadcastInSession(sessionKey, "feedbackData", fb.getValues());
try {
long averageFeedback = feedbackService.getAverageFeedbackRounded(sessionKey);
broadcastInSession(sessionKey, "feedbackDataRoundedAverage", averageFeedback);
publisher.publish(new ARSnovaEvent(this, sessionKey, "feedbackDataRoundedAverage", averageFeedback));
//broadcastInSession(sessionKey, "feedbackDataRoundedAverage", averageFeedback);
} catch (NoContentException e) {
broadcastInSession(sessionKey, "feedbackDataRoundedAverage", null);
publisher.publish(new ARSnovaEvent(this, sessionKey, "feedbackDataRoundedAverage", null));
//broadcastInSession(sessionKey, "feedbackDataRoundedAverage", null);
}
}
......@@ -253,12 +260,15 @@ public class ARSnovaSocketIOServer {
return;
}
for (SocketIOClient client : server.getAllClients()) {
publisher.publish(new ARSnovaEvent(this, user, "feedbackData", fb.getValues()));
publisher.publish(new ARSnovaEvent(this, user, "feedbackDataRoundedAverage", averageFeedback));
/*for (SocketIOClient client : server.getAllClients()) {
if (connectionIds.contains(client.getSessionId())) {
client.sendEvent("feedbackData", fb.getValues());
client.sendEvent("feedbackDataRoundedAverage", averageFeedback);
}
}
}*/
}
public void reportActiveUserCountForSession(String sessionKey) {
......@@ -268,22 +278,26 @@ public class ARSnovaSocketIOServer {
return;
}
lastActiveUserCount = count;
broadcastInSession(sessionKey, "activeUserCountData", count);
publisher.publish(new ARSnovaEvent(this, sessionKey, "activeUserCountData", count));
//broadcastInSession(sessionKey, "activeUserCountData", count);
}
public void reportAnswersToLecturerQuestionAvailable(String sessionKey, String lecturerQuestionId) {
broadcastInSession(sessionKey, "answersToLecQuestionAvail", lecturerQuestionId);
publisher.publish(new ARSnovaEvent(this, sessionKey, "answersToLecQuestionAvail", lecturerQuestionId));
//broadcastInSession(sessionKey, "answersToLecQuestionAvail", lecturerQuestionId);
}
public void reportAudienceQuestionAvailable(String sessionKey, String audienceQuestionId) {
/* TODO role handling implementation, send this only to users with role lecturer */
broadcastInSession(sessionKey, "audQuestionAvail", audienceQuestionId);
publisher.publish(new ARSnovaEvent(this, sessionKey, "audQuestionAvail", audienceQuestionId));
//broadcastInSession(sessionKey, "audQuestionAvail", audienceQuestionId);
}
public void reportLecturerQuestionAvailable(String sessionKey, String lecturerQuestionId) {
/* TODO role handling implementation, send this only to users with role audience */
broadcastInSession(sessionKey, "lecQuestionAvail", lecturerQuestionId);
publisher.publish(new ARSnovaEvent(this, sessionKey, "lecQuestionAvail", lecturerQuestionId));
//broadcastInSession(sessionKey, "lecQuestionAvail", lecturerQuestionId);
}
/** Sends event to a websocket connection identified by UUID
......@@ -294,25 +308,9 @@ public class ARSnovaSocketIOServer {
public void sendToClient(UUID sessionId, ARSnovaEvent event) {
for (SocketIOClient c : server.getAllClients()) {
if (c.getSessionId().equals(sessionId)) {
System.out.println(sessionId);
c.sendEvent(event.getEventName(), event.getData());
break;
}
}
}
public void broadcastInSession(String sessionKey, String eventName, Object data) {
/**
* collect a list of users which are in the current session iterate over
* all connected clients and if send feedback, if user is in current
* session
*/
Set<User> users = userService.getUsersInSession(sessionKey);
for (SocketIOClient c : server.getAllClients()) {
User u = userService.getUser2SocketId(c.getSessionId());
if (u != null && users.contains(u)) {
c.sendEvent(eventName, data);
}
}
}
}
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