Просмотр исходного кода

Coding style: comments, formatting, sorting order

master
Lyubo Marinov 7 лет назад
Родитель
Сommit
75c7cfd9e1

+ 0
- 2
android/app/src/main/java/org/jitsi/meet/MainActivity.java Просмотреть файл

115
             inviteController.setListener(new InviteControllerListener() {
115
             inviteController.setListener(new InviteControllerListener() {
116
                 public void beginAddPeople(
116
                 public void beginAddPeople(
117
                         AddPeopleController addPeopleController) {
117
                         AddPeopleController addPeopleController) {
118
-                    UiThreadUtil.assertOnUiThread();
119
-
120
                     onInviteControllerBeginAddPeople(
118
                     onInviteControllerBeginAddPeople(
121
                         inviteController,
119
                         inviteController,
122
                         addPeopleController);
120
                         addPeopleController);

+ 71
- 39
android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java Просмотреть файл

140
     }
140
     }
141
 
141
 
142
     /**
142
     /**
143
-     * Dispatches an event that occurred on JavaScript to the view's listener.
143
+     * Dispatches an event that occurred on the JavaScript side of the SDK to
144
+     * the specified {@link JitsiMeetView}'s listener.
144
      *
145
      *
145
      * @param name The name of the event.
146
      * @param name The name of the event.
146
      * @param data The details/specifics of the event to send determined
147
      * @param data The details/specifics of the event to send determined
151
     public void sendEvent(final String name,
152
     public void sendEvent(final String name,
152
                           final ReadableMap data,
153
                           final ReadableMap data,
153
                           final String scope) {
154
                           final String scope) {
154
-        UiThreadUtil.runOnUiThread(new Runnable() {
155
-            @Override
156
-            public void run() {
157
-                // The JavaScript App needs to provide uniquely identifying
158
-                // information to the native ExternalAPI module so that the
159
-                // latter may match the former to the native JitsiMeetView which
160
-                // hosts it.
161
-                JitsiMeetView view
162
-                    = JitsiMeetView.findViewByExternalAPIScope(scope);
163
-
164
-                if (view == null) {
165
-                    return;
155
+        // The JavaScript App needs to provide uniquely identifying information
156
+        // to the native ExternalAPI module so that the latter may match the
157
+        // former to the native JitsiMeetView which hosts it.
158
+        JitsiMeetView view = JitsiMeetView.findViewByExternalAPIScope(scope);
159
+
160
+        if (view == null) {
161
+            return;
162
+        }
163
+
164
+        // XXX The JitsiMeetView property URL was introduced in order to address
165
+        // an exception in the Picture-in-Picture functionality which arose
166
+        // because of delays related to bridging between JavaScript and Java. To
167
+        // reduce these delays do not wait for the call to be transfered to the
168
+        // UI thread.
169
+        maybeSetViewURL(name, data, view);
170
+
171
+        // Make sure JitsiMeetView's listener is invoked on the UI thread. It
172
+        // was requested by SDK consumers.
173
+        if (UiThreadUtil.isOnUiThread()) {
174
+            sendEventOnUiThread(name, data, scope);
175
+        } else {
176
+            UiThreadUtil.runOnUiThread(new Runnable() {
177
+                @Override
178
+                public void run() {
179
+                    sendEventOnUiThread(name, data, scope);
166
                 }
180
                 }
181
+            });
182
+        }
183
+    }
184
+
185
+    /**
186
+     * Dispatches an event that occurred on the JavaScript side of the SDK to
187
+     * the specified {@link JitsiMeetView}'s listener on the UI thread.
188
+     *
189
+     * @param name The name of the event.
190
+     * @param data The details/specifics of the event to send determined
191
+     * by/associated with the specified {@code name}.
192
+     * @param scope
193
+     */
194
+    private void sendEventOnUiThread(final String name,
195
+                          final ReadableMap data,
196
+                          final String scope) {
197
+        // The JavaScript App needs to provide uniquely identifying information
198
+        // to the native ExternalAPI module so that the latter may match the
199
+        // former to the native JitsiMeetView which hosts it.
200
+        JitsiMeetView view = JitsiMeetView.findViewByExternalAPIScope(scope);
167
 
201
 
168
-                maybeSetViewURL(name, data, view);
202
+        if (view == null) {
203
+            return;
204
+        }
169
 
205
 
170
-                JitsiMeetViewListener listener = view.getListener();
206
+        JitsiMeetViewListener listener = view.getListener();
171
 
207
 
172
-                if (listener == null) {
173
-                    return;
174
-                }
208
+        if (listener == null) {
209
+            return;
210
+        }
175
 
211
 
176
-                Method method = JITSI_MEET_VIEW_LISTENER_METHODS.get(name);
177
-
178
-                if (method != null) {
179
-                    try {
180
-                        method.invoke(listener, toHashMap(data));
181
-                    } catch (IllegalAccessException e) {
182
-                        // FIXME There was a multicatch for
183
-                        // IllegalAccessException and InvocationTargetException,
184
-                        // but Android Studio complained with: "Multi-catch with
185
-                        // these reflection exceptions requires API level 19
186
-                        // (current min is 16) because they get compiled to the
187
-                        // common but new super type
188
-                        // ReflectiveOperationException. As a workaround either
189
-                        // create individual catch statements, or
190
-                        // catch Exception."
191
-                        throw new RuntimeException(e);
192
-                    } catch (InvocationTargetException e) {
193
-                        throw new RuntimeException(e);
194
-                    }
195
-                }
212
+        Method method = JITSI_MEET_VIEW_LISTENER_METHODS.get(name);
213
+
214
+        if (method != null) {
215
+            try {
216
+                method.invoke(listener, toHashMap(data));
217
+            } catch (IllegalAccessException e) {
218
+                // FIXME There was a multicatch for IllegalAccessException and
219
+                // InvocationTargetException, but Android Studio complained
220
+                // with: "Multi-catch with these reflection exceptions requires
221
+                // API level 19 (current min is 16) because they get compiled to
222
+                // the common but new super type ReflectiveOperationException.
223
+                // As a workaround either create individual catch statements, or
224
+                // catch Exception."
225
+                throw new RuntimeException(e);
226
+            } catch (InvocationTargetException e) {
227
+                throw new RuntimeException(e);
196
             }
228
             }
197
-        });
229
+        }
198
     }
230
     }
