Skip to content
Snippets Groups Projects
Commit ae51cc81 authored by Sven Kästle's avatar Sven Kästle
Browse files

feat: Add targetId to AnnotationMessage and Implement WebSocket logic

parent 5e8da014
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ package unipotsdam.gf.modules.annotation.model; ...@@ -3,6 +3,7 @@ package unipotsdam.gf.modules.annotation.model;
public class AnnotationMessage { public class AnnotationMessage {
// variables // variables
private String from; private String from;
private String targetId;
private AnnotationMessageType type; private AnnotationMessageType type;
private String annotationId; private String annotationId;
...@@ -20,6 +21,14 @@ public class AnnotationMessage { ...@@ -20,6 +21,14 @@ public class AnnotationMessage {
this.from = from; this.from = from;
} }
public String getTargetId() {
return targetId;
}
public void setTargetId(String targetId) {
this.targetId = targetId;
}
public AnnotationMessageType getType() { public AnnotationMessageType getType() {
return type; return type;
} }
...@@ -40,6 +49,7 @@ public class AnnotationMessage { ...@@ -40,6 +49,7 @@ public class AnnotationMessage {
public String toString() { public String toString() {
return "AnnotationMessage{" + return "AnnotationMessage{" +
"from='" + from + '\'' + "from='" + from + '\'' +
", targetId='" + targetId + '\'' +
", type=" + type + ", type=" + type +
", annotationId='" + annotationId + '\'' + ", annotationId='" + annotationId + '\'' +
'}'; '}';
......
...@@ -29,7 +29,8 @@ public class AnnotationWebSocketEndpoint { ...@@ -29,7 +29,8 @@ public class AnnotationWebSocketEndpoint {
@OnMessage @OnMessage
public void onMessage(Session session, AnnotationMessage annotationMessage) throws IOException, EncodeException { public void onMessage(Session session, AnnotationMessage annotationMessage) throws IOException, EncodeException {
annotationMessage.setFrom(targets.get(session.getId())); annotationMessage.setTargetId(targets.get(session.getId()));
annotationMessage.setFrom(session.getId());
broadcast(annotationMessage); broadcast(annotationMessage);
} }
...@@ -48,7 +49,9 @@ public class AnnotationWebSocketEndpoint { ...@@ -48,7 +49,9 @@ public class AnnotationWebSocketEndpoint {
endpoints.forEach(endpoint -> { endpoints.forEach(endpoint -> {
synchronized (endpoint) { synchronized (endpoint) {
try { try {
if (targets.get(endpoint.session.getId()).equals(annotationMessage.getFrom())) { if (targets.get(endpoint.session.getId()).equals(annotationMessage.getTargetId())
&& !endpoint.session.getId().equals(annotationMessage.getFrom())) {
System.out.println("Send message to session" + endpoint.session.getId() + " from session " + annotationMessage.getFrom());
endpoint.session.getBasicRemote().sendObject(annotationMessage); endpoint.session.getBasicRemote().sendObject(annotationMessage);
} }
} }
......
...@@ -166,6 +166,8 @@ $(document).ready(function() { ...@@ -166,6 +166,8 @@ $(document).ready(function() {
// delte annotation from server and from list // delte annotation from server and from list
deleteAnnotation(id, function () { deleteAnnotation(id, function () {
// send delete request to websocket
send("DELETE", id);
// remove annotation from list // remove annotation from list
$('#' + id).closest('.listelement').remove() $('#' + id).closest('.listelement').remove()
// remove highlighted text // remove highlighted text
...@@ -531,6 +533,8 @@ function saveNewAnnotation(title, comment, startCharacter, endCharacter) { ...@@ -531,6 +533,8 @@ function saveNewAnnotation(title, comment, startCharacter, endCharacter) {
// send new annotation to back-end and display it in list // send new annotation to back-end and display it in list
createAnnotation(annotationPostRequest, function(response) { createAnnotation(annotationPostRequest, function(response) {
// send new annotation to websocket
send("GET", response.id);
// display the new annotation // display the new annotation
displayAnnotation(response); displayAnnotation(response);
......
...@@ -9,6 +9,18 @@ function connect(targetId) { ...@@ -9,6 +9,18 @@ function connect(targetId) {
ws.onmessage = function (e) { ws.onmessage = function (e) {
var message = JSON.parse(e.data); var message = JSON.parse(e.data);
console.log(message.from) console.log(message.from)
if (message.type === "GET") {
// get annotation from server
getAnnotation(message.annotationId, function (response) {
// display annotation
displayAnnotation(response)
})
}
else if (message.type === "DELETE") {
// remove annotation from list
$('#' + message.annotationId).closest('.listelement').remove()
}
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment