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

feat(mobile) adds actions and events for the chat

master
tmoldovan8x8 4 лет назад
Родитель
Сommit
f71e8a9982
Аккаунт пользователя с таким Email не найден

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

@@ -63,7 +63,10 @@ public class BroadcastAction {
63 63
         HANG_UP("org.jitsi.meet.HANG_UP"),
64 64
         SEND_ENDPOINT_TEXT_MESSAGE("org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE"),
65 65
         TOGGLE_SCREEN_SHARE("org.jitsi.meet.TOGGLE_SCREEN_SHARE"),
66
-        RETRIEVE_PARTICIPANTS_INFO("org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO");
66
+        RETRIEVE_PARTICIPANTS_INFO("org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO"),
67
+        OPEN_CHAT("org.jitsi.meet.OPEN_CHAT"),
68
+        CLOSE_CHAT("org.jitsi.meet.CLOSE_CHAT"),
69
+        SEND_CHAT_MESSAGE("org.jitsi.meet.SEND_CHAT_MESSAGE");
67 70
 
68 71
         private final String action;
69 72
 

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

@@ -83,7 +83,9 @@ public class BroadcastEvent {
83 83
         PARTICIPANT_LEFT("org.jitsi.meet.PARTICIPANT_LEFT"),
84 84
         ENDPOINT_TEXT_MESSAGE_RECEIVED("org.jitsi.meet.ENDPOINT_TEXT_MESSAGE_RECEIVED"),
85 85
         SCREEN_SHARE_TOGGLED("org.jitsi.meet.SCREEN_SHARE_TOGGLED"),
86
-        PARTICIPANTS_INFO_RETRIEVED("org.jitsi.meet.PARTICIPANTS_INFO_RETRIEVED");
86
+        PARTICIPANTS_INFO_RETRIEVED("org.jitsi.meet.PARTICIPANTS_INFO_RETRIEVED"),
87
+        CHAT_MESSAGE_RECEIVED("org.jitsi.meet.CHAT_MESSAGE_RECEIVED"),
88
+        CHAT_TOGGLED("org.jitsi.meet.CHAT_TOGGLED");
87 89
 
88 90
         private static final String CONFERENCE_WILL_JOIN_NAME = "CONFERENCE_WILL_JOIN";
89 91
         private static final String CONFERENCE_JOINED_NAME = "CONFERENCE_JOINED";
@@ -94,6 +96,8 @@ public class BroadcastEvent {
94 96
         private static final String ENDPOINT_TEXT_MESSAGE_RECEIVED_NAME = "ENDPOINT_TEXT_MESSAGE_RECEIVED";
95 97
         private static final String SCREEN_SHARE_TOGGLED_NAME = "SCREEN_SHARE_TOGGLED";
96 98
         private static final String PARTICIPANTS_INFO_RETRIEVED_NAME = "PARTICIPANTS_INFO_RETRIEVED";
99
+        private static final String CHAT_MESSAGE_RECEIVED_NAME = "CHAT_MESSAGE_RECEIVED";
100
+        private static final String CHAT_TOGGLED_NAME = "CHAT_TOGGLED";
97 101
 
98 102
         private final String action;
99 103
 
@@ -134,6 +138,10 @@ public class BroadcastEvent {
134 138
                     return SCREEN_SHARE_TOGGLED;
135 139
                 case PARTICIPANTS_INFO_RETRIEVED_NAME:
136 140
                     return PARTICIPANTS_INFO_RETRIEVED;
141
+                case CHAT_MESSAGE_RECEIVED_NAME:
142
+                    return CHAT_MESSAGE_RECEIVED;
143
+                case CHAT_TOGGLED_NAME:
144
+                    return CHAT_TOGGLED;
137 145
             }
138 146
 
139 147
             return null;

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

@@ -23,4 +23,21 @@ public class BroadcastIntentHelper {
23 23
     public static Intent buildToggleScreenShareIntent() {
24 24
         return new Intent(BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
25 25
     }
26
+
27
+    public static Intent buildOpenChatIntent(String participantId) {
28
+        Intent intent = new Intent(BroadcastAction.Type.OPEN_CHAT.getAction());
29
+        intent.putExtra("to", participantId);
30
+        return intent;
31
+    }
32
+
33
+    public static Intent buildCloseChatIntent() {
34
+        return new Intent(BroadcastAction.Type.CLOSE_CHAT.getAction());
35
+    }
36
+
37
+    public static Intent buildSendChatMessageIntent(String participantId, String message) {
38
+        Intent intent = new Intent(BroadcastAction.Type.SEND_CHAT_MESSAGE.getAction());
39
+        intent.putExtra("to", participantId);
40
+        intent.putExtra("message", message);
41
+        return intent;
42
+    }
26 43
 }

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

@@ -82,6 +82,9 @@ class ExternalAPIModule
82 82
         constants.put("SEND_ENDPOINT_TEXT_MESSAGE", BroadcastAction.Type.SEND_ENDPOINT_TEXT_MESSAGE.getAction());
83 83
         constants.put("TOGGLE_SCREEN_SHARE", BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
84 84
         constants.put("RETRIEVE_PARTICIPANTS_INFO", BroadcastAction.Type.RETRIEVE_PARTICIPANTS_INFO.getAction());
85
+        constants.put("OPEN_CHAT", BroadcastAction.Type.OPEN_CHAT.getAction());
86
+        constants.put("CLOSE_CHAT", BroadcastAction.Type.CLOSE_CHAT.getAction());
87
+        constants.put("SEND_CHAT_MESSAGE", BroadcastAction.Type.SEND_CHAT_MESSAGE.getAction());
85 88
 
86 89
         return constants;
87 90
     }

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

@@ -123,6 +123,14 @@
123 123
   NSLog(@"%@%@", @"Screen share toggled: ", data);
124 124
 }
125 125
 
126
+- (void)chatMessageReceived:(NSDictionary *)data {
127
+    NSLog(@"%@%@", @"Chat message received: ", data);
128
+}
129
+
130
+- (void)chatToggled:(NSDictionary *)data {
131
+  NSLog(@"%@%@", @"Chat toggled: ", data);
132
+}
133
+
126 134
 #pragma mark - Helpers
127 135
 
128 136
 - (void)terminate {

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

@@ -19,9 +19,12 @@
19 19
 @interface ExternalAPI : RCTEventEmitter<RCTBridgeModule>
20 20
 
21 21
 - (void)sendHangUp;
22
-- (void)sendSetAudioMuted: (BOOL)muted;
22
+- (void)sendSetAudioMuted:(BOOL)muted;
23 23
 - (void)sendEndpointTextMessage:(NSString*)to :(NSString*)message;
24 24
 - (void)toggleScreenShare;
25 25
 - (void)retrieveParticipantsInfo:(void (^)(NSArray*))completion;
26
+- (void)openChat:(NSString*)to;
27
+- (void)closeChat;
28
+- (void)sendChatMessage:(NSString*)to :(NSString*)message;
26 29
 
27 30
 @end

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

@@ -23,6 +23,9 @@ static NSString * const setAudioMutedAction = @"org.jitsi.meet.SET_AUDIO_MUTED";
23 23
 static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
24 24
 static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
25 25
 static NSString * const retrieveParticipantsInfoAction = @"org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO";
26
+static NSString * const openChatAction = @"org.jitsi.meet.OPEN_CHAT";
27
+static NSString * const closeChatAction = @"org.jitsi.meet.CLOSE_CHAT";
28
+static NSString * const sendChatMessageAction = @"org.jitsi.meet.SEND_CHAT_MESSAGE";
26 29
 
27 30
 @implementation ExternalAPI
28 31
 
@@ -41,7 +44,10 @@ RCT_EXPORT_MODULE();
41 44
         @"SET_AUDIO_MUTED" : setAudioMutedAction,
42 45
         @"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction,
43 46
         @"TOGGLE_SCREEN_SHARE": toggleScreenShareAction,
44
-        @"RETRIEVE_PARTICIPANTS_INFO": retrieveParticipantsInfoAction
47
+        @"RETRIEVE_PARTICIPANTS_INFO": retrieveParticipantsInfoAction,
48
+        @"OPEN_CHAT": openChatAction,
49
+        @"CLOSE_CHAT": closeChatAction,
50
+        @"SEND_CHAT_MESSAGE": sendChatMessageAction
45 51
     };
46 52
 };
47 53
 
@@ -61,7 +67,11 @@ RCT_EXPORT_MODULE();
61 67
               setAudioMutedAction,
62 68
               sendEndpointTextMessageAction,
63 69
               toggleScreenShareAction,
64
-              retrieveParticipantsInfoAction];
70
+              retrieveParticipantsInfoAction,
71
+              openChatAction,
72
+              closeChatAction,
73
+              sendChatMessageAction
74
+    ];
65 75
 }