199
 
231
 
200
     /**
232
     /**

+ 68
- 38
android/sdk/src/main/java/org/jitsi/meet/sdk/invite/InviteModule.java Просмотреть файл

44
      */
44
      */
45
     @ReactMethod
45
     @ReactMethod
46
     public void beginAddPeople(final String externalAPIScope) {
46
     public void beginAddPeople(final String externalAPIScope) {
47
-        UiThreadUtil.runOnUiThread(new Runnable() {
48
-            @Override
49
-            public void run() {
50
-                InviteController inviteController
51
-                    = findInviteControllerByExternalAPIScope(externalAPIScope);
52
-
53
-                if (inviteController != null) {
54
-                    inviteController.beginAddPeople(getReactApplicationContext());
47
+        // Make sure InviteControllerListener (like all other listeners of the
48
+        // SDK) is invoked on the UI thread. It was requested by SDK consumers.
49
+        if (!UiThreadUtil.isOnUiThread()) {
50
+            UiThreadUtil.runOnUiThread(new Runnable() {
51
+                @Override
52
+                public void run() {
53
+                    beginAddPeople(externalAPIScope);
55
                 }
54
                 }
56
-            }
57
-        });
55
+            });
56
+            return;
57
+        }
58
+
59
+        InviteController inviteController
60
+            = findInviteControllerByExternalAPIScope(externalAPIScope);
61
+
62
+        if (inviteController != null) {
63
+            inviteController.beginAddPeople(getReactApplicationContext());
64
+        }
58
     }
65
     }
59
 
66
 
