-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
SharedNotesClientMessageSender.java
executable file
·137 lines (114 loc) · 4.96 KB
/
SharedNotesClientMessageSender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package org.bigbluebutton.red5.client;
import java.util.HashMap;
import java.util.Map;
import org.bigbluebutton.common.messages.PatchDocumentReplyMessage;
import org.bigbluebutton.common.messages.GetCurrentDocumentReplyMessage;
import org.bigbluebutton.common.messages.CreateAdditionalNotesReplyMessage;
import org.bigbluebutton.common.messages.DestroyAdditionalNotesReplyMessage;
import org.bigbluebutton.common.messages.SharedNotesSyncNoteReplyMessage;
import org.bigbluebutton.red5.client.messaging.BroadcastClientMessage;
import org.bigbluebutton.red5.client.messaging.IConnectionInvokerService;
import org.bigbluebutton.red5.client.messaging.DirectClientMessage;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class SharedNotesClientMessageSender {
private IConnectionInvokerService service;
public SharedNotesClientMessageSender(IConnectionInvokerService service) {
this.service = service;
}
public void handleSharedNotesMessage(String message) {
JsonParser parser = new JsonParser();
JsonObject obj = (JsonObject) parser.parse(message);
if (obj.has("header") && obj.has("payload")) {
JsonObject header = (JsonObject) obj.get("header");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
switch (messageName) {
case PatchDocumentReplyMessage.PATCH_DOCUMENT_REPLY:
processPatchDocumentReplyMessage(message);
break;
case GetCurrentDocumentReplyMessage.GET_CURRENT_DOCUMENT_REPLY:
processGetCurrentDocumentReplyMessage(message);
break;
case CreateAdditionalNotesReplyMessage.CREATE_ADDITIONAL_NOTES_REPLY:
processCreateAdditionalNotesReplyMessage(message);
break;
case DestroyAdditionalNotesReplyMessage.DESTROY_ADDITIONAL_NOTES_REPLY:
processDestroyAdditionalNotesReplyMessage(message);
break;
case SharedNotesSyncNoteReplyMessage.SHAREDNOTES_SYNC_NOTE_REPLY:
processSharedNotesSyncNoteReplyMessage(message);
break;
}
}
}
}
private void processPatchDocumentReplyMessage(String json) {
PatchDocumentReplyMessage msg = PatchDocumentReplyMessage.fromJson(json);
if (msg != null) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("userID", msg.requesterID);
args.put("noteID", msg.noteID);
args.put("patch", msg.patch);
args.put("patchID", msg.patchID);
args.put("undo", msg.undo);
args.put("redo", msg.redo);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingID, "PatchDocumentCommand", message);
service.sendMessage(m);
}
}
private void processGetCurrentDocumentReplyMessage(String json) {
GetCurrentDocumentReplyMessage msg = GetCurrentDocumentReplyMessage.fromJson(json);
if (msg != null) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("notes", msg.notes);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
DirectClientMessage m = new DirectClientMessage(msg.meetingID, msg.requesterID, "GetCurrentDocumentCommand", message);
service.sendMessage(m);
}
}
private void processCreateAdditionalNotesReplyMessage(String json) {
CreateAdditionalNotesReplyMessage msg = CreateAdditionalNotesReplyMessage.fromJson(json);
if (msg != null) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("noteID", msg.noteID);
args.put("noteName", msg.noteName);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingID, "CreateAdditionalNotesCommand", message);
service.sendMessage(m);
}
}
private void processDestroyAdditionalNotesReplyMessage(String json) {
DestroyAdditionalNotesReplyMessage msg = DestroyAdditionalNotesReplyMessage.fromJson(json);
if (msg != null) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("noteID", msg.noteID);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingID, "DestroyAdditionalNotesCommand", message);
service.sendMessage(m);
}
}
private void processSharedNotesSyncNoteReplyMessage(String json) {
SharedNotesSyncNoteReplyMessage msg = SharedNotesSyncNoteReplyMessage.fromJson(json);
if (msg != null) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("noteID", msg.noteID);
args.put("note", msg.note);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
DirectClientMessage m = new DirectClientMessage(msg.meetingID, msg.requesterID, "SharedNotesSyncNoteCommand", message);
service.sendMessage(m);
}
}
}