您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbar.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /* global $, buttonClick, config, lockRoom, Moderator, roomName,
  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. function callSipButtonClicked()
  132. {
  133. var defaultNumber
  134. = config.defaultSipNumber ? config.defaultSipNumber : '';
  135. messageHandler.openTwoButtonDialog(null,
  136. '<h2>Enter SIP number</h2>' +
  137. '<input id="sipNumber" type="text"' +
  138. ' value="' + defaultNumber + '" autofocus>',
  139. false,
  140. "Dial",
  141. function (e, v, m, f) {
  142. if (v) {
  143. var numberInput = document.getElementById('sipNumber');
  144. if (numberInput.value) {
  145. connection.rayo.dial(
  146. numberInput.value, 'fromnumber',
  147. roomName, sharedKey);
  148. }
  149. }
  150. },
  151. function (event) {
  152. document.getElementById('sipNumber').focus();
  153. }
  154. );
  155. }
  156. var Toolbar = (function (my) {
  157. my.init = function () {
  158. for(var k in buttonHandlers)
  159. $("#" + k).click(buttonHandlers[k]);
  160. }
  161. /**
  162. * Sets shared key
  163. * @param sKey the shared key
  164. */
  165. my.setSharedKey = function (sKey) {
  166. sharedKey = sKey;
  167. };
  168. my.closeAuthenticationWindow = function () {
  169. if (authenticationWindow) {
  170. authenticationWindow.close();
  171. authenticationWindow = null;
  172. }
  173. }
  174. my.authenticateClicked = function () {
  175. // If auth window exists just bring it to the front
  176. if (authenticationWindow) {
  177. authenticationWindow.focus();
  178. return;
  179. }
  180. // Get authentication URL
  181. Moderator.getAuthUrl(function (url) {
  182. // Open popup with authentication URL
  183. authenticationWindow = messageHandler.openCenteredPopup(
  184. url, 910, 660,
  185. // On closed
  186. function () {
  187. // Close authentication dialog if opened
  188. if (authDialog) {
  189. messageHandler.closeDialog();
  190. authDialog = null;
  191. }
  192. // On popup closed - retry room allocation
  193. Moderator.allocateConferenceFocus(roomName, doJoinAfterFocus);
  194. authenticationWindow = null;
  195. });
  196. if (!authenticationWindow) {
  197. Toolbar.showAuthenticateButton(true);
  198. messageHandler.openMessageDialog(
  199. null, "Your browser is blocking popup windows from this site." +
  200. " Please enable popups in your browser security settings" +
  201. " and try again.");
  202. }
  203. });
  204. };
  205. /**
  206. * Updates the room invite url.
  207. */
  208. my.updateRoomUrl = function (newRoomUrl) {
  209. roomUrl = newRoomUrl;
  210. // If the invite dialog has been already opened we update the information.
  211. var inviteLink = document.getElementById('inviteLinkRef');
  212. if (inviteLink) {
  213. inviteLink.value = roomUrl;
  214. inviteLink.select();
  215. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  216. }
  217. }
  218. /**
  219. * Disables and enables some of the buttons.
  220. */
  221. my.setupButtonsFromConfig = function () {
  222. if (config.disablePrezi)
  223. {
  224. $("#prezi_button").css({display: "none"});
  225. }
  226. };
  227. /**
  228. * Opens the lock room dialog.
  229. */
  230. my.openLockDialog = function () {
  231. // Only the focus is able to set a shared key.
  232. if (!Moderator.isModerator()) {
  233. if (sharedKey) {
  234. messageHandler.openMessageDialog(null,
  235. "This conversation is currently protected by" +
  236. " a password. Only the owner of the conference" +
  237. " could set a password.",
  238. false,
  239. "Password");
  240. } else {
  241. messageHandler.openMessageDialog(null,
  242. "This conversation isn't currently protected by" +
  243. " a password. Only the owner of the conference" +
  244. " could set a password.",
  245. false,
  246. "Password");
  247. }
  248. } else {
  249. if (sharedKey) {
  250. messageHandler.openTwoButtonDialog(null,
  251. "Are you sure you would like to remove your password?",
  252. false,
  253. "Remove",
  254. function (e, v) {
  255. if (v) {
  256. Toolbar.setSharedKey('');
  257. lockRoom(false);
  258. }
  259. });
  260. } else {
  261. messageHandler.openTwoButtonDialog(null,
  262. '<h2>Set a password to lock your room</h2>' +
  263. '<input id="lockKey" type="text"' +
  264. 'placeholder="your password" autofocus>',
  265. false,
  266. "Save",
  267. function (e, v) {
  268. if (v) {
  269. var lockKey = document.getElementById('lockKey');
  270. if (lockKey.value) {
  271. Toolbar.setSharedKey(Util.escapeHtml(lockKey.value));
  272. lockRoom(true);
  273. }
  274. }
  275. },
  276. function () {
  277. document.getElementById('lockKey').focus();
  278. }
  279. );
  280. }
  281. }
  282. };
  283. /**
  284. * Opens the invite link dialog.
  285. */
  286. my.openLinkDialog = function () {
  287. var inviteLink;
  288. if (roomUrl === null) {
  289. inviteLink = "Your conference is currently being created...";
  290. } else {
  291. inviteLink = encodeURI(roomUrl);
  292. }
  293. messageHandler.openTwoButtonDialog(
  294. "Share this link with everyone you want to invite",
  295. '<input id="inviteLinkRef" type="text" value="' +
  296. inviteLink + '" onclick="this.select();" readonly>',
  297. false,
  298. "Invite",
  299. function (e, v) {
  300. if (v) {
  301. if (roomUrl) {
  302. inviteParticipants();
  303. }
  304. }
  305. },
  306. function () {
  307. if (roomUrl) {
  308. document.getElementById('inviteLinkRef').select();
  309. } else {
  310. document.getElementById('jqi_state0_buttonInvite')
  311. .disabled = true;
  312. }
  313. }
  314. );
  315. };
  316. /**
  317. * Opens the settings dialog.
  318. */
  319. my.openSettingsDialog = function () {
  320. messageHandler.openTwoButtonDialog(
  321. '<h2>Configure your conference</h2>' +
  322. '<input type="checkbox" id="initMuted">' +
  323. 'Participants join muted<br/>' +
  324. '<input type="checkbox" id="requireNicknames">' +
  325. 'Require nicknames<br/><br/>' +
  326. 'Set a password to lock your room:' +
  327. '<input id="lockKey" type="text" placeholder="your password"' +
  328. 'autofocus>',
  329. null,
  330. false,
  331. "Save",
  332. function () {
  333. document.getElementById('lockKey').focus();
  334. },
  335. function (e, v) {
  336. if (v) {
  337. if ($('#initMuted').is(":checked")) {
  338. // it is checked
  339. }
  340. if ($('#requireNicknames').is(":checked")) {
  341. // it is checked
  342. }
  343. /*
  344. var lockKey = document.getElementById('lockKey');
  345. if (lockKey.value) {
  346. setSharedKey(lockKey.value);
  347. lockRoom(true);
  348. }
  349. */
  350. }
  351. }
  352. );
  353. };
  354. /**
  355. * Toggles the application in and out of full screen mode
  356. * (a.k.a. presentation mode in Chrome).
  357. */
  358. my.toggleFullScreen = function () {
  359. var fsElement = document.documentElement;
  360. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  361. //Enter Full Screen
  362. if (fsElement.mozRequestFullScreen) {
  363. fsElement.mozRequestFullScreen();
  364. }
  365. else {
  366. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  367. }
  368. } else {
  369. //Exit Full Screen
  370. if (document.mozCancelFullScreen) {
  371. document.mozCancelFullScreen();
  372. } else {
  373. document.webkitCancelFullScreen();
  374. }
  375. }
  376. };
  377. /**
  378. * Unlocks the lock button state.
  379. */
  380. my.unlockLockButton = function () {
  381. if ($("#lockIcon").hasClass("icon-security-locked"))
  382. buttonClick("#lockIcon", "icon-security icon-security-locked");
  383. };
  384. /**
  385. * Updates the lock button state to locked.
  386. */
  387. my.lockLockButton = function () {
  388. if ($("#lockIcon").hasClass("icon-security"))
  389. buttonClick("#lockIcon", "icon-security icon-security-locked");
  390. };
  391. /**
  392. * Shows or hides authentication button
  393. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  394. */
  395. my.showAuthenticateButton = function (show) {
  396. if (show) {
  397. $('#authentication').css({display: "inline"});
  398. }
  399. else {
  400. $('#authentication').css({display: "none"});
  401. }
  402. };
  403. // Shows or hides the 'recording' button.
  404. my.showRecordingButton = function (show) {
  405. if (!config.enableRecording) {
  406. return;
  407. }
  408. if (show) {
  409. $('#recording').css({display: "inline"});
  410. }
  411. else {
  412. $('#recording').css({display: "none"});
  413. }
  414. };
  415. // Sets the state of the recording button
  416. my.setRecordingButtonState = function (isRecording) {
  417. if (isRecording) {
  418. $('#recordButton').removeClass("icon-recEnable");
  419. $('#recordButton').addClass("icon-recEnable active");
  420. } else {
  421. $('#recordButton').removeClass("icon-recEnable active");
  422. $('#recordButton').addClass("icon-recEnable");
  423. }
  424. };
  425. // Shows or hides SIP calls button
  426. my.showSipCallButton = function (show) {
  427. if (Moderator.isSipGatewayEnabled() && show) {
  428. $('#sipCallButton').css({display: "inline"});
  429. } else {
  430. $('#sipCallButton').css({display: "none"});
  431. }
  432. };
  433. /**
  434. * Sets the state of the button. The button has blue glow if desktop
  435. * streaming is active.
  436. * @param active the state of the desktop streaming.
  437. */
  438. my.changeDesktopSharingButtonState = function (active) {
  439. var button = $("#desktopsharing > a");
  440. if (active)
  441. {
  442. button.addClass("glow");
  443. }
  444. else
  445. {
  446. button.removeClass("glow");
  447. }
  448. };
  449. return my;
  450. }(Toolbar || {}));
  451. module.exports = Toolbar;