|
@@ -2,6 +2,7 @@
|
2
|
2
|
|
3
|
3
|
import { NativeEventEmitter, NativeModules } from 'react-native';
|
4
|
4
|
|
|
5
|
+import { ENDPOINT_TEXT_MESSAGE_NAME } from '../../../../modules/API/constants';
|
5
|
6
|
import { appNavigate } from '../../app/actions';
|
6
|
7
|
import { APP_WILL_MOUNT } from '../../base/app/actionTypes';
|
7
|
8
|
import {
|
|
@@ -12,6 +13,7 @@ import {
|
12
|
13
|
JITSI_CONFERENCE_URL_KEY,
|
13
|
14
|
SET_ROOM,
|
14
|
15
|
forEachConference,
|
|
16
|
+ getCurrentConference,
|
15
|
17
|
isRoomValid
|
16
|
18
|
} from '../../base/conference';
|
17
|
19
|
import { LOAD_CONFIG_ERROR } from '../../base/config';
|
|
@@ -22,6 +24,7 @@ import {
|
22
|
24
|
JITSI_CONNECTION_URL_KEY,
|
23
|
25
|
getURLWithoutParams
|
24
|
26
|
} from '../../base/connection';
|
|
27
|
+import { JitsiConferenceEvents } from '../../base/lib-jitsi-meet';
|
25
|
28
|
import { SET_AUDIO_MUTED } from '../../base/media/actionTypes';
|
26
|
29
|
import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../../base/participants';
|
27
|
30
|
import { MiddlewareRegistry } from '../../base/redux';
|
|
@@ -29,6 +32,7 @@ import { muteLocal } from '../../remote-video-menu/actions';
|
29
|
32
|
import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
|
30
|
33
|
|
31
|
34
|
import { sendEvent } from './functions';
|
|
35
|
+import logger from './logger';
|
32
|
36
|
|
33
|
37
|
/**
|
34
|
38
|
* Event which will be emitted on the native side to indicate the conference
|
|
@@ -36,6 +40,12 @@ import { sendEvent } from './functions';
|
36
|
40
|
*/
|
37
|
41
|
const CONFERENCE_TERMINATED = 'CONFERENCE_TERMINATED';
|
38
|
42
|
|
|
43
|
+/**
|
|
44
|
+ * Event which will be emitted on the native side to indicate a message was received
|
|
45
|
+ * through the channel.
|
|
46
|
+ */
|
|
47
|
+const ENDPOINT_TEXT_MESSAGE_RECEIVED = 'ENDPOINT_TEXT_MESSAGE_RECEIVED';
|
|
48
|
+
|
39
|
49
|
const { ExternalAPI } = NativeModules;
|
40
|
50
|
const eventEmitter = new NativeEventEmitter(ExternalAPI);
|
41
|
51
|
|
|
@@ -52,7 +62,7 @@ MiddlewareRegistry.register(store => next => action => {
|
52
|
62
|
|
53
|
63
|
switch (type) {
|
54
|
64
|
case APP_WILL_MOUNT:
|
55
|
|
- _registerForNativeEvents(store.dispatch);
|
|
65
|
+ _registerForNativeEvents(store);
|
56
|
66
|
break;
|
57
|
67
|
case CONFERENCE_FAILED: {
|
58
|
68
|
const { error, ...data } = action;
|
|
@@ -75,12 +85,16 @@ MiddlewareRegistry.register(store => next => action => {
|
75
|
85
|
break;
|
76
|
86
|
}
|
77
|
87
|
|
78
|
|
- case CONFERENCE_JOINED:
|
79
|
88
|
case CONFERENCE_LEFT:
|
80
|
89
|
case CONFERENCE_WILL_JOIN:
|
81
|
90
|
_sendConferenceEvent(store, action);
|
82
|
91
|
break;
|
83
|
92
|
|
|
93
|
+ case CONFERENCE_JOINED:
|
|
94
|
+ _sendConferenceEvent(store, action);
|
|
95
|
+ _registerForEndpointTextMessages(store);
|
|
96
|
+ break;
|
|
97
|
+
|
84
|
98
|
case CONNECTION_DISCONNECTED: {
|
85
|
99
|
// FIXME: This is a hack. See the description in the JITSI_CONNECTION_CONFERENCE_KEY constant definition.
|
86
|
100
|
// Check if this connection was attached to any conference. If it wasn't, fake a CONFERENCE_TERMINATED event.
|
|
@@ -160,11 +174,11 @@ MiddlewareRegistry.register(store => next => action => {
|
160
|
174
|
/**
|
161
|
175
|
* Registers for events sent from the native side via NativeEventEmitter.
|
162
|
176
|
*
|
163
|
|
- * @param {Dispatch} dispatch - The Redux dispatch function.
|
|
177
|
+ * @param {Store} store - The redux store.
|
164
|
178
|
* @private
|
165
|
179
|
* @returns {void}
|
166
|
180
|
*/
|
167
|
|
-function _registerForNativeEvents(dispatch) {
|
|
181
|
+function _registerForNativeEvents({ getState, dispatch }) {
|
168
|
182
|
eventEmitter.addListener(ExternalAPI.HANG_UP, () => {
|
169
|
183
|
dispatch(appNavigate(undefined));
|
170
|
184
|
});
|
|
@@ -172,6 +186,48 @@ function _registerForNativeEvents(dispatch) {
|
172
|
186
|
eventEmitter.addListener(ExternalAPI.SET_AUDIO_MUTED, ({ muted }) => {
|
173
|
187
|
dispatch(muteLocal(muted === 'true'));
|
174
|
188
|
});
|
|
189
|
+
|
|
190
|
+ eventEmitter.addListener(ExternalAPI.SEND_ENDPOINT_TEXT_MESSAGE, ({ to, message }) => {
|
|
191
|
+ const conference = getCurrentConference(getState());
|
|
192
|
+
|
|
193
|
+ try {
|
|
194
|
+ conference && conference.sendEndpointMessage(to, {
|
|
195
|
+ name: ENDPOINT_TEXT_MESSAGE_NAME,
|
|
196
|
+ text: message
|
|
197
|
+ });
|
|
198
|
+ } catch (error) {
|
|
199
|
+ logger.warn('Cannot send endpointMessage', error);
|
|
200
|
+ }
|
|
201
|
+ });
|
|
202
|
+}
|
|
203
|
+
|
|
204
|
+/**
|
|
205
|
+ * Registers for endpoint messages sent on conference data channel.
|
|
206
|
+ *
|
|
207
|
+ * @param {Store} store - The redux store.
|
|
208
|
+ * @private
|
|
209
|
+ * @returns {void}
|
|
210
|
+ */
|
|
211
|
+function _registerForEndpointTextMessages(store) {
|
|
212
|
+ const conference = getCurrentConference(store.getState());
|
|
213
|
+
|
|
214
|
+ conference && conference.on(
|
|
215
|
+ JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
|
|
216
|
+ (...args) => {
|
|
217
|
+ if (args && args.length >= 2) {
|
|
218
|
+ const [ sender, eventData ] = args;
|
|
219
|
+
|
|
220
|
+ if (eventData.name === ENDPOINT_TEXT_MESSAGE_NAME) {
|
|
221
|
+ sendEvent(
|
|
222
|
+ store,
|
|
223
|
+ ENDPOINT_TEXT_MESSAGE_RECEIVED,
|
|
224
|
+ /* data */ {
|
|
225
|
+ message: eventData.text,
|
|
226
|
+ senderId: sender._id
|
|
227
|
+ });
|
|
228
|
+ }
|
|
229
|
+ }
|
|
230
|
+ });
|
175
|
231
|
}
|
176
|
232
|
|
177
|
233
|
/**
|