瀏覽代碼

feat: introduce ConferenceUrl module

We need to make sure that on the page reload all original parameters
used to load the conference are preserved. New modules helps to manage
different types of conference URLs like the one used for invites and
the one for reloading the page.
efficient_tiling
paweldomas 8 年之前
父節點
當前提交
f7bfe8d8bf

+ 17
- 0
app.js 查看文件

@@ -19,6 +19,7 @@ import 'aui-experimental-css';
19 19
 window.toastr = require("toastr");
20 20
 
21 21
 import URLProcessor from "./modules/config/URLProcessor";
22
+import ConferenceUrl from './modules/URL/ConferenceUrl';
22 23
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
23 24
 
24 25
 import UI from "./modules/UI/UI";
@@ -47,6 +48,18 @@ function pushHistoryState(roomName, URL) {
47 48
     return null;
48 49
 }
49 50
 
51
+/**
52
+ * Replaces current history state(replaces the URL displayed by the browser).
53
+ * @param {string} newUrl the URL string which is to be displayed by the browser
54
+ * to the user.
55
+ */
56
+function replaceHistoryState (newUrl) {
57
+    if (window.history
58
+        && typeof window.history.replaceState === 'function') {
59
+        window.history.replaceState({}, document.title, newUrl);
60
+    }
61
+}
62
+
50 63
 /**
51 64
  * Builds and returns the room name.
52 65
  */
