jiti-meet/modules/UI/side_pannels/settings/SettingsMenu.js

207 lines
6.0 KiB
JavaScript
Raw Normal View History

/* global APP, $ */
import UIUtil from "../../util/UIUtil";
import UIEvents from "../../../../service/UI/UIEvents";
import languages from "../../../../service/translation/languages";
2015-12-31 15:23:23 +00:00
import Settings from '../../../settings/Settings';
2016-03-02 15:39:39 +00:00
/**
* Generate html select options for available languages.
* @param {string[]} items available languages
* @param {string} [currentLang] current language
* @returns {string}
*/
function generateLanguagesOptions(items, currentLang) {
return items.map(function (lang) {
let attrs = {
value: lang,
'data-i18n': `languages:${lang}`
};
2016-03-02 15:39:39 +00:00
if (lang === currentLang) {
attrs.selected = 'selected';
}
2016-03-02 15:39:39 +00:00
let attrsStr = UIUtil.attrsToString(attrs);
return `<option ${attrsStr}></option>`;
}).join('\n');
}
2015-01-07 14:54:03 +00:00
2016-03-02 15:39:39 +00:00
/**
* Generate html select options for available physical devices.
* @param {{ deviceId, label }[]} items available devices
* @param {string} [selectedId] id of selected device
* @returns {string}
*/
function generateDevicesOptions(items, selectedId) {
return items.map(function (item) {
let attrs = {
value: item.deviceId
};
if (item.deviceId === selectedId) {
attrs.selected = 'selected';
}
let attrsStr = UIUtil.attrsToString(attrs);
return `<option ${attrsStr}>${item.label}</option>`;
}).join('\n');
}
2015-01-07 14:54:03 +00:00
2015-12-31 15:23:23 +00:00
export default {
init (emitter) {
2015-01-07 14:54:03 +00:00
2016-03-02 15:39:39 +00:00
// DISPLAY NAME
function updateDisplayName () {
emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
}
$('#setDisplayName')
.val(Settings.getDisplayName())
.keyup(function (event) {
if (event.keyCode === 13) { // enter
updateDisplayName();
}
})
.focusout(updateDisplayName);
// EMAIL
function updateEmail () {
emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
}
$('#setEmail')
.val(Settings.getEmail())
.keyup(function (event) {
if (event.keyCode === 13) { // enter
updateEmail();
2015-12-31 15:23:23 +00:00
}
2016-03-02 15:39:39 +00:00
}).focusout(updateEmail);
2015-12-31 15:23:23 +00:00
2016-03-02 15:39:39 +00:00
// START MUTED
$("#startMutedOptions").change(function () {
2015-12-31 15:23:23 +00:00
let startAudioMuted = $("#startAudioMuted").is(":checked");
let startVideoMuted = $("#startVideoMuted").is(":checked");
2016-03-02 15:39:39 +00:00
emitter.emit(
UIEvents.START_MUTED_CHANGED,
startAudioMuted,
startVideoMuted
);
});
// FOLLOW ME
$("#followMeOptions").change(function () {
let isFollowMeEnabled = $("#followMeCheckBox").is(":checked");
emitter.emit(
UIEvents.FOLLOW_ME_ENABLED,
isFollowMeEnabled
);
});
2016-03-02 15:39:39 +00:00
// LANGUAGES BOX
let languagesBox = $("#languages_selectbox");
languagesBox.html(generateLanguagesOptions(
languages.getLanguages(),
APP.translation.getCurrentLanguage()
));
APP.translation.translateElement(languagesBox);
languagesBox.change(function () {
emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
});
// DEVICES LIST
this.changeDevicesList([]);
$('#selectCamera').change(function () {
let cameraDeviceId = $(this).val();
if (cameraDeviceId !== Settings.getCameraDeviceId()) {
emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
}
2016-03-02 15:39:39 +00:00
});
$('#selectMic').change(function () {
let micDeviceId = $(this).val();
if (micDeviceId !== Settings.getMicDeviceId()) {
emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
}
});
},
2016-03-02 15:39:39 +00:00
/**
* If start audio muted/start video muted options should be visible or not.
* @param {boolean} show
*/
showStartMutedOptions (show) {
if (show) {
2015-05-19 15:03:01 +00:00
$("#startMutedOptions").css("display", "block");
2016-03-02 15:39:39 +00:00
} else {
2015-05-19 15:03:01 +00:00
$("#startMutedOptions").css("display", "none");
}
},
2016-03-02 15:39:39 +00:00
updateStartMutedBox (startAudioMuted, startVideoMuted) {
$("#startAudioMuted").attr("checked", startAudioMuted);
$("#startVideoMuted").attr("checked", startVideoMuted);
2015-01-07 14:54:03 +00:00
},
/**
* Shows/hides the follow me options in the settings dialog.
*
* @param {boolean} show {true} to show those options, {false} to hide them
*/
showFollowMeOptions (show) {
if (show) {
$("#followMeOptions").css("display", "block");
} else {
$("#followMeOptions").css("display", "none");
}
},
2016-03-02 15:39:39 +00:00
/**
* Check if settings menu is visible or not.
* @returns {boolean}
*/
2015-12-31 15:23:23 +00:00
isVisible () {
2015-01-07 14:54:03 +00:00
return $('#settingsmenu').is(':visible');
},
2016-03-02 15:39:39 +00:00
/**
* Change user display name in the settings menu.
* @param {string} newDisplayName
*/
changeDisplayName (newDisplayName) {
$('#setDisplayName').val(newDisplayName);
},
2015-12-31 15:23:23 +00:00
2016-03-02 15:39:39 +00:00
/**
* Change user avatar in the settings menu.
* @param {string} avatarUrl url of the new avatar
*/
changeAvatar (avatarUrl) {
$('#avatar').attr('src', avatarUrl);
},
2016-03-02 15:39:39 +00:00
/**
* Change available cameras/microphones or hide selects completely if
* no devices available.
* @param {{ deviceId, label, kind }[]} devices list of available devices
*/
changeDevicesList (devices) {
if (!devices.length) {
$('#devicesOptions').hide();
return;
}
let audio = devices.filter(device => device.kind === 'audioinput');
let video = devices.filter(device => device.kind === 'videoinput');
$('#selectCamera').html(
generateDevicesOptions(video, Settings.getCameraDeviceId())
);
$('#selectMic').html(
generateDevicesOptions(audio, Settings.getMicDeviceId())
);
$('#devicesOptions').show();
2015-01-07 14:54:03 +00:00
}
};