66 76
 
67 77
 /**
@@ -144,10 +154,9 @@ RCT_EXPORT_METHOD(sendEvent:(NSString *)name
144 154
 }
145 155
 
146 156
 - (void)sendEndpointTextMessage:(NSString*)to :(NSString*)message {
147
-    NSDictionary *data = @{
148
-        @"to": to,
149
-        @"message": message
150
-    };
157
+    NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
158
+    data[@"to"] = to;
159
+    data[@"message"] = message;
151 160
     
152 161
     [self sendEventWithName:sendEndpointTextMessageAction body:data];
153 162
 }
@@ -164,4 +173,24 @@ RCT_EXPORT_METHOD(sendEvent:(NSString *)name
164 173
     
165 174
     [self sendEventWithName:retrieveParticipantsInfoAction body:data];
166 175
 }
176
+
177
+- (void)openChat:(NSString*)to {
178
+    NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
179
+    data[@"to"] = to;
180
+    
181
+    [self sendEventWithName:openChatAction body:data];
182
+}
183
+
184
+- (void)closeChat {
185
+    [self sendEventWithName:closeChatAction body:nil];
186
+}
187
+
188
+- (void)sendChatMessage:(NSString*)to :(NSString*)message {
189
+    NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
190
+    data[@"to"] = to;
191
+    data[@"message"] = message;
192
+    
193
+    [self sendEventWithName:sendChatMessageAction body:data];
194
+}
195
+
167 196
 @end

+ 3
- 5
ios/sdk/src/JitsiMeetView.h Просмотреть файл

@@ -36,15 +36,13 @@
36 36
  * Leaves the currently active conference.
37 37
  */
