ref(iframe_API): Changing the format of the outgoing messages for API.js

This commit is contained in:
hristoterezov 2017-05-01 15:59:18 -05:00
parent 96bde3ff44
commit dfc94ff144
3 changed files with 30 additions and 18 deletions

View File

@ -127,18 +127,14 @@ class API {
} }
/** /**
* Sends message to the external application. * Sends event to the external application.
* *
* @param {string} name - The name of the event. * @param {Object} event - The event to be sent.
* @param {Object} data - The data to be sent.
* @returns {void} * @returns {void}
*/ */
_sendEvent(name, data = {}) { _sendEvent(event = {}) {
if (this._enabled) { if (this._enabled) {
transport.sendEvent({ transport.sendEvent(event);
data,
name
});
} }
} }
@ -149,7 +145,10 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifySendingChatMessage(message) { notifySendingChatMessage(message) {
this._sendEvent('outgoing-message', { message }); this._sendEvent({
name: 'outgoing-message',
message
});
} }
/** /**
@ -164,7 +163,8 @@ class API {
return; return;
} }
this._sendEvent('incoming-message', { this._sendEvent({
name: 'incoming-message',
from: id, from: id,
message: body, message: body,
nick, nick,
@ -180,7 +180,10 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyUserJoined(id) { notifyUserJoined(id) {
this._sendEvent('participant-joined', { id }); this._sendEvent({
name: 'participant-joined',
id
});
} }
/** /**
@ -191,7 +194,10 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyUserLeft(id) { notifyUserLeft(id) {
this._sendEvent('participant-left', { id }); this._sendEvent({
name: 'participant-left',
id
});
} }
/** /**
@ -203,7 +209,7 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyDisplayNameChanged(id, displayname) { notifyDisplayNameChanged(id, displayname) {
this._sendEvent('display-name-change', { this._sendEvent({ name: 'display-name-change',
displayname, displayname,
id id
}); });
@ -217,7 +223,10 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyConferenceJoined(roomName) { notifyConferenceJoined(roomName) {
this._sendEvent('video-conference-joined', { roomName }); this._sendEvent({
name: 'video-conference-joined',
roomName
});
} }
/** /**
@ -228,7 +237,10 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyConferenceLeft(roomName) { notifyConferenceLeft(roomName) {
this._sendEvent('video-conference-left', { roomName }); this._sendEvent({
name: 'video-conference-left',
roomName
});
} }
/** /**
@ -238,7 +250,7 @@ class API {
* @returns {void} * @returns {void}
*/ */
notifyReadyToClose() { notifyReadyToClose() {
this._sendEvent('video-ready-to-close', {}); this._sendEvent({ name: 'video-ready-to-close' });
} }
/** /**

View File

@ -234,7 +234,7 @@ class JitsiMeetExternalAPI extends EventEmitter {
*/ */
_setupListeners() { _setupListeners() {
this._transport.on('event', ({ data, name }) => { this._transport.on('event', ({ name, ...data }) => {
if (name === 'participant-joined') { if (name === 'participant-joined') {
changeParticipantNumber(this, 1); changeParticipantNumber(this, 1);
} else if (name === 'participant-left') { } else if (name === 'participant-left') {

View File

@ -123,7 +123,7 @@ export default class PostMessageTransportBackend {
* @param {Object} legacyMessage - The message to be sent. * @param {Object} legacyMessage - The message to be sent.
* @returns {void} * @returns {void}
*/ */
_sendLegacyMessage({ data, name }) { _sendLegacyMessage({ name, ...data }) {
if (name && LEGACY_OUTGOING_METHODS.indexOf(name) !== -1) { if (name && LEGACY_OUTGOING_METHODS.indexOf(name) !== -1) {
this.postis.send({ this.postis.send({
method: name, method: name,