2016-05-06 14:31:23 +00:00
|
|
|
/* global APP, $, JitsiMeetJS */
|
2015-12-11 14:48:16 +00:00
|
|
|
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';
|
2015-02-06 15:46:50 +00:00
|
|
|
|
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}`
|
|
|
|
};
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2016-03-02 15:39:39 +00:00
|
|
|
if (lang === currentLang) {
|
|
|
|
attrs.selected = 'selected';
|
|
|
|
}
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2016-03-02 15:39:39 +00:00
|
|
|
let attrsStr = UIUtil.attrsToString(attrs);
|
|
|
|
return `<option ${attrsStr}></option>`;
|
|
|
|
}).join('\n');
|
2015-02-06 15:46:50 +00:00
|
|
|
}
|
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
|
2016-05-17 15:58:25 +00:00
|
|
|
* @param {boolean} permissionGranted if permission to use selected device type
|
|
|
|
* is granted
|
2016-03-02 15:39:39 +00:00
|
|
|
* @returns {string}
|
|
|
|
*/
|
2016-05-17 15:58:25 +00:00
|
|
|
function generateDevicesOptions(items, selectedId, permissionGranted) {
|
|
|
|
if (!permissionGranted && items.length) {
|
|
|
|
return '<option data-i18n="settings.noPermission"></option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = items.map(function (item) {
|
2016-02-09 10:19:43 +00:00
|
|
|
let attrs = {
|
|
|
|
value: item.deviceId
|
|
|
|
};
|
|
|
|
|
|
|
|
if (item.deviceId === selectedId) {
|
|
|
|
attrs.selected = 'selected';
|
|
|
|
}
|
|
|
|
|
|
|
|
let attrsStr = UIUtil.attrsToString(attrs);
|
|
|
|
return `<option ${attrsStr}>${item.label}</option>`;
|
2016-05-17 15:58:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!items.length) {
|
|
|
|
options.unshift('<option data-i18n="settings.noDevice"></option>');
|
|
|
|
}
|
|
|
|
|
|
|
|
return options.join('');
|
2016-02-09 10:19:43 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-12-31 15:23:23 +00:00
|
|
|
export default {
|
|
|
|
init (emitter) {
|
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
|
|
|
|
);
|
|
|
|
});
|
2016-02-09 10:19:43 +00:00
|
|
|
|
2016-03-24 01:43:29 +00:00
|
|
|
// 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
|
2016-08-04 14:25:16 +00:00
|
|
|
JitsiMeetJS.mediaDevices.isDeviceListAvailable()
|
|
|
|
.then((isDeviceListAvailable) => {
|
|
|
|
if (isDeviceListAvailable &&
|
|
|
|
JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
|
|
|
|
this._initializeDeviceSelectionSettings(emitter);
|
2016-05-17 15:58:25 +00:00
|
|
|
}
|
|
|
|
});
|
2016-08-04 14:25:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_initializeDeviceSelectionSettings(emitter) {
|
|
|
|
this.changeDevicesList([]);
|
|
|
|
|
|
|
|
$('#selectCamera').change(function () {
|
|
|
|
let cameraDeviceId = $(this).val();
|
|
|
|
if (cameraDeviceId !== Settings.getCameraDeviceId()) {
|
|
|
|
emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#selectMic').change(function () {
|
|
|
|
let micDeviceId = $(this).val();
|
|
|
|
if (micDeviceId !== Settings.getMicDeviceId()) {
|
|
|
|
emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#selectAudioOutput').change(function () {
|
|
|
|
let audioOutputDeviceId = $(this).val();
|
|
|
|
if (audioOutputDeviceId !== Settings.getAudioOutputDeviceId()) {
|
|
|
|
emitter.emit(
|
|
|
|
UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED, audioOutputDeviceId);
|
|
|
|
}
|
|
|
|
});
|
2015-02-06 15:46:50 +00:00
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2016-03-24 01:43:29 +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 () {
|
2016-09-08 22:34:16 +00:00
|
|
|
return UIUtil.isVisible(document.getElementById("settings_container"));
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
|
|
|
|
2016-05-26 08:53:02 +00:00
|
|
|
/**
|
|
|
|
* Sets microphone's <select> element to select microphone ID from settings.
|
|
|
|
*/
|
|
|
|
setSelectedMicFromSettings () {
|
|
|
|
$('#selectMic').val(Settings.getMicDeviceId());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets camera's <select> element to select camera ID from settings.
|
|
|
|
*/
|
|
|
|
setSelectedCameraFromSettings () {
|
|
|
|
$('#selectCamera').val(Settings.getCameraDeviceId());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets audio outputs's <select> element to select audio output ID from
|
|
|
|
* settings.
|
|
|
|
*/
|
|
|
|
setSelectedAudioOutputFromSettings () {
|
|
|
|
$('#selectAudioOutput').val(Settings.getAudioOutputDeviceId());
|
|
|
|
},
|
|
|
|
|
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) {
|
2016-05-05 14:34:15 +00:00
|
|
|
let $selectCamera= $('#selectCamera'),
|
|
|
|
$selectMic = $('#selectMic'),
|
2016-05-06 14:31:23 +00:00
|
|
|
$selectAudioOutput = $('#selectAudioOutput'),
|
|
|
|
$selectAudioOutputParent = $selectAudioOutput.parent();
|
2016-05-05 14:34:15 +00:00
|
|
|
|
2016-05-17 15:58:25 +00:00
|
|
|
let audio = devices.filter(device => device.kind === 'audioinput'),
|
|
|
|
video = devices.filter(device => device.kind === 'videoinput'),
|
|
|
|
audioOutput = devices
|
|
|
|
.filter(device => device.kind === 'audiooutput'),
|
|
|
|
selectedAudioDevice = audio.find(
|
|
|
|
d => d.deviceId === Settings.getMicDeviceId()) || audio[0],
|
|
|
|
selectedVideoDevice = video.find(
|
|
|
|
d => d.deviceId === Settings.getCameraDeviceId()) || video[0],
|
|
|
|
selectedAudioOutputDevice = audioOutput.find(
|
|
|
|
d => d.deviceId === Settings.getAudioOutputDeviceId()),
|
|
|
|
videoPermissionGranted =
|
|
|
|
JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video'),
|
|
|
|
audioPermissionGranted =
|
|
|
|
JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio');
|
2016-02-09 10:19:43 +00:00
|
|
|
|
2016-05-17 15:58:25 +00:00
|
|
|
$selectCamera
|
|
|
|
.html(generateDevicesOptions(
|
|
|
|
video,
|
|
|
|
selectedVideoDevice ? selectedVideoDevice.deviceId : '',
|
|
|
|
videoPermissionGranted))
|
|
|
|
.prop('disabled', !video.length || !videoPermissionGranted);
|
2016-02-09 10:19:43 +00:00
|
|
|
|
2016-05-17 15:58:25 +00:00
|
|
|
$selectMic
|
|
|
|
.html(generateDevicesOptions(
|
|
|
|
audio,
|
|
|
|
selectedAudioDevice ? selectedAudioDevice.deviceId : '',
|
|
|
|
audioPermissionGranted))
|
|
|
|
.prop('disabled', !audio.length || !audioPermissionGranted);
|
|
|
|
|
|
|
|
if (JitsiMeetJS.mediaDevices.isDeviceChangeAvailable('output')) {
|
|
|
|
$selectAudioOutput
|
|
|
|
.html(generateDevicesOptions(
|
|
|
|
audioOutput,
|
|
|
|
selectedAudioOutputDevice
|
|
|
|
? selectedAudioOutputDevice.deviceId
|
|
|
|
: 'default',
|
|
|
|
videoPermissionGranted || audioPermissionGranted))
|
|
|
|
.prop('disabled', !audioOutput.length ||
|
|
|
|
(!videoPermissionGranted && !audioPermissionGranted));
|
2016-05-06 14:31:23 +00:00
|
|
|
|
|
|
|
$selectAudioOutputParent.show();
|
2016-05-05 14:34:15 +00:00
|
|
|
} else {
|
2016-05-06 14:31:23 +00:00
|
|
|
$selectAudioOutputParent.hide();
|
2016-05-05 14:34:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 15:58:25 +00:00
|
|
|
$('#devicesOptions').show();
|
|
|
|
|
2016-09-08 22:34:16 +00:00
|
|
|
APP.translation.translateElement($('#settings_container option'));
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
2016-09-11 21:54:32 +00:00
|
|
|
};
|