index.mjs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // const http = require('http');
  2. // const server = http.createServer();
  3. // const io = require('socket.io')(server,
  4. // {
  5. // cors: {
  6. // origin: "*"
  7. // }
  8. // }
  9. // );
  10. import * as http from 'http';
  11. import * as socket_io from 'socket.io';
  12. import {world_server} from './src/world-server.mjs';
  13. function Main() {
  14. const port = process.env.PORT || 3000;
  15. const server = http.createServer();
  16. const io = new socket_io.Server(server, {
  17. cors: {
  18. origin: '*'
  19. }
  20. });
  21. server.listen(port, () => {
  22. console.log('listening on: *', port);
  23. });
  24. const _WORLD = new world_server.WorldServer(io);
  25. _WORLD.Run();
  26. }
  27. Main();
  28. // app.all("/socket.io/*", function(req, res, next) {
  29. // res.header("Access-Control-Allow-Origin", "*");
  30. // res.header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
  31. // res.header("Access-Control-Allow-Methods", "GET, PUT, POST");
  32. // return next();
  33. // });
  34. // class Client {
  35. // constructor(socket) {
  36. // this.socket_ = socket;
  37. // this.SetupSocket_();
  38. // }
  39. // SetupSocket_() {
  40. // this.socket_.on('user-connected', () => {
  41. // console.log('socket.id: ' + socket.id);
  42. // // users.push({id: socket.id})
  43. // // io.emit('user-connected', socket.id)
  44. // });
  45. // this.socket_.on('disconnect', () => {
  46. // // const index = getIndex(socket.id)
  47. // // users.splice(1, index)
  48. // // io.emit('user-disconnected', socket.id)
  49. // });
  50. // }
  51. // };
  52. // class WorldServer {
  53. // constructor() {
  54. // this.SetupIO_();
  55. // }
  56. // SetupIO_() {
  57. // io.on('connection', socket => {
  58. // this.clients_[socket.id] = new Client(socket);
  59. // });
  60. // }
  61. // };
  62. // class World {
  63. // constructor() {
  64. // this.server_ = new WorldServer();
  65. // }
  66. // };
  67. // const _WORLD = new World();