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

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
         HANG_UP("org.jitsi.meet.HANG_UP"),
63
         HANG_UP("org.jitsi.meet.HANG_UP"),
64
         SEND_ENDPOINT_TEXT_MESSAGE("org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE"),
64
         SEND_ENDPOINT_TEXT_MESSAGE("org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE"),
65
         TOGGLE_SCREEN_SHARE("org.jitsi.meet.TOGGLE_SCREEN_SHARE"),
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
         private final String action;
71
         private final String action;
69
 
72
 

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

83
         PARTICIPANT_LEFT("org.jitsi.meet.PARTICIPANT_LEFT"),
83
         PARTICIPANT_LEFT("org.jitsi.meet.PARTICIPANT_LEFT"),
84
         ENDPOINT_TEXT_MESSAGE_RECEIVED("org.jitsi.meet.ENDPOINT_TEXT_MESSAGE_RECEIVED"),
84
         ENDPOINT_TEXT_MESSAGE_RECEIVED("org.jitsi.meet.ENDPOINT_TEXT_MESSAGE_RECEIVED"),
85
         SCREEN_SHARE_TOGGLED("org.jitsi.meet.SCREEN_SHARE_TOGGLED"),
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
         private static final String CONFERENCE_WILL_JOIN_NAME = "CONFERENCE_WILL_JOIN";
90
         private static final String CONFERENCE_WILL_JOIN_NAME = "CONFERENCE_WILL_JOIN";
89
         private static final String CONFERENCE_JOINED_NAME = "CONFERENCE_JOINED";
91
         private static final String CONFERENCE_JOINED_NAME = "CONFERENCE_JOINED";
94
         private static final String ENDPOINT_TEXT_MESSAGE_RECEIVED_NAME = "ENDPOINT_TEXT_MESSAGE_RECEIVED";
96
         private static final String ENDPOINT_TEXT_MESSAGE_RECEIVED_NAME = "ENDPOINT_TEXT_MESSAGE_RECEIVED";
95
         private static final String SCREEN_SHARE_TOGGLED_NAME = "SCREEN_SHARE_TOGGLED";
97
         private static final String SCREEN_SHARE_TOGGLED_NAME = "SCREEN_SHARE_TOGGLED";
96
         private static final String PARTICIPANTS_INFO_RETRIEVED_NAME = "PARTICIPANTS_INFO_RETRIEVED";
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
         private final String action;
102
         private final String action;
99
 
103
 
134
                     return SCREEN_SHARE_TOGGLED;
138
                     return SCREEN_SHARE_TOGGLED;
135
                 case PARTICIPANTS_INFO_RETRIEVED_NAME:
139
                 case PARTICIPANTS_INFO_RETRIEVED_NAME:
136
                     return PARTICIPANTS_INFO_RETRIEVED;
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
             return null;
147
             return null;

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

