index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. sender: 'server'
  25. };
  26. global.gun.get('server').get('heartbeat').get('tick').put(tickMsg);
  27. //instance.get('heartbeat').put({ tick: "{}" }).heartbeat(0.0, 1);
  28. setInterval(function () {
  29. let message = {
  30. parameters: "[]",
  31. time: 'tick', //hb
  32. sender: 'server'
  33. };
  34. global.gun.get('server').get('heartbeat').get('tick').put(message,function(ack){
  35. if(ack.err){
  36. console.log('ERROR: ' + ack.err)
  37. }});
  38. }, 50);