60
     private InviteController findInviteControllerByExternalAPIScope(
67
     private InviteController findInviteControllerByExternalAPIScope(
81
             final String externalAPIScope,
88
             final String externalAPIScope,
82
             final String addPeopleControllerScope,
89
             final String addPeopleControllerScope,
83
             final ReadableArray failedInvitees) {
90
             final ReadableArray failedInvitees) {
84
-        UiThreadUtil.runOnUiThread(new Runnable() {
85
-            @Override
86
-            public void run() {
87
-                InviteController inviteController
88
-                    = findInviteControllerByExternalAPIScope(externalAPIScope);
89
-
90
-                if (inviteController == null) {
91
-                    Log.w(
92
-                        "InviteModule",
93
-                        "Invite settled, but failed to find active controller to notify");
94
-                } else {
95
-                    inviteController.inviteSettled(
91
+        // Make sure AddPeopleControllerListener (like all other listeners of
92
+        // the SDK) is invoked on the UI thread. It was requested by SDK
93
+        // consumers.
94
+        if (!UiThreadUtil.isOnUiThread()) {
95
+            UiThreadUtil.runOnUiThread(new Runnable() {
96
+                @Override
97
+                public void run() {
98
+                    inviteSettled(
99
+                        externalAPIScope, 
96
                         addPeopleControllerScope,
100
                         addPeopleControllerScope,
97
                         failedInvitees);
101
                         failedInvitees);
98
                 }
102
                 }
99
-            }
100
-        });
103
+            });
104
+            return;
105
+        }
106
+
107
+        InviteController inviteController
108
+            = findInviteControllerByExternalAPIScope(externalAPIScope);
109
+
110
+        if (inviteController == null) {
111
+            Log.w(
112
+                "InviteModule",
113
+                "Invite settled, but failed to find active controller to notify");
114
+        } else {
115
+            inviteController.inviteSettled(
116
+                addPeopleControllerScope,
117
+                failedInvitees);
118
+        }
101
     }
119
     }
102
 
120
 
103
     /**
121
     /**
113
             final String addPeopleControllerScope,
131
             final String addPeopleControllerScope,
114
             final String query,
132
             final String query,
115
             final ReadableArray results) {
133
             final ReadableArray results) {
116
-        UiThreadUtil.runOnUiThread(new Runnable() {
117
-            @Override
118
-            public void run() {
119
-                InviteController inviteController
120
-                    = findInviteControllerByExternalAPIScope(externalAPIScope);
121
-
122
-                if (inviteController == null) {
123
-                    Log.w(
124
-                        "InviteModule",
125
-                        "Received results, but failed to find active controller to send results back");
126
-                } else {
127
-                    inviteController.receivedResultsForQuery(
134
+        // Make sure AddPeopleControllerListener (like all other listeners of
135
+        // the SDK) is invoked on the UI thread. It was requested by SDK
136
+        // consumers.
137
+        if (!UiThreadUtil.isOnUiThread()) {
138
+            UiThreadUtil.runOnUiThread(new Runnable() {
139
+                @Override
140
+                public void run() {
141
+                    receivedResults(
142
+                        externalAPIScope,
128
                         addPeopleControllerScope,
143
                         addPeopleControllerScope,
129
                         query,
144
                         query,
130
                         results);
145
                         results);
131
                 }
146
                 }
132
-            }
133
-        });
147
+            });
148
+            return;
149
+        }
150
+
151
+        InviteController inviteController
152
+            = findInviteControllerByExternalAPIScope(externalAPIScope);
153
+
154
+        if (inviteController == null) {
155
+            Log.w(
156
+                "InviteModule",
157
+                "Received results, but failed to find active controller to send results back");
158
+        } else {
159
+            inviteController.receivedResultsForQuery(
160
+                addPeopleControllerScope,
161
+                query,
162
+                results);
163
+        }
134
     }
164
     }
135
 }
165
 }

+ 21
- 17
ios/app/src/ViewController.m Просмотреть файл

14
  * limitations under the License.
14
  * limitations under the License.
15
  */
15
  */
16
 
16
 
17
-#import <assert.h>
18
-
19
 #import "ViewController.h"
