浏览代码

get recording status by signaling

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 2 年之前
父节点
当前提交
1aafc9989d

+ 35 - 18
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -98,6 +98,7 @@ import com.nextcloud.talk.utils.ApiUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.NotificationUtils;
 import com.nextcloud.talk.utils.animations.PulseAnimation;
+import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
 import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil;
 import com.nextcloud.talk.utils.power.PowerManagerUtils;
@@ -1674,26 +1675,42 @@ public class CallActivity extends CallBaseActivity {
             return;
         }
 
-        switch (webSocketCommunicationEvent.getType()) {
-            case "hello":
-                Log.d(TAG, "onMessageEvent 'hello'");
-                if (!webSocketCommunicationEvent.getHashMap().containsKey("oldResumeId")) {
-                    if (currentCallStatus == CallStatus.RECONNECTING) {
-                        hangup(false);
-                    } else {
-                        setCallState(CallStatus.RECONNECTING);
-                        runOnUiThread(this::initiateCall);
+        if (webSocketCommunicationEvent.getHashMap() != null) {
+            switch (webSocketCommunicationEvent.getType()) {
+                case "hello":
+                    Log.d(TAG, "onMessageEvent 'hello'");
+                    if (!webSocketCommunicationEvent.getHashMap().containsKey("oldResumeId")) {
+                        if (currentCallStatus == CallStatus.RECONNECTING) {
+                            hangup(false);
+                        } else {
+                            setCallState(CallStatus.RECONNECTING);
+                            runOnUiThread(this::initiateCall);
+                        }
                     }
-                }
-                break;
-            case "roomJoined":
-                Log.d(TAG, "onMessageEvent 'roomJoined'");
-                startSendingNick();
+                    break;
+                case "roomJoined":
+                    Log.d(TAG, "onMessageEvent 'roomJoined'");
+                    startSendingNick();
 
-                if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
-                    performCall();
-                }
-                break;
+                    if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
+                        performCall();
+                    }
+                    break;
+                case "recordingStatus":
+                    Log.d(TAG, "onMessageEvent 'recordingStatus'");
+
+                    if (webSocketCommunicationEvent.getHashMap().containsKey(BundleKeys.KEY_RECORDING_STATE)) {
+                        String recordingStateString =
+                            webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_RECORDING_STATE);
+
+                        if (recordingStateString != null) {
+                            runOnUiThread(() -> {
+                                callRecordingViewModel.setRecordingState(Integer.parseInt(recordingStateString));
+                            });
+                        }
+                    }
+                    break;
+            }
         }
     }
 

+ 1 - 0
app/src/main/java/com/nextcloud/talk/viewmodels/CallRecordingViewModel.kt

@@ -108,6 +108,7 @@ class CallRecordingViewModel @Inject constructor(private val repository: CallRec
         when (state) {
             0 -> _viewState.value = RecordingStoppedState
             1 -> _viewState.value = RecordingStartedState
+            2 -> _viewState.value = RecordingStartedState
             else -> {}
         }
     }

+ 4 - 2
app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java

@@ -266,13 +266,15 @@ public class MagicWebSocketInstance extends WebSocketListener {
                     refreshChatHashMap.put(BundleKeys.KEY_INTERNAL_USER_ID, Long.toString(conversationUser.getId()));
                     eventBus.post(new WebSocketCommunicationEvent("refreshChat", refreshChatHashMap));
                 }
-            } else if (dataHashMap.containsKey("recording")) {
+            } else if (dataHashMap != null && dataHashMap.containsKey("recording")) {
                 Map<String, Object> recordingMap = (Map<String, Object>) dataHashMap.get("recording");
                 if (recordingMap != null && recordingMap.containsKey("status")) {
                     int status = ((Long) recordingMap.get("status")).intValue();
                     Log.d(TAG, "status is " + status);
 
-                    // TODO: inform ChatController about state (after Daniels PRs are merged..)
+                    HashMap<String, String> recordingHashMap = new HashMap<>();
+                    recordingHashMap.put(BundleKeys.KEY_RECORDING_STATE, Integer.toString(status));
+                    eventBus.post(new WebSocketCommunicationEvent("recordingStatus", recordingHashMap));
                 }
             }
         }