jiti-meet/modules/UI/toolbars/Toolbar.js

544 lines
17 KiB
JavaScript
Raw Normal View History

/* global APP, $, config, interfaceConfig, JitsiMeetJS */
/* jshint -W101 */
2015-12-10 16:36:03 +00:00
import UIUtil from '../util/UIUtil';
import UIEvents from '../../../service/UI/UIEvents';
2015-01-07 14:54:03 +00:00
2015-12-10 16:36:03 +00:00
let roomUrl = null;
let emitter = null;
2015-01-07 14:54:03 +00:00
2015-12-10 13:30:25 +00:00
/**
* Opens the invite link dialog.
*/
function openLinkDialog () {
2015-12-10 16:36:03 +00:00
let inviteAttributes;
2015-12-10 13:30:25 +00:00
if (roomUrl === null) {
inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
APP.translation.translateString("roomUrlDefaultMsg") + '"';
} else {
inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
}
APP.UI.messageHandler.openTwoButtonDialog(
2015-12-10 13:30:25 +00:00
"dialog.shareLink", null, null,
`<input id="inviteLinkRef" type="text" ${inviteAttributes} onclick="this.select();" readonly>`,
false, "dialog.Invite",
function (e, v) {
if (v && roomUrl) {
JitsiMeetJS.analytics.sendEvent('toolbar.invite.button');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.USER_INVITED, roomUrl);
}
2016-08-01 20:03:38 +00:00
else {
JitsiMeetJS.analytics.sendEvent('toolbar.invite.cancel');
2016-08-01 20:03:38 +00:00
}
2015-12-10 13:30:25 +00:00
},
function (event) {
if (roomUrl) {
document.getElementById('inviteLinkRef').select();
} else {
if (event && event.target) {
$(event.target).find('button[value=true]').prop('disabled', true);
}
}
2016-08-01 20:03:38 +00:00
},
function (e, v, m, f) {
if(!v && !m && !f)
JitsiMeetJS.analytics.sendEvent('toolbar.invite.close');
2015-12-10 13:30:25 +00:00
}
);
}
const buttonHandlers = {
2015-01-07 14:54:03 +00:00
"toolbar_button_mute": function () {
let sharedVideoManager = APP.UI.getSharedVideoManager();
if (APP.conference.audioMuted) {
// If there's a shared video with the volume "on" and we aren't
// the video owner, we warn the user
// that currently it's not possible to unmute.
if (sharedVideoManager
&& sharedVideoManager.isSharedVideoVolumeOn()
&& !sharedVideoManager.isSharedVideoOwner()) {
UIUtil.animateShowElement(
$("#unableToUnmutePopup"), true, 5000);
}
else {
JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
emitter.emit(UIEvents.AUDIO_MUTED, false, true);
}
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
emitter.emit(UIEvents.AUDIO_MUTED, true, true);
2015-09-02 17:08:48 +00:00
}
2015-01-07 14:54:03 +00:00
},
"toolbar_button_camera": function () {
if (APP.conference.videoMuted) {
JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
2015-12-03 13:11:01 +00:00
emitter.emit(UIEvents.VIDEO_MUTED, false);
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
2015-12-03 13:11:01 +00:00
emitter.emit(UIEvents.VIDEO_MUTED, true);
2015-09-02 17:08:48 +00:00
}
2015-01-07 14:54:03 +00:00
},
"toolbar_button_security": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.lock.clicked');
2015-12-09 17:10:49 +00:00
emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_link": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
2015-12-10 13:30:25 +00:00
openLinkDialog();
2015-01-07 14:54:03 +00:00
},
"toolbar_button_chat": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.TOGGLE_CHAT);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_etherpad": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
emitter.emit(UIEvents.ETHERPAD_CLICKED);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_sharedvideo": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
},
2015-01-07 14:54:03 +00:00
"toolbar_button_desktopsharing": function () {
if (APP.conference.isSharingScreen) {
JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
2015-09-02 17:08:48 +00:00
}
2015-12-30 13:28:56 +00:00
emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_fullScreen": function() {
JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
2016-08-29 03:59:09 +00:00
UIUtil.buttonClick("#toolbar_button_fullScreen",
"icon-full-screen icon-exit-full-screen");
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_sip": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
2015-12-10 15:48:56 +00:00
showSipNumberInput();
2015-01-07 14:54:03 +00:00
},
"toolbar_button_dialpad": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
2015-12-10 13:30:25 +00:00
dialpadButtonClicked();
},
2015-01-07 14:54:03 +00:00
"toolbar_button_settings": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.TOGGLE_SETTINGS);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_hangup": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
2015-12-10 15:48:56 +00:00
emitter.emit(UIEvents.HANGUP);
},
"toolbar_button_login": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.AUTH_CLICKED);
},
"toolbar_button_logout": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
// Ask for confirmation
APP.UI.messageHandler.openTwoButtonDialog(
"dialog.logoutTitle",
null,
2015-02-23 14:59:36 +00:00
"dialog.logoutQuestion",
null,
false,
"dialog.Yes",
function (evt, yes) {
if (yes) {
2015-12-10 15:48:56 +00:00
emitter.emit(UIEvents.LOGOUT);
}
2015-12-10 15:48:56 +00:00
}
);
2015-01-07 14:54:03 +00:00
}
};
2015-12-10 16:36:03 +00:00
const defaultToolbarButtons = {
2016-08-29 03:59:09 +00:00
'microphone': {
id: '#toolbar_button_mute',
shortcut: 'M',
shortcutAttr: 'mutePopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
APP.conference.toggleAudioMuted();
},
shortcutDescription: "keyboardShortcuts.mute"
},
'camera': {
id: '#toolbar_button_camera',
shortcut: 'V',
shortcutAttr: 'toggleVideoPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
APP.conference.toggleVideoMuted();
},
shortcutDescription: "keyboardShortcuts.videoMute"
},
'desktop': {
id: '#toolbar_button_desktopsharing',
shortcut: 'D',
shortcutAttr: 'toggleDesktopSharingPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
APP.conference.toggleScreenSharing();
},
shortcutDescription: "keyboardShortcuts.toggleScreensharing"
},
'security': {
id: '#toolbar_button_security'
},
'invite': {
id: '#toolbar_button_link'
},
'chat': {
id: '#toolbar_button_chat',
shortcut: 'C',
shortcutAttr: 'toggleChatPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
APP.UI.toggleChat();
},
shortcutDescription: "keyboardShortcuts.toggleChat"
},
'etherpad': {
id: '#toolbar_button_etherpad'
},
'fullscreen': {
id: '#toolbar_button_fullScreen'
},
'settings': {
id: '#toolbar_button_settings'
},
'hangup': {
id: '#toolbar_button_hangup'
}
};
2015-01-07 14:54:03 +00:00
function dialpadButtonClicked() {
//TODO show the dialpad box
}
2015-12-10 15:48:56 +00:00
function showSipNumberInput () {
2015-12-10 13:30:25 +00:00
let defaultNumber = config.defaultSipNumber
? config.defaultSipNumber
: '';
let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
APP.UI.messageHandler.openTwoButtonDialog(
2015-12-10 13:30:25 +00:00
null, null, null,
`<h2>${sipMsg}</h2>
2015-12-25 16:55:45 +00:00
<input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
2015-12-10 13:30:25 +00:00
false, "dialog.Dial",
function (e, v, m, f) {
2015-12-10 15:48:56 +00:00
if (v && f.sipNumber) {
emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
}
},
null, null, ':input:first'
);
}
2015-12-10 13:30:25 +00:00
const Toolbar = {
2015-12-09 17:10:49 +00:00
init (eventEmitter) {
2015-12-03 13:11:01 +00:00
emitter = eventEmitter;
// The toolbar is enabled by default.
this.enabled = true;
this.toolbarSelector = $("#header");
2015-12-10 16:36:03 +00:00
UIUtil.hideDisabledButtons(defaultToolbarButtons);
2016-08-29 03:59:09 +00:00
Object.keys(defaultToolbarButtons).forEach(
id => {
if (UIUtil.isButtonEnabled(id)) {
var button = defaultToolbarButtons[id];
if (button.shortcut)
APP.keyboardshortcut.registerShortcut(
2016-08-29 03:59:09 +00:00
button.shortcut,
button.shortcutAttr,
button.shortcutFunc,
button.shortcutDescription
);
}
}
);
2015-12-10 16:36:03 +00:00
Object.keys(buttonHandlers).forEach(
buttonId => $(`#${buttonId}`).click(function(event) {
!$(this).prop('disabled') && buttonHandlers[buttonId](event);
})
2015-12-10 16:36:03 +00:00
);
2015-12-09 17:10:49 +00:00
},
/**
* Enables / disables the toolbar.
* @param {e} set to {true} to enable the toolbar or {false}
* to disable it
*/
enable (e) {
this.enabled = e;
if (!e && this.isVisible())
this.hide(false);
},
/**
* Indicates if the bottom toolbar is currently enabled.
* @return {this.enabled}
*/
isEnabled() {
return this.enabled;
},
2015-01-07 14:54:03 +00:00
/**
* Updates the room invite url.
*/
2015-12-09 17:10:49 +00:00
updateRoomUrl (newRoomUrl) {
2015-01-07 14:54:03 +00:00
roomUrl = newRoomUrl;
// If the invite dialog has been already opened we update the
// information.
2015-12-10 16:36:03 +00:00
let inviteLink = document.getElementById('inviteLinkRef');
2015-01-07 14:54:03 +00:00
if (inviteLink) {
inviteLink.value = roomUrl;
inviteLink.select();
$('#inviteLinkRef').parent()
.find('button[value=true]').prop('disabled', false);
2015-01-07 14:54:03 +00:00
}
2015-12-09 17:10:49 +00:00
},
2015-01-07 14:54:03 +00:00
/**
* Unlocks the lock button state.
*/
2015-12-09 17:10:49 +00:00
unlockLockButton () {
if ($("#toolbar_button_security").hasClass("icon-security-locked"))
2016-03-29 17:13:54 +00:00
UIUtil.buttonClick("#toolbar_button_security",
"icon-security icon-security-locked");
2015-12-09 17:10:49 +00:00
},
/**
* Updates the lock button state to locked.
*/
2015-12-09 17:10:49 +00:00
lockLockButton () {
if ($("#toolbar_button_security").hasClass("icon-security"))
2016-03-29 17:13:54 +00:00
UIUtil.buttonClick("#toolbar_button_security",
"icon-security icon-security-locked");
2015-12-09 17:10:49 +00:00
},
/**
* Shows or hides authentication button
* @param show <tt>true</tt> to show or <tt>false</tt> to hide
*/
2015-12-09 17:10:49 +00:00
showAuthenticateButton (show) {
if (UIUtil.isButtonEnabled('authentication') && show) {
$('#authentication').css({display: "inline"});
} else {
$('#authentication').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
2015-12-25 16:55:45 +00:00
showEtherpadButton () {
if (!$('#toolbar_button_etherpad').is(":visible")) {
$('#toolbar_button_etherpad').css({display: 'inline-block'});
}
},
// Shows or hides the 'shared video' button.
showSharedVideoButton () {
if (UIUtil.isButtonEnabled('sharedvideo')
&& config.disableThirdPartyRequests !== true) {
$('#toolbar_button_sharedvideo').css({display: "inline-block"});
} else {
$('#toolbar_button_sharedvideo').css({display: "none"});
}
},
// checks whether desktop sharing is enabled and whether
// we have params to start automatically sharing
2015-12-09 17:10:49 +00:00
checkAutoEnableDesktopSharing () {
if (UIUtil.isButtonEnabled('desktop')
&& config.autoEnableDesktopSharing) {
2015-12-30 13:28:56 +00:00
emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
}
2015-12-09 17:10:49 +00:00
},
2014-08-08 13:25:24 +00:00
// Shows or hides SIP calls button
2015-12-09 17:10:49 +00:00
showSipCallButton (show) {
if (APP.conference.sipGatewayEnabled()
&& UIUtil.isButtonEnabled('sip') && show) {
$('#toolbar_button_sip').css({display: "inline-block"});
} else {
$('#toolbar_button_sip').css({display: "none"});
2014-08-08 13:25:24 +00:00
}
2015-12-09 17:10:49 +00:00
},
2014-08-08 13:25:24 +00:00
// Shows or hides the dialpad button
2015-12-09 17:10:49 +00:00
showDialPadButton (show) {
if (UIUtil.isButtonEnabled('dialpad') && show) {
$('#toolbar_button_dialpad').css({display: "inline-block"});
} else {
$('#toolbar_button_dialpad').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Displays user authenticated identity name(login).
* @param authIdentity identity name to be displayed.
*/
2015-12-09 17:10:49 +00:00
setAuthenticatedIdentity (authIdentity) {
if (authIdentity) {
2015-12-10 16:36:03 +00:00
let selector = $('#toolbar_auth_identity');
2015-04-08 10:49:49 +00:00
selector.css({display: "list-item"});
selector.text(authIdentity);
} else {
$('#toolbar_auth_identity').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Shows/hides login button.
* @param show <tt>true</tt> to show
*/
2015-12-09 17:10:49 +00:00
showLoginButton (show) {
if (UIUtil.isButtonEnabled('authentication') && show) {
$('#toolbar_button_login').css({display: "list-item"});
} else {
$('#toolbar_button_login').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Shows/hides logout button.
* @param show <tt>true</tt> to show
*/
2015-12-09 17:10:49 +00:00
showLogoutButton (show) {
if (UIUtil.isButtonEnabled('authentication') && show) {
$('#toolbar_button_logout').css({display: "list-item"});
} else {
$('#toolbar_button_logout').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Update the state of the button. The button has blue glow if desktop
* streaming is active.
*/
updateDesktopSharingButtonState () {
2015-12-10 16:36:03 +00:00
let button = $("#toolbar_button_desktopsharing");
if (APP.conference.isSharingScreen) {
button.addClass("glow");
} else {
button.removeClass("glow");
}
2015-12-10 15:48:56 +00:00
},
/**
* Marks video icon as muted or not.
* @param {boolean} muted if icon should look like muted or not
*/
markVideoIconAsMuted (muted) {
$('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
},
/**
* Marks video icon as disabled or not.
* @param {boolean} disabled if icon should look like disabled or not
*/
markVideoIconAsDisabled (disabled) {
var $btn = $('#toolbar_button_camera');
$btn
.prop("disabled", disabled)
.attr("data-i18n", disabled
? "[content]toolbar.cameraDisabled"
: "[content]toolbar.videomute")
.attr("shortcut", disabled ? "" : "toggleVideoPopover");
disabled
? $btn.attr("disabled", "disabled")
: $btn.removeAttr("disabled");
APP.translation.translateElement($btn);
disabled && this.markVideoIconAsMuted(disabled);
},
/**
* Marks audio icon as muted or not.
* @param {boolean} muted if icon should look like muted or not
*/
markAudioIconAsMuted (muted) {
$('#toolbar_button_mute').toggleClass("icon-microphone",
!muted).toggleClass("icon-mic-disabled", muted);
},
/**
* Marks audio icon as disabled or not.
* @param {boolean} disabled if icon should look like disabled or not
*/
markAudioIconAsDisabled (disabled) {
var $btn = $('#toolbar_button_mute');
$btn
.prop("disabled", disabled)
.attr("data-i18n", disabled
? "[content]toolbar.micDisabled"
: "[content]toolbar.mute")
.attr("shortcut", disabled ? "" : "mutePopover");
disabled
? $btn.attr("disabled", "disabled")
: $btn.removeAttr("disabled");
APP.translation.translateElement($btn);
disabled && this.markAudioIconAsMuted(disabled);
},
/**
* Indicates if the toolbar is currently hovered.
* @return {boolean} true if the toolbar is currently hovered,
* false otherwise
*/
isHovered() {
var hovered = false;
this.toolbarSelector.find('*').each(function () {
let id = $(this).attr('id');
if ($(`#${id}:hover`).length > 0) {
hovered = true;
// break each
return false;
}
});
if (hovered)
return true;
if ($("#bottomToolbar:hover").length > 0) {
return true;
}
return false;
},
/**
* Returns true if this toolbar is currently visible, or false otherwise.
* @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
*/
isVisible() {
return this.toolbarSelector.is(":visible");
},
/**
* Hides the toolbar with animation or not depending on the animate
* parameter.
*/
hide() {
this.toolbarSelector.hide(
"slide", { direction: "up", duration: 300});
},
/**
* Shows the toolbar with animation or not depending on the animate
* parameter.
*/
show() {
this.toolbarSelector.show(
"slide", { direction: "up", duration: 300});
2015-12-09 17:10:49 +00:00
}
};
2015-01-07 14:54:03 +00:00
2015-12-09 17:10:49 +00:00
export default Toolbar;