ref(remotecontrol): To use transport module instead of API

This commit is contained in:
hristoterezov 2017-04-17 14:59:24 -05:00
parent 0dff35c0db
commit 54388b6a0a
4 changed files with 76 additions and 72 deletions

View File

@ -603,8 +603,8 @@ export default {
APP.store.dispatch(showDesktopSharingButton());
APP.remoteControl.init();
this._createRoom(tracks);
APP.remoteControl.init();
if (UIUtil.isButtonEnabled('contacts')
&& !interfaceConfig.filmStripOnly) {

View File

@ -35,9 +35,7 @@ function initCommands() {
'toggle-share-screen': toggleScreenSharing,
'video-hangup': () => APP.conference.hangup(),
'email': APP.conference.changeLocalEmail,
'avatar-url': APP.conference.changeLocalAvatarUrl,
'remote-control-event':
event => APP.remoteControl.onRemoteControlAPIEvent(event)
'avatar-url': APP.conference.changeLocalAvatarUrl
};
transport.on('event', event => {
const { name, data } = event;
@ -237,16 +235,6 @@ class API {
this._sendEvent('video-ready-to-close', {});
}
/**
* Sends remote control event.
*
* @param {RemoteControlEvent} event - The remote control event.
* @returns {void}
*/
sendRemoteControlEvent(event) {
this._sendEvent('remote-control-event', event);
}
/**
* Disposes the allocated resources.
*

View File

@ -1,10 +1,16 @@
/* global APP, JitsiMeetJS, interfaceConfig */
const logger = require("jitsi-meet-logger").getLogger(__filename);
import {DISCO_REMOTE_CONTROL_FEATURE, REMOTE_CONTROL_EVENT_TYPE, EVENT_TYPES,
PERMISSIONS_ACTIONS} from "../../service/remotecontrol/Constants";
import RemoteControlParticipant from "./RemoteControlParticipant";
/* global APP, JitsiMeetJS, interfaceConfig, config */
import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
import {
DISCO_REMOTE_CONTROL_FEATURE,
EVENT_TYPES,
PERMISSIONS_ACTIONS,
REMOTE_CONTROL_EVENT_TYPE
} from "../../service/remotecontrol/Constants";
import { transport } from '../transport';
import RemoteControlParticipant from "./RemoteControlParticipant";
const logger = require("jitsi-meet-logger").getLogger(__filename);
const ConferenceEvents = JitsiMeetJS.events.conference;
/**
@ -25,13 +31,24 @@ export default class Receiver extends RemoteControlParticipant {
= this._onRemoteControlEvent.bind(this);
this._userLeftListener = this._onUserLeft.bind(this);
this._hangupListener = this._onHangup.bind(this);
// We expect here that even if we receive the supported event earlier
// it will be cached and we'll receive it.
transport.on('event', data => {
if(data.name === REMOTE_CONTROL_EVENT_TYPE) {
this._onRemoteControlAPIEvent(data.event);
return true;
}
return false;
});
}
/**
* Enables / Disables the remote control
* @param {boolean} enabled the new state.
*/
enable(enabled) {
_enable(enabled) {
if(this.enabled === enabled) {
return;
}
@ -73,8 +90,11 @@ export default class Receiver extends RemoteControlParticipant {
this.controller = null;
APP.conference.removeConferenceListener(ConferenceEvents.USER_LEFT,
this._userLeftListener);
APP.API.sendRemoteControlEvent({
type: EVENT_TYPES.stop
transport.sendEvent({
name: REMOTE_CONTROL_EVENT_TYPE,
event: {
type: EVENT_TYPES.stop
}
});
if(!dontShowDialog) {
APP.UI.messageHandler.openMessageDialog(
@ -113,6 +133,7 @@ export default class Receiver extends RemoteControlParticipant {
if(this.controller === null
&& remoteControlEvent.type === EVENT_TYPES.permissions
&& remoteControlEvent.action === PERMISSIONS_ACTIONS.request) {
// FIXME: Maybe use transport.sendRequest in this case???
remoteControlEvent.userId = participant.getId();
remoteControlEvent.userJID = participant.getJid();
remoteControlEvent.displayName = participant.getDisplayName()
@ -125,7 +146,10 @@ export default class Receiver extends RemoteControlParticipant {
this._stop();
return;
}
APP.API.sendRemoteControlEvent(remoteControlEvent);
transport.sendEvent({
name: REMOTE_CONTROL_EVENT_TYPE,
event: remoteControlEvent
});
} else if(event.type === REMOTE_CONTROL_EVENT_TYPE) {
logger.log("Remote control event is ignored because remote "
+ "control is disabled", event);
@ -133,7 +157,7 @@ export default class Receiver extends RemoteControlParticipant {
}
/**
* Handles remote control permission events received from the API module.
* Handles remote control permission events.
* @param {String} userId the user id of the participant related to the
* event.
* @param {PERMISSIONS_ACTIONS} action the action related to the event.
@ -173,6 +197,36 @@ export default class Receiver extends RemoteControlParticipant {
});
}
/**
* Handles remote control events from the external app. Currently only
* events with type = EVENT_TYPES.supported or EVENT_TYPES.permissions
* @param {RemoteControlEvent} event the remote control event.
*/
_onRemoteControlAPIEvent(event) {
switch(event.type) {
case EVENT_TYPES.supported:
this._onRemoteControlSupported();
break;
case EVENT_TYPES.permissions:
this._onRemoteControlPermissionsEvent(
event.userId, event.action);
break;
}
}
/**
* Handles events for support for executing remote control events into
* the wrapper application.
*/
_onRemoteControlSupported() {
logger.log("Remote Control supported.");
if(!config.disableRemoteControl) {
this._enable(true);
} else {
logger.log("Remote Control disabled.");
}
}
/**
* Calls the stop method if the other side have left.
* @param {string} id - the user id for the participant that have left
@ -187,6 +241,6 @@ export default class Receiver extends RemoteControlParticipant {
* Handles hangup events. Disables the receiver.
*/
_onHangup() {
this.enable(false);
this._enable(false);
}
}

View File

@ -1,9 +1,11 @@
/* global APP, config */
const logger = require("jitsi-meet-logger").getLogger(__filename);
import Controller from "./Controller";
import Receiver from "./Receiver";
import {EVENT_TYPES, DISCO_REMOTE_CONTROL_FEATURE}
from "../../service/remotecontrol/Constants";
import { DISCO_REMOTE_CONTROL_FEATURE }
from '../../service/remotecontrol/Constants';
import Controller from './Controller';
import Receiver from './Receiver';
const logger = require('jitsi-meet-logger').getLogger(__filename);
/**
* Implements the remote control functionality.
@ -15,14 +17,12 @@ class RemoteControl {
*/
constructor() {
this.controller = new Controller();
this.receiver = new Receiver();
this.enabled = false;
this.initialized = false;
}
/**
* Initializes the remote control - checks if the remote control should be
* enabled or not, initializes the API module.
* enabled or not.
*/
init() {
if(config.disableRemoteControl || this.initialized
@ -31,46 +31,8 @@ class RemoteControl {
}
logger.log("Initializing remote control.");
this.initialized = true;
APP.API.init({
forceEnable: true,
});
this.controller.enable(true);
if(this.enabled) { // supported message came before init.
this._onRemoteControlSupported();
}
}
/**
* Handles remote control events from the API module. Currently only events
* with type = EVENT_TYPES.supported or EVENT_TYPES.permissions
* @param {RemoteControlEvent} event the remote control event.
*/
onRemoteControlAPIEvent(event) {
switch(event.type) {
case EVENT_TYPES.supported:
this._onRemoteControlSupported();
break;
case EVENT_TYPES.permissions:
this.receiver._onRemoteControlPermissionsEvent(
event.userId, event.action);
break;
}
}
/**
* Handles API event for support for executing remote control events into
* the wrapper application.
*/
_onRemoteControlSupported() {
logger.log("Remote Control supported.");
if(!config.disableRemoteControl) {
this.enabled = true;
if(this.initialized) {
this.receiver.enable(true);
}
} else {
logger.log("Remote Control disabled.");
}
this.receiver = new Receiver();
}
/**