瀏覽代碼

android: add ability to keep track of the current ongoing conference

master
Saúl Ibarra Corretgé 6 年之前
父節點
當前提交
f71ec55170

+ 3
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java 查看文件

@@ -67,6 +67,9 @@ class ExternalAPIModule
67 67
      */
68 68
     @ReactMethod
69 69
     public void sendEvent(String name, ReadableMap data, String scope) {
70
+        // Keep track of the current ongoing conference.
71
+        OngoingConferenceTracker.onExternalAPIEvent(name, data);
72
+
70 73
         // The JavaScript App needs to provide uniquely identifying information
71 74
         // to the native ExternalAPI module so that the latter may match the
72 75
         // former to the native BaseReactView which hosts it.

+ 9
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeet.java 查看文件

@@ -36,6 +36,15 @@ public class JitsiMeet {
36 36
         defaultConferenceOptions = options;
37 37
     }
38 38
 
39
+    /**
40
+     * Returns the current conference URL as a string.
41
+     *
42
+     * @return the current conference URL.
43
+     */
44
+    public static String getCurrentConference() {
45
+        return OngoingConferenceTracker.getCurrentConference();
46
+    }
47
+
39 48
     /**
40 49
      * Helper to get the default conference options as a {@link Bundle}.
41 50
      *

+ 20
- 28
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java 查看文件

@@ -29,7 +29,8 @@ import java.lang.reflect.Method;
29 29
 import java.util.Map;
30 30
 
31 31
 
32
-public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener> {
32
+public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
33
+        implements OngoingConferenceTracker.OngoingConferenceListener {
33 34
 
34 35
     /**
35 36
      * The {@code Method}s of {@code JitsiMeetViewListener} by event name i.e.
@@ -106,6 +107,14 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener> {
106 107
         if (!(context instanceof JitsiMeetActivityInterface)) {
107 108
             throw new RuntimeException("Enclosing Activity must implement JitsiMeetActivityInterface");
108 109
         }
110
+
111
+        OngoingConferenceTracker.addListener(this);
112
+    }
113
+
114
+    @Override
115
+    public void dispose() {
116
+        OngoingConferenceTracker.removeListener(this);
117
+        super.dispose();
109 118
     }
110 119
 
111 120
     /**
@@ -173,27 +182,17 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener> {
173 182
     }
174 183
 
175 184
     /**
176
-     * The internal processing for the URL of the current conference set on the
177
-     * associated {@link JitsiMeetView}.
178
-     *
179
-     * @param eventName the name of the external API event to be processed
180
-     * @param eventData the details/specifics of the event to process determined
181
-     * by/associated with the specified {@code eventName}.
185
+     * Handler for {@link OngoingConferenceTracker} events.
186
+     * @param conferenceUrl
182 187
      */
183
-    private void maybeSetViewURL(String eventName, ReadableMap eventData) {
184
-        String url = eventData.hasKey("url") ? eventData.getString("url") : null;
185
-
186
-        switch(eventName) {
187
-        case "CONFERENCE_WILL_JOIN":
188
-            this.url = url;
189
-            break;
190
-
191
-        case "CONFERENCE_TERMINATED":
192
-            if (url != null && url.equals(this.url)) {
193
-                this.url = null;
194
-            }
195
-            break;
196
-        }
188
+    @Override
189
+    public void onCurrentConferenceChanged(String conferenceUrl) {
190
+        // This property was introduced in order to address
191
+        // an exception in the Picture-in-Picture functionality which arose
192
+        // because of delays related to bridging between JavaScript and Java. To
193
+        // reduce these delays do not wait for the call to be transferred to the
194
+        // UI thread.
195
+        this.url = conferenceUrl;
197 196
     }
198 197
 
199 198
     /**
@@ -205,13 +204,6 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener> {
205 204
      */
206 205
     @Override
207 206
     protected void onExternalAPIEvent(String name, ReadableMap data) {
208
-        // XXX The JitsiMeetView property URL was introduced in order to address
209
-        // an exception in the Picture-in-Picture functionality which arose
210
-        // because of delays related to bridging between JavaScript and Java. To
211
-        // reduce these delays do not wait for the call to be transferred to the
212
-        // UI thread.
213
-        maybeSetViewURL(name, data);
214
-
215 207
         onExternalAPIEvent(LISTENER_METHODS, name, data);
216 208
     }
217 209
 }

+ 73
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/OngoingConferenceTracker.java 查看文件

@@ -0,0 +1,73 @@
1
+/*
2
+ * Copyright @ 2019-present 8x8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *     http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+package org.jitsi.meet.sdk;
18
+
19
+import com.facebook.react.bridge.ReadableMap;
20
+
21
+import java.util.Collection;
22
+import java.util.Collections;
23
+import java.util.HashSet;
24
+
25
+class OngoingConferenceTracker {
26
+    private static final Collection<OngoingConferenceListener> listeners =
27
+        Collections.synchronizedSet(new HashSet<OngoingConferenceListener>());
28
+    private static String currentConference;
29
+
30
+    static synchronized String getCurrentConference() {
31
+        return currentConference;
32
+    }
33
+
34
+    static synchronized void onExternalAPIEvent(String name, ReadableMap data) {
35
+        if (!data.hasKey("url")) {
36
+            return;
37
+        }
38
+
39
+        String url = data.getString("url");
40
+
41
+        switch(name) {
42
+            case "CONFERENCE_WILL_JOIN":
43
+                currentConference = url;
44
+                updateCurrentConference();
45
+                break;
46
+
47
+            case "CONFERENCE_TERMINATED":
48
+                if (currentConference != null && url.equals(currentConference)) {
49
+                    currentConference = null;
50
+                    updateCurrentConference();
51
+                }
52
+                break;
53
+        }
54
+    }
55
+
56
+    static void addListener(OngoingConferenceListener listener) {
57
+        listeners.add(listener);
58
+    }
59
+
60
+    static void removeListener(OngoingConferenceListener listener) {
61
+        listeners.remove(listener);
62
+    }
63
+
64
+    private static synchronized void updateCurrentConference() {
65
+        for (OngoingConferenceListener listener: listeners) {
66
+            listener.onCurrentConferenceChanged(currentConference);
67
+        }
68
+    }
69
+
70
+    public interface OngoingConferenceListener {
71
+        void onCurrentConferenceChanged(String conferenceUrl);
72
+    }
73
+}

Loading…
取消
儲存