瀏覽代碼

external_api: add ability to send a text message through datachannels

master
horymury 5 年之前
父節點
當前提交
4616065b1d
沒有連結到貢獻者的電子郵件帳戶。
共有 5 個檔案被更改,包括 71 行新增4 行删除
  1. 17
    1
      conference.js
  2. 20
    0
      doc/api.md
  3. 26
    1
      modules/API/API.js
  4. 6
    2
      modules/API/constants.js
  5. 2
    0
      modules/API/external/external_api.js

+ 17
- 1
conference.js 查看文件

2
 
2
 
3
 import { openConnection } from './connection';
3
 import { openConnection } from './connection';
4
 
4
 
5
+import { ENDPOINT_TEXT_MESSAGE_NAME } from './modules/API/constants';
5
 import AuthHandler from './modules/UI/authentication/AuthHandler';
6
 import AuthHandler from './modules/UI/authentication/AuthHandler';
6
 import Recorder from './modules/recorder/Recorder';
7
 import Recorder from './modules/recorder/Recorder';
7
 
8
 
2041
 
2042
 
2042
         room.on(
2043
         room.on(
2043
             JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
2044
             JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
2044
-            (...args) => APP.store.dispatch(endpointMessageReceived(...args)));
2045
+            (...args) => {
2046
+                APP.store.dispatch(endpointMessageReceived(...args));
2047
+                if (args && args.length >= 2) {
2048
+                    const [ sender, eventData ] = args;
2049
+
2050
+                    if (eventData.name === ENDPOINT_TEXT_MESSAGE_NAME) {
2051
+                        APP.API.notifyEndpointTextMessageReceived({
2052
+                            senderInfo: {
2053
+                                jid: sender._jid,
2054
+                                id: sender._id
2055
+                            },
2056
+                            eventData
2057
+                        });
2058
+                    }
2059
+                }
2060
+            });
2045
 
2061
 
2046
         room.on(
2062
         room.on(
2047
             JitsiConferenceEvents.LOCK_STATE_CHANGED,
2063
             JitsiConferenceEvents.LOCK_STATE_CHANGED,

+ 20
- 0
doc/api.md 查看文件

270
 api.executeCommand('avatarUrl', 'https://avatars0.githubusercontent.com/u/3671647');
270
 api.executeCommand('avatarUrl', 'https://avatars0.githubusercontent.com/u/3671647');
271
 ```
271
 ```
272
 
272
 
273
+* **sendEndpointTextMessage** - Sends a text message to another participant through the datachannels.
274
+```javascript
275
+api.executeCommand('receiverParticipantId', 'text');
276
+```
277
+
273
 You can also execute multiple commands using the `executeCommands` method:
278
 You can also execute multiple commands using the `executeCommands` method:
274
 ```javascript
279
 ```javascript
275
 api.executeCommands(commands);
280
 api.executeCommands(commands);
323
 }
328
 }
324
 ```
329
 ```
325
 
330
 
331
+* **endpointTextMessageReceived** - event notifications about a text message received through datachannels.
332
+The listener will receive an object with the following structure:
333
+```javascript
334
+{
335
+    senderInfo: {
336
+        jid: string, // the jid of the sender
337
+        id: string // the participant id of the sender
338
+    },
339
+    eventData: {
340
+        name: string // the name of the datachannel event: `endpoint-text-message`
341
+        text: string // the received text from the sender
342
+    }
343
+}
344
+```
345
+
326
 * **micError** - event notifications about Jitsi-Meet having failed to access the mic. The listener will receive an object with the following structure:
346
 * **micError** - event notifications about Jitsi-Meet having failed to access the mic. The listener will receive an object with the following structure:
327
 ```javascript
347
 ```javascript
