-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (50 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var express = require('express')
, Emitter = require('primus-emitter')
, Primus = require('primus')
, engine = require('ejs-locals')
, xmpp = require('xmpp-ftw')
, Buddycloud = require('xmpp-ftw-buddycloud')
var app = express()
app.get('/', function(req, res){
res.render('index')
})
var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port)
})
app.configure(function() {
app.use(express.static(__dirname + '/public'))
app.set('views', __dirname + '/views')
app.set('view engine', 'ejs')
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.logger)
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}))
app.engine('ejs', engine)
})
var options = {
transformer: 'socket.io',
parser: 'JSON',
transports: [
'websocket',
'htmlfile',
'xhr-polling',
'jsonp-polling'
],
global: 'Buddycloud'
}
var primus = new Primus(server, options)
primus.use('emitter', Emitter)
primus.save(__dirname + '/public/scripts/buddycloud.js')
primus.on('connection', function(socket) {
console.log('Websocket connection made')
var xmppFtw = new xmpp.Xmpp(socket)
xmppFtw.addListener(new Buddycloud())
socket.xmppFtw = xmppFtw
})
primus.on('disconnection', function(socket) {
console.log('Client disconnected, logging them out')
socket.xmppFtw.logout()
})