浏览代码

Added functionality to connect to an XMPP server.

Can succesfully connect now, but still need to get rid of ajax calls to @@xmp-userinfo, and replace them with
VCards.
JC Brand 12 年之前
父节点
当前提交
c17ffdb98a
共有 3 个文件被更改,包括 67 次插入17 次删除
  1. 13 8
      converse.js
  2. 8 8
      index.html
  3. 46 1
      main.js

+ 13 - 8
converse.js

@@ -43,6 +43,7 @@
         define([
             "Libraries/burry.js/burry",
             "Libraries/underscore.string",
+            "Libraries/jquery-ui-1.9.1.custom",
             "Libraries/sjcl",
             "Libraries/backbone",
             "Libraries/strophe.muc",
@@ -1693,14 +1694,18 @@
                 }, this));
 
             // Controlbox toggler
-            $toggle.bind('click', $.proxy(function (e) {
-                e.preventDefault();
-                if ($("div#controlbox").is(':visible')) {
-                    this.chatboxesview.closeChat('controlbox');
-                } else {
-                    this.chatboxesview.openChat('controlbox');
-                }
-            }, this));
+            if ($toggle.length) {
+                $toggle.bind('click', $.proxy(function (e) {
+                    e.preventDefault();
+                    if ($("div#controlbox").is(':visible')) {
+                        this.chatboxesview.closeChat('controlbox');
+                    } else {
+                        this.chatboxesview.openChat('controlbox');
+                    }
+                }, this));
+            } else {
+                this.chatboxesview.openChat('controlbox');
+            }
         }, this));
     }, xmppchat));
 }));

+ 8 - 8
index.html

@@ -3,22 +3,22 @@
     <head>
         <title>Converse.js Demo Page</title>
         <!-- This is a special version of jQuery with RequireJS built-in -->
-        <link rel="stylesheet" href="css/smoothness/jquery-ui-1.9.0.custom.css" type="text/css" media="all">
+        <link rel="stylesheet" href="Libraries/css/jquery-ui-1.9.1.custom/ui-lightness/jquery-ui-1.9.1.custom.css" type="text/css" media="all">
         <link rel="stylesheet" href="converse.css" type="text/css" media="all">
         <script data-main="main" src="Libraries/require-jquery.js"></script>
     </head>
     <body>
         <h1>Converse.js Demo Page</h1>
-
-        Log in with your Jabber/XMPP ID and password. If you don't have an XMPP
-        account, you can create one for free on <a href="http://register.jabber.org">jabber.org</a>.
-
+        Log in with your Jabber/XMPP ID and password. 
         <!-- login dialog -->
         <div id='login_dialog' class='hidden'>
-            <label>Login ID:</label><input type='text' id='jid'>
-            <label>Password:</label><input type='password' id='password'>
+            <label>Login ID:</label>
+            <input type='text' id='jid'>
+            <label>Password:</label>
+            <input type='password' id='password'>
+            <label>BOSH Service URL:</label>
+            <input type='text' id='bosh_service_url'>
         </div>
-
         <div id="collective-xmpp-chat-data"></div>
     </body>
 </html>

+ 46 - 1
main.js

@@ -1,5 +1,50 @@
 require(["jquery", "converse"], function($) {
     $(function() {
-        alert('success!');
+        $('#login_dialog').dialog({
+            autoOpen: true,
+            draggable: false,
+            modal: true,
+            title: 'Connect to XMPP',
+            buttons: {
+                "Connect": function () {
+                    $(document).trigger('connect', {
+                        jid: $('#jid').val(),
+                        password: $('#password').val(),
+                        bosh_service_url: $('#bosh_service_url').val()
+                    });
+                    $('#password').val('');
+                    $(this).dialog('close');
+                }
+            }
+        });
+
+        $(document).bind('connect', function (ev, data) {
+            var connection = new Strophe.Connection(data.bosh_service_url);
+
+            connection.connect(data.jid, data.password, function (status) {
+                if (status === Strophe.Status.CONNECTED) {
+                    console.log('Connected');
+                    $(document).trigger('jarnxmpp.connected', connection);
+                } else if (status === Strophe.Status.DISCONNECTED) {
+                    console.log('Disconnected');
+                    $(document).trigger('jarnxmpp.disconnected');
+                } else if (status === Strophe.Status.Error) {
+                    console.log('Error');
+                } else if (status === Strophe.Status.CONNECTING) {
+                    console.log('Connecting');
+                } else if (status === Strophe.Status.CONNFAIL) {
+                    console.log('Connection Failed');
+                } else if (status === Strophe.Status.AUTHENTICATING) {
+                    console.log('Authenticating');
+                } else if (status === Strophe.Status.AUTHFAIL) {
+                    console.log('Authenticating Failed');
+                } else if (status === Strophe.Status.DISCONNECTING) {
+                    console.log('Disconnecting');
+                } else if (status === Strophe.Status.ATTACHED) {
+                    console.log('Attached');
+                }
+            });
+        });
+
     });
 });