Sfoglia il codice sorgente

external_api: add ability to send a text message through datachannels

master
horymury 5 anni fa
parent
commit
4616065b1d
Nessun account collegato all'indirizzo email del committer
5 ha cambiato i file con 71 aggiunte e 4 eliminazioni
  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 Vedi File

@@ -2,6 +2,7 @@
2 2
 
3 3
 import { openConnection } from './connection';
4 4
 
5
+import { ENDPOINT_TEXT_MESSAGE_NAME } from './modules/API/constants';
5 6
 import AuthHandler from './modules/UI/authentication/AuthHandler';
6 7
 import Recorder from './modules/recorder/Recorder';
7 8
 
@@ -2041,7 +2042,22 @@ export default {
2041 2042
 
2042 2043
         room.on(
2043 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 2062
         room.on(
2047 2063
             JitsiConferenceEvents.LOCK_STATE_CHANGED,

+ 20
- 0
doc/api.md Vedi File

@@ -270,6 +270,11 @@ api.executeCommand('email', 'example@example.com');
270 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 278
 You can also execute multiple commands using the `executeCommands` method:
274 279
 ```javascript
275 280
 api.executeCommands(commands);
@@ -323,6 +328,21 @@ changes. The listener will receive an object with the following structure:
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 346
 * **micError** - event notifications about Jitsi-Meet having failed to access the mic. The listener will receive an object with the following structure:
327 347
 ```javascript
328 348
 {

+ 26
- 1
modules/API/API.js Vedi File

@@ -15,7 +15,7 @@ import { invite } from '../../react/features/invite';
15 15
 import { toggleTileView } from '../../react/features/video-layout';
16 16
 import { getJitsiMeetTransport } from '../transport';
17 17
 
18
-import { API_ID } from './constants';
18
+import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
19 19
 import {
20 20
     processExternalDeviceRequest
21 21
 } from '../../react/features/device-selection/functions';
@@ -155,6 +155,17 @@ function initCommands() {
155 155
         'avatar-url': avatarUrl => {
156 156
             sendAnalytics(createApiEvent('avatar.url.changed'));
157 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 171
     transport.on('event', ({ data, name }) => {
@@ -437,6 +448,20 @@ class API {
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 466
      * Notify external application (if API is enabled) that the device list has
442 467
      * changed.

+ 6
- 2
modules/API/constants.js Vedi File

@@ -9,5 +9,9 @@ import parseURLParams from '../../react/features/base/config/parseURLParams';
9 9
 /**
10 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 Vedi File

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

Loading…
Annulla
Salva