|
@@ -65,11 +65,22 @@ import okio.ByteString;
|
|
|
|
|
|
import static com.nextcloud.talk.models.json.participants.Participant.ActorType.GUESTS;
|
|
|
import static com.nextcloud.talk.models.json.participants.Participant.ActorType.USERS;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.EVENT_TYPE;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.EVENT_TYPE_UPDATE;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.JOB_ID;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.PARTICIPANTS_UPDATE;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.ROOM_TOKEN;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.TARGET_PARTICIPANTS;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.UPDATE_ALL;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.UPDATE_IN_CALL;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.UPDATE_ROOM_ID;
|
|
|
+import static com.nextcloud.talk.webrtc.Globals.UPDATE_USERS;
|
|
|
|
|
|
@AutoInjector(NextcloudTalkApplication.class)
|
|
|
public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
private static final String TAG = "MagicWebSocketInstance";
|
|
|
|
|
|
+
|
|
|
@Inject
|
|
|
OkHttpClient okHttpClient;
|
|
|
|
|
@@ -190,7 +201,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
}
|
|
|
|
|
|
if (!TextUtils.isEmpty(currentRoomToken)) {
|
|
|
- helloHasHap.put("roomToken", currentRoomToken);
|
|
|
+ helloHasHap.put(ROOM_TOKEN, currentRoomToken);
|
|
|
}
|
|
|
eventBus.post(new WebSocketCommunicationEvent("hello", helloHasHap));
|
|
|
break;
|
|
@@ -221,23 +232,23 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
switch (target) {
|
|
|
case "room":
|
|
|
if (eventOverallWebSocketMessage.getEventMap().get("type").equals("message")) {
|
|
|
- Map<String, Object> messageHashMap =
|
|
|
- (Map<String, Object>) eventOverallWebSocketMessage.getEventMap().get("message");
|
|
|
- if (messageHashMap.containsKey("data")) {
|
|
|
- Map<String, Object> dataHashMap = (Map<String, Object>) messageHashMap.get(
|
|
|
- "data");
|
|
|
- if (dataHashMap.containsKey("chat")) {
|
|
|
- boolean shouldRefreshChat;
|
|
|
- Map<String, Object> chatMap = (Map<String, Object>) dataHashMap.get("chat");
|
|
|
- if (chatMap.containsKey("refresh")) {
|
|
|
- shouldRefreshChat = (boolean) chatMap.get("refresh");
|
|
|
- if (shouldRefreshChat) {
|
|
|
- HashMap<String, String> refreshChatHashMap = new HashMap<>();
|
|
|
- refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), (String) messageHashMap.get("roomid"));
|
|
|
- refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), Long.toString(conversationUser.getId()));
|
|
|
- eventBus.post(new WebSocketCommunicationEvent("refreshChat", refreshChatHashMap));
|
|
|
- }
|
|
|
+ Map<String, Object> messageHashMap =
|
|
|
+ (Map<String, Object>) eventOverallWebSocketMessage.getEventMap().get("message");
|
|
|
+ if (messageHashMap.containsKey("data")) {
|
|
|
+ Map<String, Object> dataHashMap = (Map<String, Object>) messageHashMap.get(
|
|
|
+ "data");
|
|
|
+ if (dataHashMap.containsKey("chat")) {
|
|
|
+ boolean shouldRefreshChat;
|
|
|
+ Map<String, Object> chatMap = (Map<String, Object>) dataHashMap.get("chat");
|
|
|
+ if (chatMap.containsKey("refresh")) {
|
|
|
+ shouldRefreshChat = (boolean) chatMap.get("refresh");
|
|
|
+ if (shouldRefreshChat) {
|
|
|
+ HashMap<String, String> refreshChatHashMap = new HashMap<>();
|
|
|
+ refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), (String) messageHashMap.get("roomid"));
|
|
|
+ refreshChatHashMap.put(BundleKeys.INSTANCE.getKEY_INTERNAL_USER_ID(), Long.toString(conversationUser.getId()));
|
|
|
+ eventBus.post(new WebSocketCommunicationEvent("refreshChat", refreshChatHashMap));
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else if (eventOverallWebSocketMessage.getEventMap().get("type").equals("join")) {
|
|
@@ -264,26 +275,45 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
- case "participants":
|
|
|
- if (eventOverallWebSocketMessage.getEventMap().get("type").equals("update")) {
|
|
|
+ case TARGET_PARTICIPANTS:
|
|
|
+ if (EVENT_TYPE_UPDATE.equals(eventOverallWebSocketMessage.getEventMap().get(EVENT_TYPE))) {
|
|
|
HashMap<String, String> refreshChatHashMap = new HashMap<>();
|
|
|
- HashMap<String, Object> updateEventMap = (HashMap<String, Object>) eventOverallWebSocketMessage.getEventMap().get("update");
|
|
|
- refreshChatHashMap.put("roomToken", (String) updateEventMap.get("roomid"));
|
|
|
+ HashMap<String, Object> updateEventMap = (HashMap<String, Object>) eventOverallWebSocketMessage.getEventMap().get(EVENT_TYPE_UPDATE);
|
|
|
|
|
|
- if (updateEventMap.containsKey("users")) {
|
|
|
- refreshChatHashMap.put("jobId", Integer.toString(magicMap.add(updateEventMap.get("users"))));
|
|
|
+ if (updateEventMap == null) {
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- if (updateEventMap.containsKey("incall")) {
|
|
|
- refreshChatHashMap.put("incall",
|
|
|
- Long.toString((Long)updateEventMap.get("incall")));
|
|
|
+ if (updateEventMap.containsKey(UPDATE_ROOM_ID)) {
|
|
|
+ Object updateRoomId = updateEventMap.get(UPDATE_ROOM_ID);
|
|
|
+ if (updateRoomId != null) {
|
|
|
+ refreshChatHashMap.put(ROOM_TOKEN,
|
|
|
+ (String) updateEventMap.get(UPDATE_ROOM_ID));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (updateEventMap.containsKey(UPDATE_USERS)) {
|
|
|
+ Object updateUsers = updateEventMap.get(UPDATE_USERS);
|
|
|
+ if (updateUsers != null) {
|
|
|
+ refreshChatHashMap.put(JOB_ID, Integer.toString(magicMap.add(updateUsers)));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (updateEventMap.containsKey("all")) {
|
|
|
- refreshChatHashMap.put("all", Boolean.toString((Boolean) updateEventMap.get("all")));
|
|
|
+ if (updateEventMap.containsKey(UPDATE_IN_CALL)) {
|
|
|
+ Object inCall = updateEventMap.get(UPDATE_IN_CALL);
|
|
|
+ if (inCall != null) {
|
|
|
+ refreshChatHashMap.put(UPDATE_IN_CALL, Long.toString((Long) inCall));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (updateEventMap.containsKey(UPDATE_ALL)) {
|
|
|
+ Object updateAll = updateEventMap.get(UPDATE_ALL);
|
|
|
+ if (updateAll != null) {
|
|
|
+ refreshChatHashMap.put(UPDATE_ALL, Boolean.toString((Boolean) updateAll));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- eventBus.post(new WebSocketCommunicationEvent("participantsUpdate", refreshChatHashMap));
|
|
|
+ eventBus.post(new WebSocketCommunicationEvent(PARTICIPANTS_UPDATE, refreshChatHashMap));
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -298,7 +328,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
|
|
|
if (!TextUtils.isEmpty(ncSignalingMessage.getFrom())) {
|
|
|
HashMap<String, String> messageHashMap = new HashMap<>();
|
|
|
- messageHashMap.put("jobId", Integer.toString(magicMap.add(ncSignalingMessage)));
|
|
|
+ messageHashMap.put(JOB_ID, Integer.toString(magicMap.add(ncSignalingMessage)));
|
|
|
eventBus.post(new WebSocketCommunicationEvent("signalingMessage", messageHashMap));
|
|
|
}
|
|
|
break;
|
|
@@ -316,7 +346,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
|
|
|
|
|
|
private void sendRoomJoinedEvent() {
|
|
|
HashMap<String, String> joinRoomHashMap = new HashMap<>();
|
|
|
- joinRoomHashMap.put("roomToken", currentRoomToken);
|
|
|
+ joinRoomHashMap.put(ROOM_TOKEN, currentRoomToken);
|
|
|
eventBus.post(new WebSocketCommunicationEvent("roomJoined", joinRoomHashMap));
|
|
|
}
|
|
|
|