38 38
 - (void)leave;
39
-
40 39
 - (void)hangUp;
41
-
42 40
 - (void)setAudioMuted:(BOOL)muted;
43
-
44 41
 - (void)sendEndpointTextMessage:(NSString*)to :(NSString*)message;
45
-
46 42
 - (void)toggleScreenShare;
47
-
48 43
 - (void)retrieveParticipantsInfo:(void (^)(NSArray*))completionHandler;
44
+- (void)openChat:(NSString*)to;
45
+- (void)closeChat;
46
+- (void)sendChatMessage:(NSString*)to :(NSString*)message;
49 47
 
50 48
 @end

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

@@ -140,6 +140,21 @@ static void initializeViewsMap() {
140 140
     [externalAPI retrieveParticipantsInfo:completionHandler];
141 141
 }
142 142
 
143
+- (void)openChat:(NSString*)to  {
144
+    ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
145
+    [externalAPI openChat:to];
146
+}
147
+
148
+- (void)closeChat  {
149
+    ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
150
+    [externalAPI closeChat];
151
+}
152
+
153
+- (void)sendChatMessage:(NSString*)to :(NSString*)message  {
154
+    ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
155
+    [externalAPI sendChatMessage:to :message];
156
+}
157
+
143 158
 #pragma mark Private methods
144 159
 
145 160
 /**

+ 14
- 0
ios/sdk/src/JitsiMeetViewDelegate.h Просмотреть файл

@@ -90,4 +90,18 @@
90 90
  */
91 91
 - (void)screenShareToggled:(NSDictionary *)data;
92 92
 
93
+/**
94
+ * Called when a chat message is received.
95
+ *
96
+ * The `data` dictionary contains `message`, `senderId` and  `isPrivate` keys.
97
+ */
98
+- (void)chatMessaageReceived:(NSDictionary *)data;
99
+
100
+/**
101
+ * Called when the chat dialog is displayed/hidden.
102
+ *
103
+ * The `data` dictionary contains a `isOpen` key.
104
+ */
105
+- (void)chatToggled:(NSDictionary *)data;
106
+
93 107
 @end

+ 2
- 0
react/features/chat/middleware.js Просмотреть файл

