forked from finnp/gitter-irc-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitter.js
32 lines (22 loc) · 749 Bytes
/
gitter.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
var faye = require('faye')
module.exports = getClient
function getClient (token) {
// Authentication extension
var ClientAuthExt = function () {}
ClientAuthExt.prototype.outgoing = function (message, callback) {
if (message.channel === '/meta/handshake') {
if (!message.ext) { message.ext = {} }
message.ext.token = token
}
callback(message)
}
// faye client
var client = new faye.Client('https://ws.gitter.im/faye', {timeout: 60, retry: 5, interval: 1})
// Add Client Authentication extension
client.addExtension(new ClientAuthExt())
// keep alive, but we don't care about the answer
setInterval(function () {
client.publish('/api/v1/ping2', {reason: 'ping'})
}, 60000)
return client
}