Skip to content

Commit 8131a0b

Browse files
twondsmetajack
authored andcommittedDec 9, 2008
Add in discojs demo as contrib.
1 parent 2aee289 commit 8131a0b

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed
 

‎contrib/discojs/README.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Disco Dancing with XMPP
2+
3+
There are many things one can do via XMPP. The list is
4+
endlist. But one thing that some forget about is discovering
5+
services a XMPP entity or server provides. In most cases a human or
6+
user does not care about this information and should not care. But
7+
you may have a website or web application that needs this
8+
information in order to decide what options to show to your
9+
users. You can do this very easily with JQuery, Strophe, and
10+
Punjab.
11+
12+
We start with Punjab or a BOSH connection manager. This is
13+
needed so we can connect to a XMPP server. First, lets download
14+
punjab.
15+
16+
svn co https://code.stanziq.com/svn/punjab/trunk punjab
17+
18+
After we have punjab go into the directory and install punjab.
19+
20+
cd punjab
21+
python setup.py install
22+
23+
Then create a .tac file to configure Punjab.
24+
25+
See punjab.tac
26+
27+
Next, we will need Strophe. Lets download thelatest version from
28+
svn too.
29+
30+
cd /directory/where/you/configured/punjab/html
31+
32+
svn co https://code.stanziq.com/svn/strophe/trunk/strophejs
33+
34+
In your html directory you will then begin to create your disco browser.
35+
36+
Version 1 we take the basic example and modify it to do disco.
37+
38+
Version 2 we add anonymous login
39+
40+
Version 3 we make it pretty
41+
42+
Version 4 we add handlers for different services

‎contrib/discojs/css/disco.css

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#login .leftinput
2+
{
3+
margin-bottom: .5em;
4+
}
5+
6+
#login input
7+
{
8+
margin-bottom: 10px;
9+
}
10+
11+
#log {
12+
width: 100%;
13+
height: 200px;
14+
overflow: auto;
15+
16+
}

‎contrib/discojs/index.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<title>XMPP Disco Dancing</title>
5+
<script language='javascript'
6+
type='text/javascript'
7+
src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
8+
<script language='javascript'
9+
type='text/javascript'
10+
src='strophejs/b64.js'></script>
11+
<script language='javascript'
12+
type='text/javascript'
13+
src='strophejs/md5.js'></script>
14+
<script language='javascript'
15+
type='text/javascript'
16+
src='strophejs/sha1.js'></script>
17+
<script language='javascript'
18+
type='text/javascript'
19+
src='strophejs/strophe.js'></script>
20+
<script language='javascript'
21+
type='text/javascript'
22+
src='scripts/basic.js'></script>
23+
<script language='javascript'
24+
type='text/javascript'
25+
src='scripts/disco.js'></script>
26+
<link rel="stylesheet" href="css/disco.css" type="text/css" />
27+
</head>
28+
<body>
29+
<div id='login' style='text-align: center'>
30+
<form id='cred' name='cred'>
31+
<label for='jid'>JID:</label>
32+
<input type='text' class='leftinput' id='jid' />
33+
<label for='pass'>Password:</label>
34+
<input type='password' class='leftinput' id='pass' />
35+
<input type='submit' id='connect' value='connect' />
36+
</form>
37+
<br/>
38+
</div>
39+
<hr />
40+
<div id='disco'>
41+
</div>
42+
<hr />
43+
<div id='log_container'>
44+
<a href='#'>Status Log :</a>
45+
<div id='log'></div></div>
46+
</body>
47+
</html>

‎contrib/discojs/punjab.tac

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# punjab tac file
2+
from twisted.web import server, resource, static
3+
from twisted.application import service, internet
4+
5+
from punjab.httpb import Httpb, HttpbService
6+
7+
root = static.File("./") # This needs to be the directory
8+
# where you will have your html
9+
# and javascript.
10+
11+
b = resource.IResource(HttpbService(1)) # turn on debug with 1
12+
root.putChild('bosh', b)
13+
14+
15+
site = server.Site(root)
16+
17+
application = service.Application("punjab")
18+
internet.TCPServer(5280, site).setServiceParent(application)

‎contrib/discojs/scripts/basic.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var BOSH_SERVICE = 'http://localhost:5280/bosh';
2+
3+
var connection = null;
4+
var browser = null;
5+
var show_log = true;
6+
7+
function log(msg)
8+
{
9+
$('#log').append('<div></div>').append(document.createTextNode(msg));
10+
}
11+
12+
13+
function rawInput(data)
14+
{
15+
log('RECV: ' + data);
16+
}
17+
18+
function rawOutput(data)
19+
{
20+
log('SENT: ' + data);
21+
}
22+
23+
function onConnect(status)
24+
{
25+
if (status == Strophe.Status.CONNECTING) {
26+
log('Strophe is connecting.');
27+
28+
} else if (status == Strophe.Status.CONNFAIL) {
29+
log('Strophe failed to connect.');
30+
showConnect();
31+
} else if (status == Strophe.Status.DISCONNECTING) {
32+
log('Strophe is disconnecting.');
33+
} else if (status == Strophe.Status.DISCONNECTED) {
34+
log('Strophe is disconnected.');
35+
showConnect();
36+
37+
} else if (status == Strophe.Status.CONNECTED) {
38+
log('Strophe is connected.');
39+
// Start up disco browser
40+
browser.showBrowser();
41+
}
42+
}
43+
44+
function showConnect()
45+
{
46+
var jid = $('#jid');
47+
var pass = $('#pass');
48+
var button = $('#connect').get(0);
49+
50+
browser.closeBrowser();
51+
52+
$('label').show();
53+
jid.show();
54+
pass.show();
55+
$('#anon').show();
56+
button.value = 'connect';
57+
return false;
58+
}
59+
60+
function showDisconnect()
61+
{
62+
var jid = $('#jid');
63+
var pass = $('#pass');
64+
var button = $('#connect').get(0);
65+
66+
button.value = 'disconnect';
67+
pass.hide();
68+
jid.hide();
69+
$('label').hide();
70+
$('#anon').hide();
71+
return false;
72+
}
73+
74+
$(document).ready(function () {
75+
connection = new Strophe.Connection(BOSH_SERVICE);
76+
connection.rawInput = rawInput;
77+
connection.rawOutput = rawOutput;
78+
79+
browser = new Disco();
80+
81+
$("#log_container").bind('click', function () {
82+
$("#log").toggle();
83+
}
84+
);
85+
86+
$('#cred').bind('submit', function () {
87+
var button = $('#connect').get(0);
88+
var jid = $('#jid');
89+
var pass = $('#pass');
90+
91+
if (button.value == 'connect') {
92+
showDisconnect();
93+
connection.connect(jid.get(0).value,
94+
pass.get(0).value,
95+
onConnect);
96+
} else {
97+
connection.disconnect();
98+
showConnect();
99+
}
100+
return false;
101+
});
102+
});

‎contrib/discojs/scripts/disco.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
var NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info';
3+
var NS_DISCO_ITEM = 'http://jabber.org/protocol/disco#items';
4+
5+
6+
// Disco stuff
7+
Disco = function () {
8+
// Class that does nothing
9+
};
10+
11+
Disco.prototype = {
12+
showBrowser: function() {
13+
// Browser Display
14+
var disco = $('#disco');
15+
var jid = $('#jid');
16+
var server = connection.jid.split('@')[1];
17+
18+
// display input box
19+
disco.append("<div id='server'><form id='browse' name='browse'>Server : <input type='text' name='server' id='server' value='"+server+"' /><input type='submit' value='browse'/></form></div>");
20+
21+
// add handler for search form
22+
$("#browse").bind('submit', function () {
23+
this.startBrowse($("#server").get(0).value);
24+
return false;
25+
});
26+
27+
this.startBrowse(server);
28+
},
29+
30+
closeBrowser: function() {
31+
var disco = $('#disco');
32+
33+
disco.empty();
34+
},
35+
36+
startBrowse: function(server) {
37+
// build iq request
38+
var id = 'startBrowse';
39+
40+
var discoiq = $iq({'from':connection.jid+"/"+connection.resource,
41+
'to':server,
42+
'id':id,
43+
'type':'get'}
44+
)
45+
.c('query', {'xmlns': NS_DISCO_INFO});
46+
47+
connection.addHandler(this._cbBrowse, null, 'iq', 'result', id);
48+
connection.send(discoiq.tree());
49+
50+
},
51+
52+
_cbBrowse: function(e) {
53+
var elem = $(e); // make this Element a JQuery Element
54+
alert(e);
55+
56+
return false; // return false to remove the handler
57+
},
58+
59+
};
60+

0 commit comments

Comments
 (0)