17
 #import "ViewController.h"
20
 
18
 
21
 /**
19
 /**
62
 
60
 
63
 // JitsiMeetViewDelegate
61
 // JitsiMeetViewDelegate
64
 
62
 
65
-void _onJitsiMeetViewDelegateEvent(NSString *name, NSDictionary *data) {
63
+- (void)_onJitsiMeetViewDelegateEvent:(NSString *)name
64
+                             withData:(NSDictionary *)data {
66
     NSLog(
65
     NSLog(
67
         @"[%s:%d] JitsiMeetViewDelegate %@ %@",
66
         @"[%s:%d] JitsiMeetViewDelegate %@ %@",
68
         __FILE__, __LINE__, name, data);
67
         __FILE__, __LINE__, name, data);
69
 
68
 
70
-    assert([NSThread isMainThread]
71
-        && "Delegate method called in a non-main thread");
69
+    NSAssert(
70
+        [NSThread isMainThread],
71
+        @"JitsiMeetViewDelegate %@ method invoked on a non-main thread",
72
+        name);
72
 }
73
 }
73
 
74
 
74
 - (void)conferenceFailed:(NSDictionary *)data {
75
 - (void)conferenceFailed:(NSDictionary *)data {
75
-    _onJitsiMeetViewDelegateEvent(@"CONFERENCE_FAILED", data);
76
+    [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_FAILED" withData:data];
76
 }
77
 }
77
 
78
 
78
 - (void)conferenceJoined:(NSDictionary *)data {
79
 - (void)conferenceJoined:(NSDictionary *)data {
79
-    _onJitsiMeetViewDelegateEvent(@"CONFERENCE_JOINED", data);
80
+    [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_JOINED" withData:data];
80
 }
81
 }
81
 
82
 
82
 - (void)conferenceLeft:(NSDictionary *)data {
83
 - (void)conferenceLeft:(NSDictionary *)data {
83
-    _onJitsiMeetViewDelegateEvent(@"CONFERENCE_LEFT", data);
84
+    [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_LEFT" withData:data];
84
 }
85
 }
85
 
86
 
86
 - (void)conferenceWillJoin:(NSDictionary *)data {
87
 - (void)conferenceWillJoin:(NSDictionary *)data {
87
-    _onJitsiMeetViewDelegateEvent(@"CONFERENCE_WILL_JOIN", data);
88
+    [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_JOIN" withData:data];
88
 }
89
 }
89
 
90
 
90
 - (void)conferenceWillLeave:(NSDictionary *)data {
91
 - (void)conferenceWillLeave:(NSDictionary *)data {
91
-    _onJitsiMeetViewDelegateEvent(@"CONFERENCE_WILL_LEAVE", data);
92
+    [self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_LEAVE" withData:data];
92
 }
93
 }
93
 
94
 
94
 - (void)loadConfigError:(NSDictionary *)data {
95
 - (void)loadConfigError:(NSDictionary *)data {
95
-    _onJitsiMeetViewDelegateEvent(@"LOAD_CONFIG_ERROR", data);
96
+    [self _onJitsiMeetViewDelegateEvent:@"LOAD_CONFIG_ERROR" withData:data];
96
 }
97
 }
97
 
98
 
98
 // JMInviteControllerDelegate
99
 // JMInviteControllerDelegate
102
         @"[%s:%d] JMInviteControllerDelegate %s",
103
         @"[%s:%d] JMInviteControllerDelegate %s",
103
         __FILE__, __LINE__, __FUNCTION__);
104
         __FILE__, __LINE__, __FUNCTION__);
104
 
105
 
105
-    assert([NSThread isMainThread]
106
-        && "Delegate method called in a non-main thread");
106
+    NSAssert(
107
+        [NSThread isMainThread],
108
+        @"JMInviteControllerDelegate beginAddPeople: invoked on a non-main thread");
107
 
109
 
108
     NSString *query = ADD_PEOPLE_CONTROLLER_QUERY;
110
     NSString *query = ADD_PEOPLE_CONTROLLER_QUERY;
109
     JitsiMeetView *view = (JitsiMeetView *) self.view;
111
     JitsiMeetView *view = (JitsiMeetView *) self.view;
127
 - (void)addPeopleController:(JMAddPeopleController * _Nonnull)controller
129
 - (void)addPeopleController:(JMAddPeopleController * _Nonnull)controller
128
           didReceiveResults:(NSArray<NSDictionary *> * _Nonnull)results
130
           didReceiveResults:(NSArray<NSDictionary *> * _Nonnull)results
129
                    forQuery:(NSString * _Nonnull)query {
131
                    forQuery:(NSString * _Nonnull)query {
130
-    assert([NSThread isMainThread]
131
-        && "Delegate method called in a non-main thread");
132
+    NSAssert(
133
+        [NSThread isMainThread],
134
+        @"JMAddPeopleControllerDelegate addPeopleController:didReceiveResults:forQuery: invoked on a non-main thread");
132
 
135
 
133
     NSUInteger count = results.count;
136
     NSUInteger count = results.count;
134
 
137
 
162
 
165
 
163
 - (void) inviteSettled:(NSArray<NSDictionary *> * _Nonnull)failedInvitees
166
 - (void) inviteSettled:(NSArray<NSDictionary *> * _Nonnull)failedInvitees
164
   fromSearchController:(JMAddPeopleController * _Nonnull)addPeopleController {
167
   fromSearchController:(JMAddPeopleController * _Nonnull)addPeopleController {
165
-    assert([NSThread isMainThread]
166
-        && "Delegate method called in a non-main thread");
168
+    NSAssert(
169
+        [NSThread isMainThread],
170
+        @"JMAddPeopleControllerDelegate inviteSettled:fromSearchController: invoked on a non-main thread");
167
 
171
 
168
     // XXX Explicitly invoke endAddPeople on addPeopleController; otherwise, it
172
     // XXX Explicitly invoke endAddPeople on addPeopleController; otherwise, it
169
     // is going to be memory-leaked in the associated JMInviteController and no
173
     // is going to be memory-leaked in the associated JMInviteController and no

+ 1
- 1
ios/sdk/src/ExternalAPI.m Просмотреть файл

26
 RCT_EXPORT_MODULE();
26
 RCT_EXPORT_MODULE();
27
 
27
 
28
 /**
28
 /**
29
- * Make sure all methods in this module are called in the main (i.e. UI) thread.
29
+ * Make sure all methods in this module are invoked on the main/UI thread.
30
  */
