aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-07 23:58:00 +0300
committerGravatar Vitaly Takmazov2018-10-09 13:10:00 +0300
commit8fa7260a5bbf332312fa3ba77e2a60d8b60054ac (patch)
tree5f1b8f3ee4a9a52332f6ddf433739b258b4b3bdf /juick-server/src/main/java/com/juick/server/api
parentb664517144d3a82fc1b7951f83751cec1174959d (diff)
Server Side Events: server and webapp
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Service.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Service.java b/juick-server/src/main/java/com/juick/server/api/Service.java
index 41f05f97..2351c076 100644
--- a/juick-server/src/main/java/com/juick/server/api/Service.java
+++ b/juick-server/src/main/java/com/juick/server/api/Service.java
@@ -3,6 +3,7 @@ package com.juick.server.api;
import com.juick.User;
import com.juick.server.CommandsManager;
import com.juick.server.EmailManager;
+import com.juick.server.ServerManager;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.UserUtils;
import com.juick.service.EmailService;
@@ -17,8 +18,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
@@ -50,6 +53,8 @@ public class Service {
private String tmpDir;
@Value("${banned_emails:}")
private String[] ignoredEmails;
+ @Inject
+ private ServerManager serverManager;
Session session = Session.getDefaultInstance(new Properties());
@@ -131,4 +136,15 @@ public class Service {
throw new HttpForbiddenException();
}
}
+ @GetMapping("/api/events")
+ public SseEmitter handle() {
+ logger.info("{} connected", UserUtils.getCurrentUser().getName());
+ SseEmitter emitter = new SseEmitter(86400000L);
+ serverManager.getSessions().add(new ServerManager.EventSession(UserUtils.getCurrentUser(), emitter));
+
+ emitter.onCompletion(() -> serverManager.getSessions().remove(emitter));
+ emitter.onTimeout(() -> serverManager.getSessions().remove(emitter));
+
+ return emitter;
+ }
}