-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.js
69 lines (67 loc) · 2.28 KB
/
test.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 oscar = require('./oscar');
var aim = new oscar.OscarConnection({
connection: {
username: 'xxxxxx',
password: 'xxxxxx'
}
});
aim.on('typing', function(who, type) {
if (type === oscar.TYPING_NOTIFY.START)
type = 'started typing';
else if (type === oscar.TYPING_NOTIFY.FINISH)
type = 'finished typing';
else if (type === oscar.TYPING_NOTIFY.TEXT_ENTERED)
type = 'entered text';
else
type = 'closed the IM';
console.log('test.js :: typing notification: ' + who + ' ' + type);
});
aim.on('im', function(text, sender, flags, when) {
console.log('test.js :: received ' + (when ? 'offline ' : '')
+ 'IM from ' + sender.name + (when ? ' (on ' + when + ')' : '')
+ ': ' + text);
if (when)
return;
aim.sendIM(sender.name, 'I got your IM!');
});
aim.on('missed', function(sender, numMissed, reason, channel) {
console.log('test.js :: missed ' + numMissed + ' messages from ' + sender.name
+ '. Reason: ' + reason + '. Channel: ' + channel);
});
aim.on('contactonline', function(user) {
var status = 'other';
if (user.idleMins)
status = 'idle (' + user.idleMins + ' mins)';
else if (user.status === oscar.USER_STATUSES.ONLINE)
status = 'available';
else if (user.status === oscar.USER_STATUSES.AWAY)
status = 'away';
console.log('test.js :: ' + user.name + ' is now online and ' + status
+ (user.statusMsg ? ': ' + user.statusMsg : ''));
});
aim.on('contactupdate', function(user) {
var status = 'other';
if (user.idleMins)
status = 'idle (' + user.idleMins + ' mins)';
else if (user.status === oscar.USER_STATUSES.ONLINE)
status = 'available';
else if (user.status === oscar.USER_STATUSES.AWAY)
status = 'away';
console.log('test.js :: ' + user.name + ' is now ' + status
+ (user.statusMsg ? ': ' + user.statusMsg : ''));
});
aim.on('contactoffline', function(user) {
console.log('test.js :: ' + user.name + ' is now offline');
});
aim.on('icon', function(who, icon, size) {
console.log('test.js :: Got ' + size + ' buddy icon for ' + who);
});
aim.connect(function(err) {
if (err)
console.log('test.js :: Encountered error: ' + err);
else {
console.log('test.js :: ready!');
// automatically check for offline messages
aim.getOfflineMsgs();
}
});