examples/bin/old/promises-example.js
function(callback) {
  tox.on('friendRequest', function(evt) {
    console.log('Accepting friend request from ' + evt.publicKeyHex());
    // Automatically accept the request
    tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
      console.log('Successfully accepted the friend request!');
    }).catch(function(err) {
      console.error('Couldn\'t accept the friend request:', err);
    });
  });

  tox.on('friendMessage', function(evt) {
    console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
    // Echo message back to friend
    tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
      console.log('Echoed message back to friend, received receipt ' + receipt);
    }).catch(function(err) {
      console.error('Couldn\'t echo message back to friend:', err);
    });
  });

  // Setup friendMessage callback to listen for groupchat invite requests
  tox.on('friendMessage', function(evt) {
    if(evt.message() === 'invite text') {
      tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the text groupchat');
      });
    } else if(evt.message() === 'invite av') {
      tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
      });
    }
  });

  callback();
}
function(callback) {
  tox.on('friendRequest', function(evt) {
    console.log('Accepting friend request from ' + evt.publicKeyHex());
    // Automatically accept the request
    tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
      console.log('Successfully accepted the friend request!');
    }).catch(function(err) {
      console.error('Couldn\'t accept the friend request:', err);
    });
  });

  tox.on('friendMessage', function(evt) {
    console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
    // Echo message back to friend
    tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
      console.log('Echoed message back to friend, received receipt ' + receipt);
    }).catch(function(err) {
      console.error('Couldn\'t echo message back to friend:', err);
    });
  });

  // Setup friendMessage callback to listen for groupchat invite requests
  tox.on('friendMessage', function(evt) {
    if(evt.message() === 'invite text') {
      tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the text groupchat');
      });
    } else if(evt.message() === 'invite av') {
      tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
      });
    }
  });

  callback();
}
function ( callback ) { tox . on ( 'friendRequest' , function ( evt ) { console . log ( 'Accepting friend request from ' + evt . publicKeyHex ( ) ) ; // Automatically accept the request tox . addFriendNoRequestAsync ( evt . publicKey ( ) ) . then ( function ( ) { console . log ( 'Successfully accepted the friend request!' ) ; } ) . catch ( function ( err ) { console . error ( 'Couldn\'t accept the friend request:' , err ) ; } ) ; } ) ; tox . on ( 'friendMessage' , function ( evt ) { console . log ( 'Message from friend ' + evt . friend ( ) + ': ' + evt . message ( ) ) ; // Echo message back to friend tox . sendMessageAsync ( evt . friend ( ) , evt . message ( ) ) . then ( function ( receipt ) { console . log ( 'Echoed message back to friend, received receipt ' + receipt ) ; } ) . catch ( function ( err ) { console . error ( 'Couldn\'t echo message back to friend:' , err ) ; } ) ; } ) ; // Setup friendMessage callback to listen for groupchat invite requests tox . on ( 'friendMessage' , function ( evt ) { if ( evt . message ( ) === 'invite text' ) { tox . inviteAsync ( evt . friend ( ) , groupchats [ 'text' ] ) . then ( function ( ) { console . log ( 'Invited ' + evt . friend ( ) + ' to the text groupchat' ) ; } ) ; } else if ( evt . message ( ) === 'invite av' ) { tox . inviteAsync ( evt . friend ( ) , groupchats [ 'av' ] ) . then ( function ( ) { console . log ( 'Invited ' + evt . friend ( ) + ' to the audio/video groupchat' ) ; } ) ; } } ) ; callback ( ) ; }
Initialize our callbacks, listening for friend requests and messages.
Initialize our callbacks listening for friend requests and messages .