startup.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* This module handles all the different UI that happens (sometimes in order) when
  5. TogetherJS is started:
  6. - Introduce the session when you've been invited
  7. - Show any browser compatibility indicators
  8. - Show the walkthrough the first time
  9. - Show the share link window
  10. When everything is done it fires session.emit("startup-ready")
  11. */
  12. define(["util", "require", "jquery", "windowing", "storage"], function (util, require, $, windowing, storage) {
  13. var assert = util.assert;
  14. var startup = util.Module("startup");
  15. // Avoid circular import:
  16. var session = null;
  17. var STEPS = [
  18. "browserBroken",
  19. "browserUnsupported",
  20. "sessionIntro",
  21. "walkthrough",
  22. // Look in the share() below if you add anything after here:
  23. "share"
  24. ];
  25. var currentStep = null;
  26. startup.start = function () {
  27. if (! session) {
  28. require(["session"], function (sessionModule) {
  29. session = sessionModule;
  30. startup.start();
  31. });
  32. return;
  33. }
  34. var index = -1;
  35. if (currentStep) {
  36. index = STEPS.indexOf(currentStep);
  37. }
  38. index++;
  39. if (index >= STEPS.length) {
  40. session.emit("startup-ready");
  41. return;
  42. }
  43. currentStep = STEPS[index];
  44. handlers[currentStep](startup.start);
  45. };
  46. var handlers = {
  47. browserBroken: function (next) {
  48. if (window.WebSocket) {
  49. next();
  50. return;
  51. }
  52. windowing.show("#togetherjs-browser-broken", {
  53. onClose: function () {
  54. session.close();
  55. }
  56. });
  57. if ($.browser.msie) {
  58. $("#togetherjs-browser-broken-is-ie").show();
  59. }
  60. },
  61. browserUnsupported: function (next) {
  62. next();
  63. },
  64. sessionIntro: function (next) {
  65. if ((! session.isClient) || ! session.firstRun) {
  66. next();
  67. return;
  68. }
  69. TogetherJS.config.close("suppressJoinConfirmation");
  70. if (TogetherJS.config.get("suppressJoinConfirmation")) {
  71. next();
  72. return;
  73. }
  74. var cancelled = false;
  75. windowing.show("#togetherjs-intro", {
  76. onClose: function () {
  77. if (! cancelled) {
  78. next();
  79. }
  80. }
  81. });
  82. $("#togetherjs-intro .togetherjs-modal-dont-join").click(function () {
  83. cancelled = true;
  84. windowing.hide();
  85. session.close("declined-join");
  86. });
  87. },
  88. walkthrough: function (next) {
  89. storage.settings.get("seenIntroDialog").then(function (seenIntroDialog) {
  90. if (seenIntroDialog) {
  91. next();
  92. return;
  93. }
  94. require(["walkthrough"], function (walkthrough) {
  95. walkthrough.start(true, function () {
  96. storage.settings.set("seenIntroDialog", true);
  97. next();
  98. });
  99. });
  100. });
  101. },
  102. share: function (next) {
  103. TogetherJS.config.close("suppressInvite");
  104. if (session.isClient || (! session.firstRun) ||
  105. TogetherJS.config.get("suppressInvite")) {
  106. next();
  107. return;
  108. }
  109. require(["windowing"], function (windowing) {
  110. windowing.show("#togetherjs-share");
  111. // FIXME: no way to detect when the window is closed
  112. // If there was a next() step then it would not work
  113. });
  114. }
  115. };
  116. return startup;
  117. });