@@ -104,6 +104,8 @@ MiddlewareRegistry.register(store => next => action => {
104 104
         if (typeof APP !== 'undefined') {
105 105
             APP.API.notifyChatUpdated(unreadCount, true);
106 106
         }
107
+
108
+        dispatch(setActiveModalId());
107 109
         break;
108 110
 
109 111
     case SEND_MESSAGE: {

+ 80
- 3
react/features/mobile/external-api/middleware.js Просмотреть файл

@@ -27,9 +27,12 @@ import {
27 27
 } from '../../base/connection';
28 28
 import { JitsiConferenceEvents } from '../../base/lib-jitsi-meet';
29 29
 import { SET_AUDIO_MUTED } from '../../base/media/actionTypes';
30
-import { PARTICIPANT_JOINED, PARTICIPANT_LEFT, getParticipants } from '../../base/participants';
30
+import { PARTICIPANT_JOINED, PARTICIPANT_LEFT, getParticipants, getParticipantById } from '../../base/participants';
31 31
 import { MiddlewareRegistry, StateListenerRegistry } from '../../base/redux';
32 32
 import { toggleScreensharing } from '../../base/tracks';
33
+import { OPEN_CHAT, CLOSE_CHAT } from '../../chat';
34
+import { openChat } from '../../chat/actions';
35
+import { sendMessage, setPrivateMessageRecipient, closeChat } from '../../chat/actions.any';
33 36
 import { muteLocal } from '../../remote-video-menu/actions';
34 37
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
35 38
 
@@ -37,6 +40,17 @@ import { setParticipantsWithScreenShare } from './actions';
37 40
 import { sendEvent } from './functions';
38 41
 import logger from './logger';
39 42
 
43
+/**
44
+ * Event which will be emitted on the native side when a chat message is received
45
+ * through the channel.
46
+ */
47
+const CHAT_MESSAGE_RECEIVED = 'CHAT_MESSAGE_RECEIVED';
48
+
49
+/**
50
+ * Event which will be emitted on the native side when the chat dialog is displayed/closed.
51
+ */
52
+const CHAT_TOGGLED = 'CHAT_TOGGLED';
53
+
40 54
 /**
41 55
  * Event which will be emitted on the native side to indicate the conference
42 56
  * has ended either by user request or because an error was produced.
@@ -152,6 +166,17 @@ MiddlewareRegistry.register(store => next => action => {
152 166
         break;
153 167
     }
154 168
 
169
+    case OPEN_CHAT:
170
+    case CLOSE_CHAT: {
171
+        sendEvent(
172
+            store,
173
+            CHAT_TOGGLED,
174
+            /* data */ {
175
+                isOpen: action.type === OPEN_CHAT
176
+            });
177
+        break;
178
+    }
179
+
155 180
     case PARTICIPANT_JOINED:
156 181
     case PARTICIPANT_LEFT: {
157 182
         const { participant } = action;
@@ -237,7 +262,9 @@ StateListenerRegistry.register(
237 262
  * @private
238 263
  * @returns {void}
239 264
  */
240
-function _registerForNativeEvents({ getState, dispatch }) {
265
+function _registerForNativeEvents(store) {
266
+    const { getState, dispatch } = store;
267
+
241 268
     eventEmitter.addListener(ExternalAPI.HANG_UP, () => {
242 269
         dispatch(appNavigate(undefined));
243 270
     });
@@ -264,7 +291,6 @@ function _registerForNativeEvents({ getState, dispatch }) {
264 291
     });
265 292
 
266 293
     eventEmitter.addListener(ExternalAPI.RETRIEVE_PARTICIPANTS_INFO, ({ requestId }) => {
267
-        const store = getState();
268 294
 
269 295
         const participantsInfo = getParticipants(store).map(participant => {
270 296
             return {
@@ -286,6 +312,27 @@ function _registerForNativeEvents({ getState, dispatch }) {
286 312
                 requestId
287 313
             });
288 314
     });
315
+
316
+    eventEmitter.addListener(ExternalAPI.OPEN_CHAT, ({ to }) => {
317
+        const participant = getParticipantById(store, to);
318
+
319
+        dispatch(openChat(participant));
320
+    });
321
+
322
+    eventEmitter.addListener(ExternalAPI.CLOSE_CHAT, () => {
323
+        dispatch(closeChat());
324
+    });
325
+
326
+    eventEmitter.addListener(ExternalAPI.SEND_CHAT_MESSAGE, ({ message, to }) => {
327
+        const participant = getParticipantById(store, to);
328
+
329
+        if (participant) {
330
+            dispatch(setPrivateMessageRecipient(participant));
331
+        }
332
+
333
+        dispatch(sendMessage(message));
334
+    });
335
+
289 336
 }
290 337
 
291 338
 /**
@@ -315,6 +362,36 @@ function _registerForEndpointTextMessages(store) {
315 362
                 }
316 363
             }
317 364
         });
365
+
366
+    conference.on(
367
+        JitsiConferenceEvents.MESSAGE_RECEIVED,
368
+            (id, message, timestamp) => {
369
+                sendEvent(
370
+                    store,
371
+                    CHAT_MESSAGE_RECEIVED,
372
+                    /* data */ {
373
+                        senderId: id,
374
+                        message,
375
+                        isPrivate: false,
376
+                        timestamp
377
+                    });
378
+            }
379
+    );
380
+
381
+    conference.on(
382
+        JitsiConferenceEvents.PRIVATE_MESSAGE_RECEIVED,
383
+            (id, message, timestamp) => {
384
+                sendEvent(
385
+                    store,
386
+                    CHAT_MESSAGE_RECEIVED,
387
+                    /* data */ {
388
+                        senderId: id,
389
+                        message,
390
+                        isPrivate: true,
391
+                        timestamp
392
+                    });
393
+            }
394
+    );
318 395
 }
319 396
 
320 397
 /**

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