30
  */
31
 - (dispatch_queue_t)methodQueue {
31
 - (dispatch_queue_t)methodQueue {
32
     return dispatch_get_main_queue();
32
     return dispatch_get_main_queue();

+ 7
- 7
ios/sdk/src/invite/Invite.m Просмотреть файл

33
 
33
 
34
 RCT_EXPORT_MODULE();
34
 RCT_EXPORT_MODULE();
35
 
35
 
36
+/**
37
+ * Make sure all methods in this module are invoked on the main/UI thread.
38
+ */
39
+- (dispatch_queue_t)methodQueue {
40
+    return dispatch_get_main_queue();
41
+}
42
+
36
 - (NSArray<NSString *> *)supportedEvents {
43
 - (NSArray<NSString *> *)supportedEvents {
37
     return @[
44
     return @[
38
         InviteEmitterEvent,
45
         InviteEmitterEvent,
40
     ];
47
     ];
41
 }
48
 }
42
 
49
 
43
-/**
44
- * Make sure all methods in this module are called in the main (i.e. UI) thread.
45
- */
46
-- (dispatch_queue_t)methodQueue {
47
-    return dispatch_get_main_queue();
48
-}
49
-
50
 /**
50
 /**
51
  * Initiates the process to add people. This involves calling a delegate method
51
  * Initiates the process to add people. This involves calling a delegate method
52
  * in the JMInviteControllerDelegate so the native host application can start
52
  * in the JMInviteControllerDelegate so the native host application can start

Загрузка…
Отмена
Сохранить