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.
This commit is contained in:
JC Brand 2012-11-20 13:23:03 +02:00
parent aecc9942fc
commit c17ffdb98a
3 changed files with 67 additions and 17 deletions

View File

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

View File

@ -3,22 +3,22 @@
<head> <head>
<title>Converse.js Demo Page</title> <title>Converse.js Demo Page</title>
<!-- This is a special version of jQuery with RequireJS built-in --> <!-- 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"> <link rel="stylesheet" href="converse.css" type="text/css" media="all">
<script data-main="main" src="Libraries/require-jquery.js"></script> <script data-main="main" src="Libraries/require-jquery.js"></script>
</head> </head>
<body> <body>
<h1>Converse.js Demo Page</h1> <h1>Converse.js Demo Page</h1>
Log in with your Jabber/XMPP ID and password.
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>.
<!-- login dialog --> <!-- login dialog -->
<div id='login_dialog' class='hidden'> <div id='login_dialog' class='hidden'>
<label>Login ID:</label><input type='text' id='jid'> <label>Login ID:</label>
<label>Password:</label><input type='password' id='password'> <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>
<div id="collective-xmpp-chat-data"></div> <div id="collective-xmpp-chat-data"></div>
</body> </body>
</html> </html>

47
main.js
View File

@ -1,5 +1,50 @@
require(["jquery", "converse"], function($) { require(["jquery", "converse"], function($) {
$(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');
}
});
});
}); });
}); });