23
     public static Intent buildToggleScreenShareIntent() {
23
     public static Intent buildToggleScreenShareIntent() {
24
         return new Intent(BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
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
         constants.put("SEND_ENDPOINT_TEXT_MESSAGE", BroadcastAction.Type.SEND_ENDPOINT_TEXT_MESSAGE.getAction());
82
         constants.put("SEND_ENDPOINT_TEXT_MESSAGE", BroadcastAction.Type.SEND_ENDPOINT_TEXT_MESSAGE.getAction());
83
         constants.put("TOGGLE_SCREEN_SHARE", BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
83
         constants.put("TOGGLE_SCREEN_SHARE", BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
84
         constants.put("RETRIEVE_PARTICIPANTS_INFO", BroadcastAction.Type.RETRIEVE_PARTICIPANTS_INFO.getAction());
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
         return constants;
89
         return constants;
87
     }
90
     }

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

123
   NSLog(@"%@%@", @"Screen share toggled: ", data);
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
 #pragma mark - Helpers
134
 #pragma mark - Helpers
127
 
135
 
128
 - (void)terminate {
136
 - (void)terminate {

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

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

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

23
 static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
23
 static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
24
 static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
24
 static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
25
 static NSString * const retrieveParticipantsInfoAction = @"org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO";
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
 @implementation ExternalAPI
30
 @implementation ExternalAPI
28
 
31
 
41
         @"SET_AUDIO_MUTED" : setAudioMutedAction,
44
         @"SET_AUDIO_MUTED" : setAudioMutedAction,
42
         @"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction,
45
         @"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction,
43
         @"TOGGLE_SCREEN_SHARE": toggleScreenShareAction,
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
               setAudioMutedAction,
67
               setAudioMutedAction,
62
               sendEndpointTextMessageAction,
68
               sendEndpointTextMessageAction,
63
               toggleScreenShareAction,
69
               toggleScreenShareAction,
64
-              retrieveParticipantsInfoAction];
70
+              retrieveParticipantsInfoAction,
71
+              openChatAction,
72
+              closeChatAction,
73
+              sendChatMessageAction
74
+    ];
65
 }
75
 }
66
 
76
 
67
 /**
77
 /**
144
 }
154
 }
145
 
155
 
146
 - (void)sendEndpointTextMessage:(NSString*)to :(NSString*)message {
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
     [self sendEventWithName:sendEndpointTextMessageAction body:data];
161
     [self sendEventWithName:sendEndpointTextMessageAction body:data];
153
 }
162
 }
164
     
173
     
165
     [self sendEventWithName:retrieveParticipantsInfoAction body:data];
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
 @end
196
 @end

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

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

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

140
     [externalAPI retrieveParticipantsInfo:completionHandler];
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
 #pragma mark Private methods
158
 #pragma mark Private methods
144
 
159
 
145
 /**
160
 /**

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

90
  */
90
  */
91
 - (void)screenShareToggled:(NSDictionary *)data;
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
 @end
107
 @end

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

104
         if (typeof APP !== 'undefined') {
104
         if (typeof APP !== 'undefined') {
105
             APP.API.notifyChatUpdated(unreadCount, true);
105
             APP.API.notifyChatUpdated(unreadCount, true);
106
         }
106
         }
107
+
108
+        dispatch(setActiveModalId());
107
         break;
109
         break;
108
 
110
 
109
     case SEND_MESSAGE: {
111
     case SEND_MESSAGE: {

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

27
 } from '../../base/connection';
27
 } from '../../base/connection';
28
 import { JitsiConferenceEvents } from '../../base/lib-jitsi-meet';
28
 import { JitsiConferenceEvents } from '../../base/lib-jitsi-meet';
29
 import { SET_AUDIO_MUTED } from '../../base/media/actionTypes';
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
 import { MiddlewareRegistry, StateListenerRegistry } from '../../base/redux';
31
 import { MiddlewareRegistry, StateListenerRegistry } from '../../base/redux';
32
 import { toggleScreensharing } from '../../base/tracks';
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
 import { muteLocal } from '../../remote-video-menu/actions';
36
 import { muteLocal } from '../../remote-video-menu/actions';
34
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
37
 import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
35
 
38
 
37
 import { sendEvent } from './functions';
40
 import { sendEvent } from './functions';
38
 import logger from './logger';
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
  * Event which will be emitted on the native side to indicate the conference
55
  * Event which will be emitted on the native side to indicate the conference
42
  * has ended either by user request or because an error was produced.
56
  * has ended either by user request or because an error was produced.
152
         break;
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
     case PARTICIPANT_JOINED:
180
     case PARTICIPANT_JOINED:
156
     case PARTICIPANT_LEFT: {
181
     case PARTICIPANT_LEFT: {
157
         const { participant } = action;
182
         const { participant } = action;
237
  * @private
262
  * @private
238
  * @returns {void}
263
  * @returns {void}
239
  */
264
  */
240
-function _registerForNativeEvents({ getState, dispatch }) {
265
+function _registerForNativeEvents(store) {
266
+    const { getState, dispatch } = store;
267
+
241
     eventEmitter.addListener(ExternalAPI.HANG_UP, () => {
268
     eventEmitter.addListener(ExternalAPI.HANG_UP, () => {
242
         dispatch(appNavigate(undefined));
269
         dispatch(appNavigate(undefined));
243
     });
270
     });
264
     });
291
     });
265
 
292
 
266
     eventEmitter.addListener(ExternalAPI.RETRIEVE_PARTICIPANTS_INFO, ({ requestId }) => {
293
     eventEmitter.addListener(ExternalAPI.RETRIEVE_PARTICIPANTS_INFO, ({ requestId }) => {
267
-        const store = getState();
268
 
294
 
269
         const participantsInfo = getParticipants(store).map(participant => {
295
         const participantsInfo = getParticipants(store).map(participant => {
270
             return {
296
             return {
286
                 requestId
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
                 }
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
 /**

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