You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /* global $, buttonClick, config, lockRoom, Moderator,
  2. setSharedKey, sharedKey, Util */
  3. var messageHandler = require("../util/MessageHandler");
  4. var BottomToolbar = require("./BottomToolbar");
  5. var Prezi = require("../prezi/Prezi");
  6. var Etherpad = require("../etherpad/Etherpad");
  7. var PanelToggler = require("../side_pannels/SidePanelToggler");
  8. var roomUrl = null;
  9. var sharedKey = '';
  10. var authenticationWindow = null;
  11. var buttonHandlers =
  12. {
  13. "toolbar_button_mute": function () {
  14. return toggleAudio();
  15. },
  16. "toolbar_button_camera": function () {
  17. return toggleVideo();
  18. },
  19. "toolbar_button_authentication": function () {
  20. return Toolbar.authenticateClicked();
  21. },
  22. "toolbar_button_record": function () {
  23. return toggleRecording();
  24. },
  25. "toolbar_button_security": function () {
  26. return Toolbar.openLockDialog();
  27. },
  28. "toolbar_button_link": function () {
  29. return Toolbar.openLinkDialog();
  30. },
  31. "toolbar_button_chat": function () {
  32. return BottomToolbar.toggleChat();
  33. },
  34. "toolbar_button_prezi": function () {
  35. return Prezi.openPreziDialog();
  36. },
  37. "toolbar_button_etherpad": function () {
  38. return Etherpad.toggleEtherpad(0);
  39. },
  40. "toolbar_button_desktopsharing": function () {
  41. return toggleScreenSharing();
  42. },
  43. "toolbar_button_fullScreen": function()
  44. {
  45. buttonClick("#fullScreen", "icon-full-screen icon-exit-full-screen");
  46. return Toolbar.toggleFullScreen();
  47. },
  48. "toolbar_button_sip": function () {
  49. return callSipButtonClicked();
  50. },
  51. "toolbar_button_settings": function () {
  52. PanelToggler.toggleSettingsMenu();
  53. },
  54. "toolbar_button_hangup": function () {
  55. return hangup();
  56. }
  57. };
  58. /**
  59. * Starts or stops the recording for the conference.
  60. */
  61. function toggleRecording() {
  62. Recording.toggleRecording();
  63. }
  64. /**
  65. * Locks / unlocks the room.
  66. */
  67. function lockRoom(lock) {
  68. var currentSharedKey = '';
  69. if (lock)
  70. currentSharedKey = sharedKey;
  71. connection.emuc.lockRoom(currentSharedKey, function (res) {
  72. // password is required
  73. if (sharedKey)
  74. {
  75. console.log('set room password');
  76. Toolbar.lockLockButton();
  77. }
  78. else
  79. {
  80. console.log('removed room password');
  81. Toolbar.unlockLockButton();
  82. }
  83. }, function (err) {
  84. console.warn('setting password failed', err);
  85. messageHandler.showError('Lock failed',
  86. 'Failed to lock conference.',
  87. err);
  88. Toolbar.setSharedKey('');
  89. }, function () {
  90. console.warn('room passwords not supported');
  91. messageHandler.showError('Warning',
  92. 'Room passwords are currently not supported.');
  93. Toolbar.setSharedKey('');
  94. });
  95. };
  96. /**
  97. * Invite participants to conference.
  98. */
  99. function inviteParticipants() {
  100. if (roomUrl === null)
  101. return;
  102. var sharedKeyText = "";
  103. if (sharedKey && sharedKey.length > 0) {
  104. sharedKeyText =
  105. "This conference is password protected. Please use the " +
  106. "following pin when joining:%0D%0A%0D%0A" +
  107. sharedKey + "%0D%0A%0D%0A";
  108. }
  109. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  110. var subject = "Invitation to a " + interfaceConfig.APP_NAME + " (" + conferenceName + ")";
  111. var body = "Hey there, I%27d like to invite you to a " + interfaceConfig.APP_NAME +
  112. " conference I%27ve just set up.%0D%0A%0D%0A" +
  113. "Please click on the following link in order" +
  114. " to join the conference.%0D%0A%0D%0A" +
  115. roomUrl +
  116. "%0D%0A%0D%0A" +
  117. sharedKeyText +
  118. "Note that " + interfaceConfig.APP_NAME + " is currently" +
  119. " only supported by Chromium," +
  120. " Google Chrome and Opera, so you need" +
  121. " to be using one of these browsers.%0D%0A%0D%0A" +
  122. "Talk to you in a sec!";
  123. if (window.localStorage.displayname) {
  124. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  125. }
  126. if (interfaceConfig.INVITATION_POWERED_BY) {
  127. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  128. }
  129. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  130. }
  131. var Toolbar = (function (my) {
  132. my.init = function () {
  133. for(var k in buttonHandlers)
  134. $("#" + k).click(buttonHandlers[k]);
  135. }
  136. /**
  137. * Sets shared key
  138. * @param sKey the shared key
  139. */
  140. my.setSharedKey = function (sKey) {
  141. sharedKey = sKey;
  142. };
  143. my.closeAuthenticationWindow = function () {
  144. if (authenticationWindow) {
  145. authenticationWindow.close();
  146. authenticationWindow = null;
  147. }
  148. }
  149. my.authenticateClicked = function () {
  150. // Get authentication URL
  151. Moderator.getAuthUrl(function (url) {
  152. // Open popup with authentication URL
  153. authenticationWindow = messageHandler.openCenteredPopup(
  154. url, 500, 400,
  155. function () {
  156. // On popup closed - retry room allocation
  157. Moderator.allocateConferenceFocus(
  158. roomName, doJoinAfterFocus);
  159. authenticationWindow = null;
  160. });
  161. if (!authenticationWindow) {
  162. Toolbar.showAuthenticateButton(true);
  163. messageHandler.openMessageDialog(
  164. null, "Your browser is blocking popup windows from this site." +
  165. " Please enable popups in your browser security settings" +
  166. " and try again.");
  167. }
  168. });
  169. };
  170. /**
  171. * Updates the room invite url.
  172. */
  173. my.updateRoomUrl = function (newRoomUrl) {
  174. roomUrl = newRoomUrl;
  175. // If the invite dialog has been already opened we update the information.
  176. var inviteLink = document.getElementById('inviteLinkRef');
  177. if (inviteLink) {
  178. inviteLink.value = roomUrl;
  179. inviteLink.select();
  180. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  181. }
  182. }
  183. /**
  184. * Disables and enables some of the buttons.
  185. */
  186. my.setupButtonsFromConfig = function () {
  187. if (config.disablePrezi)
  188. {
  189. $("#prezi_button").css({display: "none"});
  190. }
  191. };
  192. /**
  193. * Opens the lock room dialog.
  194. */
  195. my.openLockDialog = function () {
  196. // Only the focus is able to set a shared key.
  197. if (!Moderator.isModerator()) {
  198. if (sharedKey) {
  199. messageHandler.openMessageDialog(null,
  200. "This conversation is currently protected by" +
  201. " a password. Only the owner of the conference" +
  202. " could set a password.",
  203. false,
  204. "Password");
  205. } else {
  206. messageHandler.openMessageDialog(null,
  207. "This conversation isn't currently protected by" +
  208. " a password. Only the owner of the conference" +
  209. " could set a password.",
  210. false,
  211. "Password");
  212. }
  213. } else {
  214. if (sharedKey) {
  215. messageHandler.openTwoButtonDialog(null,
  216. "Are you sure you would like to remove your password?",
  217. false,
  218. "Remove",
  219. function (e, v) {
  220. if (v) {
  221. Toolbar.setSharedKey('');
  222. lockRoom(false);
  223. }
  224. });
  225. } else {
  226. messageHandler.openTwoButtonDialog(null,
  227. '<h2>Set a password to lock your room</h2>' +
  228. '<input id="lockKey" type="text"' +
  229. 'placeholder="your password" autofocus>',
  230. false,
  231. "Save",
  232. function (e, v) {
  233. if (v) {
  234. var lockKey = document.getElementById('lockKey');
  235. if (lockKey.value) {
  236. Toolbar.setSharedKey(Util.escapeHtml(lockKey.value));
  237. lockRoom(true);
  238. }
  239. }
  240. },
  241. function () {
  242. document.getElementById('lockKey').focus();
  243. }
  244. );
  245. }
  246. }
  247. };
  248. /**
  249. * Opens the invite link dialog.
  250. */
  251. my.openLinkDialog = function () {
  252. var inviteLink;
  253. if (roomUrl === null) {
  254. inviteLink = "Your conference is currently being created...";
  255. } else {
  256. inviteLink = encodeURI(roomUrl);
  257. }
  258. messageHandler.openTwoButtonDialog(
  259. "Share this link with everyone you want to invite",
  260. '<input id="inviteLinkRef" type="text" value="' +
  261. inviteLink + '" onclick="this.select();" readonly>',
  262. false,
  263. "Invite",
  264. function (e, v) {
  265. if (v) {
  266. if (roomUrl) {
  267. inviteParticipants();
  268. }
  269. }
  270. },
  271. function () {
  272. if (roomUrl) {
  273. document.getElementById('inviteLinkRef').select();
  274. } else {
  275. document.getElementById('jqi_state0_buttonInvite')
  276. .disabled = true;
  277. }
  278. }
  279. );
  280. };
  281. /**
  282. * Opens the settings dialog.
  283. */
  284. my.openSettingsDialog = function () {
  285. messageHandler.openTwoButtonDialog(
  286. '<h2>Configure your conference</h2>' +
  287. '<input type="checkbox" id="initMuted">' +
  288. 'Participants join muted<br/>' +
  289. '<input type="checkbox" id="requireNicknames">' +
  290. 'Require nicknames<br/><br/>' +
  291. 'Set a password to lock your room:' +
  292. '<input id="lockKey" type="text" placeholder="your password"' +
  293. 'autofocus>',
  294. null,
  295. false,
  296. "Save",
  297. function () {
  298. document.getElementById('lockKey').focus();
  299. },
  300. function (e, v) {
  301. if (v) {
  302. if ($('#initMuted').is(":checked")) {
  303. // it is checked
  304. }
  305. if ($('#requireNicknames').is(":checked")) {
  306. // it is checked
  307. }
  308. /*
  309. var lockKey = document.getElementById('lockKey');
  310. if (lockKey.value) {
  311. setSharedKey(lockKey.value);
  312. lockRoom(true);
  313. }
  314. */
  315. }
  316. }
  317. );
  318. };
  319. /**
  320. * Toggles the application in and out of full screen mode
  321. * (a.k.a. presentation mode in Chrome).
  322. */
  323. my.toggleFullScreen = function () {
  324. var fsElement = document.documentElement;
  325. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  326. //Enter Full Screen
  327. if (fsElement.mozRequestFullScreen) {
  328. fsElement.mozRequestFullScreen();
  329. }
  330. else {
  331. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  332. }
  333. } else {
  334. //Exit Full Screen
  335. if (document.mozCancelFullScreen) {
  336. document.mozCancelFullScreen();
  337. } else {
  338. document.webkitCancelFullScreen();
  339. }
  340. }
  341. };
  342. /**
  343. * Unlocks the lock button state.
  344. */
  345. my.unlockLockButton = function () {
  346. if ($("#lockIcon").hasClass("icon-security-locked"))
  347. buttonClick("#lockIcon", "icon-security icon-security-locked");
  348. };
  349. /**
  350. * Updates the lock button state to locked.
  351. */
  352. my.lockLockButton = function () {
  353. if ($("#lockIcon").hasClass("icon-security"))
  354. buttonClick("#lockIcon", "icon-security icon-security-locked");
  355. };
  356. /**
  357. * Shows or hides authentication button
  358. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  359. */
  360. my.showAuthenticateButton = function (show) {
  361. if (show) {
  362. $('#authentication').css({display: "inline"});
  363. }
  364. else {
  365. $('#authentication').css({display: "none"});
  366. }
  367. };
  368. // Shows or hides the 'recording' button.
  369. my.showRecordingButton = function (show) {
  370. if (!config.enableRecording) {
  371. return;
  372. }
  373. if (show) {
  374. $('#recording').css({display: "inline"});
  375. }
  376. else {
  377. $('#recording').css({display: "none"});
  378. }
  379. };
  380. // Sets the state of the recording button
  381. my.setRecordingButtonState = function (isRecording) {
  382. if (isRecording) {
  383. $('#recordButton').removeClass("icon-recEnable");
  384. $('#recordButton').addClass("icon-recEnable active");
  385. } else {
  386. $('#recordButton').removeClass("icon-recEnable active");
  387. $('#recordButton').addClass("icon-recEnable");
  388. }
  389. };
  390. // Shows or hides SIP calls button
  391. my.showSipCallButton = function (show) {
  392. if (config.hosts.call_control && show) {
  393. $('#sipCallButton').css({display: "inline"});
  394. } else {
  395. $('#sipCallButton').css({display: "none"});
  396. }
  397. };
  398. /**
  399. * Sets the state of the button. The button has blue glow if desktop
  400. * streaming is active.
  401. * @param active the state of the desktop streaming.
  402. */
  403. my.changeDesktopSharingButtonState = function (active) {
  404. var button = $("#desktopsharing > a");
  405. if (active)
  406. {
  407. button.addClass("glow");
  408. }
  409. else
  410. {
  411. button.removeClass("glow");
  412. }
  413. };
  414. return my;
  415. }(Toolbar || {}));
  416. module.exports = Toolbar;