Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
external_api: add ability to send a text message through datachannels
horymury4616065b1dd7
diff --git a/conference.js b/conference.jsindex 798e7e49e2..9b273c5c6d 100644--- a/conference.js+++ b/conference.js@@ -2,6 +2,7 @@import { openConnection } from './connection';+import { ENDPOINT_TEXT_MESSAGE_NAME } from './modules/API/constants';import AuthHandler from './modules/UI/authentication/AuthHandler';import Recorder from './modules/recorder/Recorder';@@ -2041,7 +2042,22 @@ export default {room.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,- (...args) => APP.store.dispatch(endpointMessageReceived(...args)));+ (...args) => {+ APP.store.dispatch(endpointMessageReceived(...args));+ if (args && args.length >= 2) {+ const [ sender, eventData ] = args;++ if (eventData.name === ENDPOINT_TEXT_MESSAGE_NAME) {+ APP.API.notifyEndpointTextMessageReceived({+ senderInfo: {+ jid: sender._jid,+ id: sender._id+ },+ eventData+ });+ }+ }+ });room.on(JitsiConferenceEvents.LOCK_STATE_CHANGED,diff --git a/doc/api.md b/doc/api.mdindex bea898d9a7..0da7c9a76b 100644--- a/doc/api.md+++ b/doc/api.md@@ -270,6 +270,11 @@ api.executeCommand('email', '[email protected]');api.executeCommand('avatarUrl', 'https://avatars0.githubusercontent.com/u/3671647');```+* **sendEndpointTextMessage** - Sends a text message to another participant through the datachannels.+```javascript+api.executeCommand('receiverParticipantId', 'text');+```+You can also execute multiple commands using the `executeCommands` method:```javascriptapi.executeCommands(commands);@@ -323,6 +328,21 @@ changes. The listener will receive an object with the following structure:}```+* **endpointTextMessageReceived** - event notifications about a text message received through datachannels.+The listener will receive an object with the following structure:+```javascript+{+ senderInfo: {+ jid: string, // the jid of the sender+ id: string // the participant id of the sender+ },+ eventData: {+ name: string // the name of the datachannel event: `endpoint-text-message`+ text: string // the received text from the sender+ }+}+```+* **micError** - event notifications about Jitsi-Meet having failed to access the mic. The listener will receive an object with the following structure:```javascript{diff --git a/modules/API/API.js b/modules/API/API.jsindex 2144bdff50..76306c28c8 100644--- a/modules/API/API.js+++ b/modules/API/API.js@@ -15,7 +15,7 @@ import { invite } from '../../react/features/invite';import { toggleTileView } from '../../react/features/video-layout';import { getJitsiMeetTransport } from '../transport';-import { API_ID } from './constants';+import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';import {processExternalDeviceRequest} from '../../react/features/device-selection/functions';@@ -155,6 +155,17 @@ function initCommands() {'avatar-url': avatarUrl => {sendAnalytics(createApiEvent('avatar.url.changed'));APP.conference.changeLocalAvatarUrl(avatarUrl);+ },+ 'send-endpoint-text-message': (to, text) => {+ logger.debug('Send endpoint message command received');+ try {+ APP.conference.sendEndpointMessage(to, {+ name: ENDPOINT_TEXT_MESSAGE_NAME,+ text+ });+ } catch (err) {+ logger.error('Failed sending endpoint text message', err);+ }}};transport.on('event', ({ data, name }) => {@@ -437,6 +448,20 @@ class API {});}+ /**+ * Notify external application (if API is enabled) that user received+ * a text message through datachannels.+ *+ * @param {Object} data - The event data.+ * @returns {void}+ */+ notifyEndpointTextMessageReceived(data: Object) {+ this._sendEvent({+ name: 'endpoint-text-message-received',+ data+ });+ }+/*** Notify external application (if API is enabled) that the device list has* changed.diff --git a/modules/API/constants.js b/modules/API/constants.jsindex 600dfc3238..d7a3f2b267 100644--- a/modules/API/constants.js+++ b/modules/API/constants.js@@ -9,5 +9,9 @@ import parseURLParams from '../../react/features/base/config/parseURLParams';/*** JitsiMeetExternalAPI id - unique for a webpage.*/-export const API_ID- = parseURLParams(window.location).jitsi_meet_external_api_id;+export const API_ID = parseURLParams(window.location).jitsi_meet_external_api_id;++/**+ * The payload name for the datachannel/endpoint text message event+ */+export const ENDPOINT_TEXT_MESSAGE_NAME = 'endpoint-text-message';diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.jsindex 4960d952d9..c0c956627d 100644--- a/modules/API/external/external_api.js+++ b/modules/API/external/external_api.js@@ -32,6 +32,7 @@ const commands = {email: 'email',hangup: 'video-hangup',password: 'password',+ sendEndpointTextMessage: 'send-endpoint-text-message',sendTones: 'send-tones',subject: 'subject',submitFeedback: 'submit-feedback',@@ -55,6 +56,7 @@ const events = {'device-list-changed': 'deviceListChanged','display-name-change': 'displayNameChange','email-change': 'emailChange',+ 'endpoint-text-message-received': 'endpointTextMessageReceived','feedback-submitted': 'feedbackSubmitted','feedback-prompt-displayed': 'feedbackPromptDisplayed','filmstrip-display-changed': 'filmstripDisplayChanged',