328
 {
348
 {

+ 26
- 1
modules/API/API.js 查看文件

15
 import { toggleTileView } from '../../react/features/video-layout';
15
 import { toggleTileView } from '../../react/features/video-layout';
16
 import { getJitsiMeetTransport } from '../transport';
16
 import { getJitsiMeetTransport } from '../transport';
17
 
17
 
18
-import { API_ID } from './constants';
18
+import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
19
 import {
19
 import {
20
     processExternalDeviceRequest
20
     processExternalDeviceRequest
21
 } from '../../react/features/device-selection/functions';
21
 } from '../../react/features/device-selection/functions';
155
         'avatar-url': avatarUrl => {
155
         'avatar-url': avatarUrl => {
156
             sendAnalytics(createApiEvent('avatar.url.changed'));
156
             sendAnalytics(createApiEvent('avatar.url.changed'));
157
             APP.conference.changeLocalAvatarUrl(avatarUrl);
157
             APP.conference.changeLocalAvatarUrl(avatarUrl);
158
+        },
159
+        'send-endpoint-text-message': (to, text) => {
160
+            logger.debug('Send endpoint message command received');
161
+            try {
162
+                APP.conference.sendEndpointMessage(to, {
163
+                    name: ENDPOINT_TEXT_MESSAGE_NAME,
164
+                    text
165
+                });
166
+            } catch (err) {
167
+                logger.error('Failed sending endpoint text message', err);
168
+            }
158
         }
169
         }
159
     };
170
     };
160
     transport.on('event', ({ data, name }) => {
171
     transport.on('event', ({ data, name }) => {
437
         });
448
         });
438
     }
449
     }
439
 
450
 
451
+    /**
452
+     * Notify external application (if API is enabled) that user received
453
+     * a text message through datachannels.
454
+     *
455
+     * @param {Object} data - The event data.
456
+     * @returns {void}
457
+     */
458
+    notifyEndpointTextMessageReceived(data: Object) {
459
+        this._sendEvent({
460
+            name: 'endpoint-text-message-received',
461
+            data
462
+        });
463
+    }
464
+
440
     /**
465
     /**
441
      * Notify external application (if API is enabled) that the device list has
466
      * Notify external application (if API is enabled) that the device list has
442
      * changed.
467
      * changed.

+ 6
- 2
modules/API/constants.js 查看文件

9
 /**
9
 /**
10
  * JitsiMeetExternalAPI id - unique for a webpage.
10
  * JitsiMeetExternalAPI id - unique for a webpage.
11
  */
11
  */
12
-export const API_ID
13
-    = parseURLParams(window.location).jitsi_meet_external_api_id;
12
+export const API_ID = parseURLParams(window.location).jitsi_meet_external_api_id;
13
+
14
+/**
15
+ * The payload name for the datachannel/endpoint text message event
16
+ */
17
+export const ENDPOINT_TEXT_MESSAGE_NAME = 'endpoint-text-message';

+ 2
- 0
modules/API/external/external_api.js 查看文件

32
     email: 'email',
32
     email: 'email',
33
     hangup: 'video-hangup',
33
     hangup: 'video-hangup',
34
     password: 'password',
34
     password: 'password',
35
+    sendEndpointTextMessage: 'send-endpoint-text-message',
35
     sendTones: 'send-tones',
36
     sendTones: 'send-tones',
36
     subject: 'subject',
37
     subject: 'subject',
37
     submitFeedback: 'submit-feedback',
38
     submitFeedback: 'submit-feedback',
55
     'device-list-changed': 'deviceListChanged',
56
     'device-list-changed': 'deviceListChanged',
56
     'display-name-change': 'displayNameChange',
57
     'display-name-change': 'displayNameChange',
57
     'email-change': 'emailChange',
58
     'email-change': 'emailChange',
59
+    'endpoint-text-message-received': 'endpointTextMessageReceived',
58
     'feedback-submitted': 'feedbackSubmitted',
60
     'feedback-submitted': 'feedbackSubmitted',
59
     'feedback-prompt-displayed': 'feedbackPromptDisplayed',
61
     'feedback-prompt-displayed': 'feedbackPromptDisplayed',
60
     'filmstrip-display-changed': 'filmstripDisplayChanged',
62
     'filmstrip-display-changed': 'filmstripDisplayChanged',

Loading…
取消
儲存