浏览代码

Makes "authentication required" dialog persistent. Joins the room if someone else authenticates first and creates the conference for us.

j8
paweldomas 10 年前
父节点
当前提交
cd0c9393d8
共有 2 个文件被更改,包括 74 次插入27 次删除
  1. 57
    23
      app.js
  2. 17
    4
      message_handler.js

+ 57
- 23
app.js 查看文件

2
 /* application specific logic */
2
 /* application specific logic */
3
 var connection = null;
3
 var connection = null;
4
 var authenticatedUser = false;
4
 var authenticatedUser = false;
5
+/* Popup window that show login page */
5
 var authenticationWindow = null;
6
 var authenticationWindow = null;
7
+/* Initial "authentication required" dialog */
8
+var authDialog = null;
9
+/* Loop retry ID that wits for other user to create the room */
10
+var authRetryId = null;
6
 var activecall = null;
11
 var activecall = null;
7
 var nickname = null;
12
 var nickname = null;
8
 var sharedKey = '';
13
 var sharedKey = '';
187
 
192
 
188
 function doJoinAfterFocus() {
193
 function doJoinAfterFocus() {
189
 
194
 
195
+    // Close authentication dialog if opened
196
+    if (authDialog) {
197
+        messageHandler.closeDialog();
198
+        authDialog = null;
199
+    }
200
+    // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice
201
+    if (authRetryId) {
202
+        window.clearTimeout(authRetryId);
203
+        authRetryId = null;
204
+    }
205
+
190
     var roomjid;
206
     var roomjid;
191
     roomjid = roomName;
207
     roomjid = roomName;
192
 
208
 
879
 });
895
 });
880
 
896
 
881
 $(document).bind('auth_required.moderator', function () {
897
 $(document).bind('auth_required.moderator', function () {
898
+
899
+    // This is the loop that will wait for the room to be created by
900
+    // someone else. 'auth_required.moderator' will bring us back here.
901
+    authRetryId = window.setTimeout(
902
+        function () {
903
+            Moderator.allocateConferenceFocus(roomName, doJoinAfterFocus);
904
+        }, 5000);
905
+    // Show prompt only if it's not open
906
+    if (authDialog !== null) {
907
+        return;
908
+    }
882
     // extract room name from 'room@muc.server.net'
909
     // extract room name from 'room@muc.server.net'
883
     var room = roomName.substr(0, roomName.indexOf('@'));
910
     var room = roomName.substr(0, roomName.indexOf('@'));
884
 
911
 
885
-    messageHandler.openDialog(
912
+    authDialog = messageHandler.openDialog(
886
         'Stop',
913
         'Stop',
887
-        'Authentication is required to create room:<br/>' + room,
914
+        'Authentication is required to create room:<br/><b>' + room +
915
+        '</b></br> You can either authenticate to create the room or ' +
916
+        'just wait for someone else to do so.',
888
         true,
917
         true,
889
         {
918
         {
890
-            Authenticate: 'authNow',
891
-            Close: 'close'
919
+            Authenticate: 'authNow'
892
         },
920
         },
893
         function (onSubmitEvent, submitValue) {
921
         function (onSubmitEvent, submitValue) {
894
-            console.info('On submit: ' + submitValue, submitValue);
922
+
923
+            // Do not close the dialog yet
924
+            onSubmitEvent.preventDefault();
925
+
926
+            // Open login popup
895
             if (submitValue === 'authNow') {
927
             if (submitValue === 'authNow') {
896
                 authenticateClicked();
928
                 authenticateClicked();
897
-            } else {
898
-                Toolbar.showAuthenticateButton(true);
899
             }
929
             }
900
         }
930
         }
901
     );
931
     );
902
 });
932
 });
903
 
933
 
904
 function authenticateClicked() {
934
 function authenticateClicked() {
935
+    // If auth window exists just bring it to the front
936
+    if (authenticationWindow) {
937
+        authenticationWindow.focus();
938
+        return;
939
+    }
905
     // Get authentication URL
940
     // Get authentication URL
906
     Moderator.getAuthUrl(function (url) {
941
     Moderator.getAuthUrl(function (url) {
907
         // Open popup with authentication URL
942
         // Open popup with authentication URL
908
         authenticationWindow = messageHandler.openCenteredPopup(
943
         authenticationWindow = messageHandler.openCenteredPopup(
909
             url, 910, 660,
944
             url, 910, 660,
945
+            // On closed
910
             function () {
946
             function () {
947
+                // Close authentication dialog if opened
948
+                if (authDialog) {
949
+                    messageHandler.closeDialog();
950
+                    authDialog = null;
951
+                }
911
                 // On popup closed - retry room allocation
952
                 // On popup closed - retry room allocation
912
-                Moderator.allocateConferenceFocus(
913
-                    roomName, doJoinAfterFocus);
953
+                Moderator.allocateConferenceFocus(roomName, doJoinAfterFocus);
914
                 authenticationWindow = null;
954
                 authenticationWindow = null;
915
             });
955
             });
916
         if (!authenticationWindow) {
956
         if (!authenticationWindow) {
1587
 
1627
 
1588
     }
1628
     }
1589
 
1629
 
1590
-    $.prompt("Session Terminated",
1630
+    messageHandler.openDialog(
1631
+        "Session Terminated",
1632
+        "You hung up the call",
1633
+        true,
1634
+        { "Join again": true },
1635
+        function(event, value, message, formVals)
1591
         {
1636
         {
1592
-            title: "You hung up the call",
1593
-            persistent: true,
1594
-            buttons: {
1595
-                "Join again": true
1596
-            },
1597
-            closeText: '',
1598
-            submit: function(event, value, message, formVals)
1599
-            {
1600
-                window.location.reload();
1601
-                return false;
1602
-            }
1603
-
1637
+            window.location.reload();
1638
+            return false;
1604
         }
1639
         }
1605
     );
1640
     );
1606
-
1607
 }
1641
 }

+ 17
- 4
message_handler.js 查看文件

1
+/* global $, jQuery */
1
 var messageHandler = (function(my) {
2
 var messageHandler = (function(my) {
2
 
3
 
3
     /**
4
     /**
53
      * @param submitFunction function to be called on submit
54
      * @param submitFunction function to be called on submit
54
      * @param loadedFunction function to be called after the prompt is fully loaded
55
      * @param loadedFunction function to be called after the prompt is fully loaded
55
      */
56
      */
56
-    my.openDialog = function(titleString, msgString, persistent, buttons, submitFunction, loadedFunction) {
57
-        $.prompt(msgString, {
57
+    my.openDialog = function (titleString,    msgString, persistent, buttons,
58
+                              submitFunction, loadedFunction) {
59
+        var args = {
58
             title: titleString,
60
             title: titleString,
59
-            persistent: false,
61
+            persistent: persistent,
60
             buttons: buttons,
62
             buttons: buttons,
61
             defaultButton: 1,
63
             defaultButton: 1,
62
             loaded: loadedFunction,
64
             loaded: loadedFunction,
63
             submit: submitFunction
65
             submit: submitFunction
64
-        });
66
+        };
67
+        if (persistent) {
68
+            args.closeText = '';
69
+        }
70
+        return $.prompt(msgString, args);
71
+    };
72
+
73
+    /**
74
+     * Closes currently opened dialog.
75
+     */
76
+    my.closeDialog = function () {
77
+        $.prompt.close();
65
     };
78
     };
66
 
79
 
67
     /**
80
     /**

正在加载...
取消
保存