index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // var fs = require('fs'),
  2. // argv = require('optimist').argv
  3. var config = require('./readConfig');
  4. var Gun = require('gun')
  5. require('gun/sea')
  6. require('gun/lib/path')
  7. require('gun/lib/not')
  8. require('gun/nts')
  9. require('gun/lib/bye')
  10. config.readConfigFile();
  11. var conf = config.parseConfigOptions();
  12. var config = { port: conf.port };
  13. //create the server
  14. if (conf.ssl) {
  15. config.server = require('https').createServer(conf.sslOptions, Gun.serve(__dirname));
  16. } else {
  17. config.server = require('http').createServer(Gun.serve(__dirname));
  18. }
  19. global.gun = Gun({ web: config.server.listen(config.port), axe: false}); //until: 5000, chunk: 10
  20. console.log('Relay peer started on port ' + config.port + ' with /gun');
  21. let tickMsg = {
  22. parameters: [],
  23. time: 'tick'//hb
  24. };
  25. global.gun.get('server').get('heartbeat').get('tick').put(JSON.stringify(tickMsg));
  26. //instance.get('heartbeat').put({ tick: "{}" }).heartbeat(0.0, 1);
  27. setInterval(function () {
  28. let message = {
  29. parameters: "[]",
  30. time: 'tick', //hb
  31. sender: 'server'
  32. };
  33. global.gun.get('server').get('heartbeat').get('tick').put(message,function(ack){
  34. if(ack.err){
  35. console.log('ERROR: ' + ack.err)
  36. }});
  37. }, 50);