-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathxmpp.js
69 lines (57 loc) · 1.12 KB
/
xmpp.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
59
60
61
62
63
64
65
66
67
68
69
var xmpp = require('simple-xmpp')
, OTR = require('../index.js').OTR
, keys = require('./spec/unit/data/keys.js')
var from = ''
function err(err) {
console.log('err: ' + err)
}
function ui(msg) {
console.log('ui: ' + msg)
if (~msg.indexOf('hello')) {
otr.smpSecret('cryptocat')
}
}
function cb(msg) {
xmpp.send(from, msg)
}
function smp(type, data) {
switch (type) {
case 'question':
console.log(data)
otr.smpSecret('cryptocat')
break
case 'abort':
console.log('aborted')
break
case 'trust':
console.log('trust')
console.log(otr.trust)
break
}
}
var otr = new OTR({
fragment_size: 200
, send_interval: 200
, debug: true
, priv: keys.userA
})
otr.on('ui', ui)
otr.on('io', cb)
otr.on('error', err)
otr.on('smp', smp)
xmpp.on('online', function() {
console.log('Yes, I\'m connected!')
otr.sendQueryMsg()
})
xmpp.on('chat', function(from, message) {
otr.receiveMsg(message)
})
xmpp.on('error', function(err) {
console.error(err)
})
xmpp.connect({
jid : '',
password : '',
host : 'talk.google.com',
port : 5222
})