Skip to content

Instantly share code, notes, and snippets.

@saneki
Last active August 29, 2015 14:16
Show Gist options
  • Save saneki/fff0a6707e5a2ab55675 to your computer and use it in GitHub Desktop.
Save saneki/fff0a6707e5a2ab55675 to your computer and use it in GitHub Desktop.
node-toxcore with file loading/saving
var toxcore = require('toxcore');
// Create a default Tox instance
var tox = new toxcore.Tox();
// Try to load our tox file
tox.loadFromFile('my.tox', function(err) {
if(!err) {
console.log('Loaded from file successfully');
} else {
console.log('Error loading from file (probably doesn\'t exist)');
}
// Bootstrap from nodes (see a list at: https://wiki.tox.im/Nodes)
tox.bootstrapFromAddressSync('23.226.230.47', 33445, 'A09162D68618E742FFBCA1C2C70385E6679604B2D80EA6E84AD0996A1AC8A074'); // stal
tox.bootstrapFromAddressSync('104.219.184.206', 443, '8CD087E31C67568103E8C2A28653337E90E6B8EDA0D765D57C6B5172B4F1F04C'); // Jfreegman
// Set your name and status message
tox.setNameSync('My username');
tox.setStatusMessageSync('Hello world!');
// Listen for friend requests
tox.on('friendRequest', function(e) {
console.log('Friend request from: ' + e.publicKeyHex());
});
// Print out your tox address so others can add it
console.log('Address: ' + tox.getAddressHexSync());
// Start!
tox.start();
});
// On SIGINT (Ctrl-C), save to file
process.on('SIGINT', function() {
tox.saveToFile('my.tox', function(err) {
if(!err) {
console.log('Saved to file successfully');
process.exit(0);
} else {
console.log('Error saving to file');
process.exit(1);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment