Created
August 4, 2009 02:01
-
-
Save julien51/160982 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script language='javascript' src='http://code.stanziq.com/svn/strophe/trunk/strophejs/b64.js'></script> | |
<script language='javascript' src='http://code.stanziq.com/svn/strophe/trunk/strophejs/md5.js'></script> | |
<script language='javascript' src='http://code.stanziq.com/svn/strophe/trunk/strophejs/sha1.js'></script> | |
<script language='javascript' src='http://code.stanziq.com/svn/strophe/trunk/strophejs/strophe.js'></script> | |
<script language='javascript'> | |
<!-- | |
function log(msg) { | |
// $('#log').prepend('<div></div><br /><br />').prepend(document.createTextNode(msg)); | |
} | |
function rawInput(data) { | |
log('RECV: ' + data); | |
} | |
function rawOutput(data) { | |
log('SENT: ' + data); | |
} | |
function onMessage(msg) { | |
var event = msg.getElementsByTagName("event")[0]; | |
if(event) { | |
var string = (new XMLSerializer()).serializeToString(msg).replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;').replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');; | |
$('#console').prepend("<pre class='sh_xml'>"+ string + "</pre>"); | |
var currentTime = new Date(); | |
var hours = currentTime.getHours(); | |
var minutes = currentTime.getMinutes(); | |
var seconds = currentTime.getSeconds(); | |
if (minutes < 10) { | |
minutes = "0" + minutes | |
} | |
if (seconds < 10) { | |
seconds = "0" + seconds | |
} | |
$('#console').prepend("<h2>"+ hours + ":" + minutes + ":" + seconds + "</h2>"); | |
sh_highlightDocument(); | |
} | |
return true; | |
} | |
function onConnect(status) { | |
if (status == Strophe.Status.CONNECTED) { | |
$('#unconnected').hide(); | |
$('#connected').show(); | |
con.send($pres().c("priority").t(5).tree()); | |
con.send($pres({to: jid}).c("priority").t(5).tree()); | |
alert("You are now connected, please wait...") | |
} else if (status == Strophe.Status.DISCONNECTED) { | |
$('#console').prepend("<h2>You've been disconnected. Please reload the page and reconnect</h2>"); | |
} else if (status == Strophe.Status.AUTHFAIL) { | |
$('#console').prepend("<h2>Password error. Please reload the page.</h2>"); | |
} | |
return true; | |
} | |
var con = new Strophe.Connection('http://superfeedr.com/http-bind/'); | |
con.rawInput = rawInput; | |
con.rawOutput = rawOutput; | |
con.addHandler(onMessage, null, 'message', null, null, null); | |
$('#connect').bind('click', function () { | |
var button = $('#connect').get(0); | |
if (button.value == 'Connect') { | |
$('#connect').attr("disabled", "disabled"); // To disable | |
jid = "[email protected]"; | |
password = $('#pass').get(0).value; | |
con.connect(jid, password, onConnect); | |
} else { | |
$('#connect').attr("disabled", "disabled"); // To disable | |
$('#connect').attr("value","Connecting..."); | |
con.disconnect(); | |
} | |
}); | |
$('#publish').click(function() { | |
$.post('http://superfeedr.com/hubbub/ping', {item: this.id}, function() { | |
alert('New entry published. The notification should arrive very soon.') | |
}); | |
}); | |
// Start Doc highlighting | |
// --> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment