123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /* global APP, $ */
- import AnalyticsAdapter from '../statistics/AnalyticsAdapter';
- //maps keycode to character, id of popover for given function and function
- var shortcuts = {};
- function initShortcutHandlers() {
- shortcuts = {
- "ESCAPE": {
- character: "Esc",
- function: function() {
- APP.UI.showKeyboardShortcutsPanel(false);
- }
- },
- "C": {
- character: "C",
- id: "toggleChatPopover",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.chat.toggled');
- APP.UI.toggleChat();
- }
- },
- "D": {
- character: "D",
- id: "toggleDesktopSharingPopover",
- function: function () {
- AnalyticsAdapter.sendEvent('shortcut.screen.toggled');
- APP.conference.toggleScreenSharing();
- }
- },
- "F": {
- character: "F",
- id: "filmstripPopover",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.film.toggled');
- APP.UI.toggleFilmStrip();
- }
- },
- "M": {
- character: "M",
- id: "mutePopover",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.audiomute.toggled');
- APP.conference.toggleAudioMuted();
- }
- },
- "R": {
- character: "R",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.raisedhand.toggled');
- APP.conference.maybeToggleRaisedHand();
- }
-
- },
- "T": {
- character: "T",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.talk.clicked');
- APP.conference.muteAudio(true);
- }
- },
- "V": {
- character: "V",
- id: "toggleVideoPopover",
- function: function() {
- AnalyticsAdapter.sendEvent('shortcut.videomute.toggled');
- APP.conference.toggleVideoMuted();
- }
- },
- "?": {
- character: "?",
- function: function(e) {
- AnalyticsAdapter.sendEvent('shortcut.shortcut.help');
- APP.UI.toggleKeyboardShortcutsPanel();
- }
- }
- };
- }
-
- var KeyboardShortcut = {
- init: function () {
- initShortcutHandlers();
- var self = this;
- window.onkeyup = function(e) {
- var key = self.getKeyboardKey(e).toUpperCase();
- var num = parseInt(key, 10);
- if(!($(":focus").is("input[type=text]") ||
- $(":focus").is("input[type=password]") ||
- $(":focus").is("textarea"))) {
- if (shortcuts.hasOwnProperty(key)) {
- shortcuts[key].function(e);
- }
- else if (!isNaN(num) && num >= 0 && num <= 9) {
- APP.UI.clickOnVideo(num + 1);
- }
- //esc while the smileys are visible hides them
- } else if (key === "ESCAPE" &&
- $('#smileysContainer').is(':visible')) {
- APP.UI.toggleSmileys();
- }
- };
-
- window.onkeydown = function(e) {
- if(!($(":focus").is("input[type=text]") ||
- $(":focus").is("input[type=password]") ||
- $(":focus").is("textarea"))) {
- var key = self.getKeyboardKey(e).toUpperCase();
- if(key === "T") {
- if(APP.conference.isLocalAudioMuted())
- APP.conference.muteAudio(false);
- }
- }
- };
- $('body').popover({ selector: '[data-toggle=popover]',
- trigger: 'click hover',
- content: function() {
- return this.getAttribute("content") +
- self.getShortcut(this.getAttribute("shortcut"));
- }
- });
- },
- /**
- *
- * @param id indicates the popover associated with the shortcut
- * @returns {string} the keyboard shortcut used for the id given
- */
- getShortcut: function (id) {
- for (var key in shortcuts) {
- if (shortcuts.hasOwnProperty(key)) {
- if (shortcuts[key].id === id) {
- return " (" + shortcuts[key].character + ")";
- }
- }
- }
- return "";
- },
- /**
- * @param e a KeyboardEvent
- * @returns {string} e.key or something close if not supported
- */
- getKeyboardKey: function (e) {
- if (typeof e.key === "string") {
- return e.key;
- }
- if (e.type === "keypress" && (
- (e.which >= 32 && e.which <= 126) ||
- (e.which >= 160 && e.which <= 255) )) {
- return String.fromCharCode(e.which);
- }
- // try to fallback (0-9A-Za-z and QWERTY keyboard)
- switch (e.which) {
- case 27:
- return "Escape";
- case 191:
- return e.shiftKey ? "?" : "/";
- }
- if (e.shiftKey || e.type === "keypress") {
- return String.fromCharCode(e.which);
- } else {
- return String.fromCharCode(e.which).toLowerCase();
- }
- }
- };
-
- module.exports = KeyboardShortcut;
|