Commit 8fb90c59b72bd28a0c8a95f4978cd58aab599aec

Authored by Adhidarma Hadiwinoto
1 parent 58837c4957
Exists in master

onBuddy event

Showing 1 changed file with 14 additions and 1 deletions Side-by-side Diff

... ... @@ -4,6 +4,7 @@ var username;
4 4 var password;
5 5  
6 6 var callbacks;
  7 +var matrix;
7 8  
8 9 function onOnline(data) {
9 10 logger.info('XMPP login successful', {data: data});
... ... @@ -33,6 +34,10 @@ function onSubscribe(sender) {
33 34 xmpp.acceptSubscription(sender);
34 35 }
35 36  
  37 +function onBuddy(jid, state, statusText, resource) {
  38 + logger.verbose('Buddy state change', {jid: jid, state: state, statusText: statusText: statusText, resource: resource});
  39 +}
  40 +
36 41 function init(_username, _password, _logger, _callbacks) {
37 42 username = _username;
38 43 password = _password;
... ... @@ -42,7 +47,8 @@ function init(_username, _password, _logger, _callbacks) {
42 47 xmpp.on('online', onOnline);
43 48 xmpp.on('chat', onPM);
44 49 xmpp.on('error', onError);
45   - xmpp.on('subscribe', onSubscribe)
  50 + xmpp.on('subscribe', onSubscribe);
  51 + xmpp.on('buddy', onBuddy);
46 52  
47 53 xmpp.connect({
48 54 jid: username,
... ... @@ -50,6 +56,12 @@ function init(_username, _password, _logger, _callbacks) {
50 56 });
51 57 }
52 58  
  59 +function setOptions(options) {
  60 + if (options.matrix) {
  61 + matrix = options.matrix;
  62 + }
  63 +}
  64 +
53 65 function sendMessage(destination, msg) {
54 66 if (destination.toLowerCase() != username.replace(/\/.*/, '').toLowerCase()) {
55 67 logger.verbose('Sending message', {from: username, destination: destination, msg: msg});
... ... @@ -60,3 +72,4 @@ function sendMessage(destination, msg) {
60 72  
61 73 exports.init = init;
62 74 exports.sendMessage = sendMessage;
  75 +exports.setOptions = setOptions;