external_api: add ability to send a text message through datachannels

This commit is contained in:
horymury 2020-03-20 13:51:26 +02:00 committed by GitHub
parent 14855f3255
commit 4616065b1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 4 deletions

View File

@ -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,

View File

@ -270,6 +270,11 @@ api.executeCommand('email', 'example@example.com');
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:
```javascript
api.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
{

View File

@ -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.

View File

@ -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';

View File

@ -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',