-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
WhiteboardClientMessageSender.java
executable file
·170 lines (137 loc) · 6.25 KB
/
WhiteboardClientMessageSender.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package org.bigbluebutton.red5.client;
import java.util.HashMap;
import java.util.Map;
import org.bigbluebutton.common.messages.ClearWhiteboardReplyMessage;
import org.bigbluebutton.common.messages.GetWhiteboardShapesReplyMessage;
import org.bigbluebutton.common.messages.GetWhiteboardAccessReplyMessage;
import org.bigbluebutton.common.messages.SendWhiteboardAnnotationReplyMessage;
import org.bigbluebutton.common.messages.UndoWhiteboardReplyMessage;
import org.bigbluebutton.common.messages.ModifiedWhiteboardAccessMessage;
import org.bigbluebutton.red5.client.messaging.BroadcastClientMessage;
import org.bigbluebutton.red5.client.messaging.ConnectionInvokerService;
import org.bigbluebutton.red5.client.messaging.DirectClientMessage;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class WhiteboardClientMessageSender {
private ConnectionInvokerService service;
public WhiteboardClientMessageSender(ConnectionInvokerService service) {
this.service = service;
}
public void handleWhiteboardMessage(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 UndoWhiteboardReplyMessage.UNDO_WHITEBOARD_REPLY:
UndoWhiteboardReplyMessage uwrm = UndoWhiteboardReplyMessage.fromJson(message);
if (uwrm != null) {
processUndoWhiteboardReply(uwrm);
}
break;
case ClearWhiteboardReplyMessage.WHITEBOARD_CLEARED_MESSAGE:
ClearWhiteboardReplyMessage wcm = ClearWhiteboardReplyMessage.fromJson(message);
if (wcm != null) {
processClearWhiteboardReply(wcm);
}
break;
case GetWhiteboardShapesReplyMessage.GET_WHITEBOARD_SHAPES_REPLY:
GetWhiteboardShapesReplyMessage gwsrm = GetWhiteboardShapesReplyMessage.fromJson(message);
if (gwsrm != null) {
processGetWhiteboardShapesReplyMessage(gwsrm);
}
break;
case SendWhiteboardAnnotationReplyMessage.SEND_WHITEBOARD_ANNOTATION_REPLY:
SendWhiteboardAnnotationReplyMessage swarm = SendWhiteboardAnnotationReplyMessage.fromJson(message);
if (swarm != null) {
processSendWhiteboardAnnotationReplyMessage(swarm);
}
break;
case ModifiedWhiteboardAccessMessage.MODIFIED_WHITEBOARD_ACCESS:
ModifiedWhiteboardAccessMessage mwam = ModifiedWhiteboardAccessMessage.fromJson(message);
if (mwam != null) {
processModifiedWhiteboardAccessMessage(mwam);
}
break;
case GetWhiteboardAccessReplyMessage.GET_WHITEBOARD_ACCESS_REPLY:
GetWhiteboardAccessReplyMessage gwa = GetWhiteboardAccessReplyMessage.fromJson(message);
if (gwa != null) {
processGetWhiteboardAccessReply(gwa);
}
break;
}
}
}
}
private void processSendWhiteboardAnnotationReplyMessage(SendWhiteboardAnnotationReplyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("whiteboardId", msg.whiteboardId);
Map<String, Object> shape = new HashMap<String, Object>();
shape.put("id", msg.shape.get("id"));
shape.put("type", msg.shape.get("type"));
shape.put("status", msg.shape.get("status"));
shape.put("userId", msg.shape.get("userId"));
shape.put("shape", msg.shape.get("shapes"));
args.put("shape", shape);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
//broadcast message
BroadcastClientMessage b = new BroadcastClientMessage(msg.meetingId, "WhiteboardNewAnnotationCommand", message);
service.sendMessage(b);
}
private void processGetWhiteboardShapesReplyMessage(GetWhiteboardShapesReplyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("whiteboardId", msg.whiteboardId);
args.put("count", msg.shapes.size());
args.put("annotations",msg.shapes);
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, "WhiteboardRequestAnnotationHistoryReply", message);
service.sendMessage(m);
}
private void processClearWhiteboardReply(ClearWhiteboardReplyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("whiteboardId", msg.whiteboardId);
args.put("userId", msg.requesterId);
args.put("fullClear", msg.fullClear);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "WhiteboardClearCommand", message);
service.sendMessage(m);
}
private void processUndoWhiteboardReply(UndoWhiteboardReplyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("shapeId", msg.shapeId);
args.put("whiteboardId", msg.whiteboardId);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "WhiteboardUndoCommand", message);
service.sendMessage(m);
}
private void processModifiedWhiteboardAccessMessage(ModifiedWhiteboardAccessMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("multiUser", msg.multiUser);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
// broadcast message
BroadcastClientMessage b = new BroadcastClientMessage(msg.meetingId, "WhiteboardAccessModifiedCommand", message);
service.sendMessage(b);
}
private void processGetWhiteboardAccessReply(GetWhiteboardAccessReplyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("multiUser", msg.multiUser);
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, "WhiteboardGetWhiteboardAccessReply", message);
service.sendMessage(m);
}
}