@@ -107,6 +120,10 @@ function setTokenData() {
107 120
 
108 121
 function init() {
109 122
     setTokenData();
123
+    // Initialize the conference URL handler
124
+    ConferenceUrl.init(window.location);
125
+    // Clean up the URL displayed by the browser
126
+    replaceHistoryState(ConferenceUrl.getInviteUrl());
110 127
     var isUIReady = APP.UI.start();
111 128
     if (isUIReady) {
112 129
         APP.conference.init({roomName: buildRoomName()}).then(function () {

+ 0
- 13
modules/UI/UI.js 查看文件

@@ -258,19 +258,6 @@ UI.setLocalRaisedHandStatus = (raisedHandStatus) => {
258 258
  */
259 259
 UI.initConference = function () {
260 260
     let id = APP.conference.getMyUserId();
261
-
262
-    // Do not include query parameters in the invite URL
263
-    // "https:" + "//" + "example.com:8888" + "/SomeConference1245"
264
-    var inviteURL = window.location.protocol + "//" +
265
-        window.location.host + window.location.pathname;
266
-
267
-    this.emitEvent(UIEvents.INVITE_URL_INITIALISED, inviteURL);
268
-
269
-    // Clean up the URL displayed by the browser
270
-    if (window.history && typeof window.history.replaceState === 'function') {
271
-        window.history.replaceState({}, document.title, inviteURL);
272
-    }
273
-
274 261
     // Add myself to the contact list.
275 262
     UI.ContactList.addContact(id, true);
276 263
 

+ 2
- 5
modules/UI/invite/Invite.js 查看文件

@@ -3,6 +3,7 @@
3 3
 import InviteDialogView from './InviteDialogView';
4 4
 import createRoomLocker from './RoomLocker';
5 5
 import UIEvents from  '../../../service/UI/UIEvents';
6
+import ConferenceUrl from '../../URL/ConferenceUrl';
6 7
 
7 8
 const ConferenceEvents = JitsiMeetJS.events.conference;
8 9
 
@@ -14,6 +15,7 @@ const ConferenceEvents = JitsiMeetJS.events.conference;
14 15
 class Invite {
15 16
     constructor(conference) {
16 17
         this.conference = conference;
18
+        this.inviteUrl = ConferenceUrl.getInviteUrl();
17 19
         this.createRoomLocker(conference);
18 20
         this.registerListeners();
19 21
     }
@@ -48,11 +50,6 @@ class Invite {
48 50
         APP.UI.addListener( UIEvents.INVITE_CLICKED,
49 51
                             () => { this.openLinkDialog(); });
50 52
 
51
-        APP.UI.addListener( UIEvents.INVITE_URL_INITIALISED,
52
-                            (inviteUrl) => {
53
-                                this.updateInviteUrl(inviteUrl);
54
-                            });
55
-
56 53
         APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
57 54
             () => {
58 55
                 this.setLockedFromElsewhere(true);

+ 2
- 3
modules/UI/reload_overlay/PageReloadOverlay.js 查看文件

@@ -1,6 +1,6 @@
1 1
 /* global $, APP, AJS */
2 2
 
3
-import { reload } from '../../util/helpers';
3
+import ConferenceUrl from '../../URL/ConferenceUrl';
4 4
 
5 5
 let $overlay;
6 6
 
@@ -78,9 +78,8 @@ function start(timeoutSeconds) {
78 78
         updateDisplay();
79 79
 
80 80
         if (timeLeft === 0) {
81
-            console.info("Reloading!");
82 81
             window.clearInterval(intervalId);
83
-            reload();
82
+            ConferenceUrl.reload();
84 83
         }
85 84
     }, 1000);
86 85
 }

+ 73
- 0
modules/URL/ConferenceUrl.js 查看文件

@@ -0,0 +1,73 @@
1
+
2
+import { redirect } from '../util/helpers';
3
+
4
+/**
5
+ * Stores the original conference room URL with all parameters.
6
+ * @type {string}
7
+ */
8
+let originalURL;
9
+
10
+/**
11
+ * A simplified version of the conference URL stripped out of the parameters
12
+ * which should be used for sending invites.
13
+ * @type {string}
14
+ */
15
+let inviteURL;
16
+
17
+/**
18
+ * The modules stores information about the URL used to start the conference and
19
+ * provides utility methods for dealing with conference URL and reloads.
20
+ */
21
+export default {
22
+    /**
23
+     * Initializes the module.
24
+     *
25
+     * @param location an object which stores provides the info about conference
26
+     * URL(would be 'window.location' for the Web app). The params below are
27
+     * described based on the following example URL:
28
+     *
29
+     * https://example.com:8888/SomeConference1245?opt=1#somehash
30
+     *
31
+     * @param location.href full URL with all parameters, would be the whole URL
32
+     * from the example string above.
33
+     *
34
+     * @param location.host the host part of the URL, 'example.com' from
35
+     * the sample URL above.
36
+     *
37
+     * @param location.pathname the path part of the URL, would be
38
+     * '/SomeConference1245' from the example above.
39
+     *
40
+     * @param location.protocol the protocol part of the URL, would be 'https:'
41
+     * from the sample URL.
42
+     */
43
+    init(location) {
44
+        originalURL = location.href;
45
+        // "https:" + "//" + "example.com:8888" + "/SomeConference1245"
46
+        inviteURL
47
+            = location.protocol + "//" + location.host + location.pathname;
48
+        console.info("Stored original conference URL: " + originalURL);
49
+        console.info("Conference URL for invites: " + inviteURL);
50
+    },
51
+    /**
52
+     * Obtains the conference invite URL.
53
+     * @return {string} the URL pointing o the conference which is mean to be
54
+     * used to invite new participants.
55
+     */
56
+    getInviteUrl() {
57
+        return inviteURL;
58
+    },
59
+    /**
60
+     * Obtains full conference URL with all original parameters.
61
+     * @return {string} the original URL used to open the current conference.
62
+     */
63
+    getOriginalUrl() {
64
+        return originalURL;
65
+    },
66
+    /**
67
+     * Reloads the conference using original URL with all of the parameters.
68
+     */
69
+    reload() {
70
+        console.info("Reloading the conference using URL: " + originalURL);
71
+        redirect(originalURL);
72
+    }
73
+};

+ 9
- 0
modules/util/helpers.js 查看文件

@@ -20,6 +20,15 @@ export function reload () {
20 20
     window.location.reload();
21 21
 }
22 22
 
23
+/**
24
+ * Redirects to new URL.
25
+ * @param {string} url the URL pointing to the location where the user should
26
+ * be redirected to.
27
+ */
28
+export function redirect (url) {
29
+    window.location.replace(url);
30
+}
31
+
23 32
 /**
24 33
  * Prints the error and reports it to the global error handler.
25 34
  * @param e {Error} the error

+ 0
- 5
service/UI/UIEvents.js 查看文件

@@ -145,11 +145,6 @@ export default {
145 145
      */
146 146
     DISPLAY_NAME_CHANGED: "UI.display_name_changed",
147 147
 
148
-    /**
149
-     * Indicates that the invite url has been initialised.
150
-     */
151
-    INVITE_URL_INITIALISED: "UI.invite_url_initialised",
152
-
153 148
     /**
154 149
      * Indicates that a password is required for the call.
155 150
      */

Loading…
取消
儲存