Last active
August 29, 2015 13:58
-
-
Save lloydwatkin/9973366 to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<script type="text/javascript" | |
src="https://code.jquery.com/jquery-2.1.0.min.js"></script> | |
<script type="text/javascript" src="https://xmpp-ftw.jit.su/scripts/primus.js"></script> | |
</head> | |
<body> | |
<div id="container"> | |
<h1>Welcome to my XMPP-FTW project</h1> | |
<p>Please see <a href="https://github.com/xmpp-ftw/skeleton-project.git">github</a> for more information.</p> | |
<h2>Getting started</h2> | |
<p>To quickly get started perform the following actions:</p> | |
<pre> | |
git clone git@github.com:xmpp-ftw/skeleton-project.git | |
cd skeleton-project | |
npm i . | |
npm start & | |
open http://localhost:3000 | |
</pre> | |
<h2>Adding additional XMPP-FTW modules</h2> | |
<p>To use the additional module you wish to use do the following:</p> | |
<pre> | |
npm i --save xmpp-ftw-<project> | |
</pre> | |
<p>Then add the following call at <a href="https://github.com/xmpp-ftw/skeleton-project/blob/master/index.js#L48"><strong>line 48</strong> in <em>index.js</em></a>:</p> | |
<pre> | |
var Module = require('xmpp-ftw-<project>') | |
xmppFtw.addListener(new Module()) | |
</pre> | |
<h2>Example</h2> | |
<p>The code anonymously connects to <a href="http://buddycloud.com">Buddycloud.com</a> and pulls the latest 5 posts from the development channel.</p> | |
<p>Please see the <a href="https://github.com/xmpp-ftw/skeleton-project/blob/master/views/index.ejs">source of this file</a> for the code.</p> | |
<h3>Posts</h3> | |
<ul class="posts"><li><em>Will appear here</em></li></ul> | |
<p>...or see the real posts at the <a href="https://demo.buddycloud.org/team@topics.buddycloud.org">Buddycloud developer channel</a>.</p> | |
</div> | |
<script type="text/javascript"> | |
$(window.document).ready(function() { | |
var socket = new Primus('https://xmpp-ftw.jit.su') | |
socket.on('error', function(error) { console.error(error) }) | |
var handleItems = function(error, items) { | |
if (error) return console.error(error) | |
$('ul.posts').empty() | |
var content | |
items.forEach(function(item) { | |
content = '<li>' | |
content += item.entry.atom.content.content | |
content += '<br/> by ' | |
content += item.entry.atom.author.name | |
content += '</li>' | |
$('ul.posts').append(content) | |
}) | |
} | |
var getNodeItems = function() { | |
socket.send( | |
'xmpp.buddycloud.retrieve', | |
{ node: '/user/team@topics.buddycloud.org/posts', rsm: { max: 5 } }, | |
handleItems | |
) | |
} | |
var discoverBuddycloudServer = function() { | |
socket.send( | |
'xmpp.buddycloud.discover', | |
{ server: 'channels.buddycloud.org' }, | |
function(error, data) { | |
if (error) return console.error(error) | |
console.log('Discovered Buddycloud server at', data) | |
getNodeItems() | |
} | |
) | |
} | |
var login = function() { | |
socket.send( | |
'xmpp.login.anonymous', | |
{ jid: '@anon.buddycloud.org' } | |
) | |
socket.on('xmpp.connection', function(data) { | |
console.log('Connected as', data.jid) | |
discoverBuddycloudServer() | |
}) | |
} | |
socket.on('open', function() { | |
console.log('Connected') | |
login() | |
}) | |
socket.on('timeout', function(reason) { | |
console.error('Connection failed: ' + reason) | |
}) | |
socket.on('end', function() { | |
console.log('Socket connection closed') | |
socket = null | |
}) | |
socket.on('xmpp.error', function(error) { | |
console.error('XMPP-FTW error', error) | |
}) | |
socket.on('xmpp.error.client', function(error) { | |
console.error('XMPP-FTW client error', error) | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment