'use strict'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _socket = _interopRequireDefault(require("socket.io")); var ServerToolListner = /*#__PURE__*/function () { function ServerToolListner(server) { (0, _classCallCheck2.default)(this, ServerToolListner); this.server = server; } (0, _createClass2.default)(ServerToolListner, [{ key: "listen", value: function listen(port) { var server = this.server; this.serverTool = _socket.default.listen(port); this.serverTool.on('connection', function (socket) { console.log('tool connected'); socket.on('players', function (option, callback) { callback(server.getCurrentListAuthorizedPlayers()); socket.disconnect(false); }); socket.on('syncdb', /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(option, callback) { var response; return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return server.updatePlayersFromDb(); case 2: response = _context.sent; callback(response); socket.disconnect(false); case 5: case "end": return _context.stop(); } } }, _callee); })); return function (_x, _x2) { return _ref.apply(this, arguments); }; }()); socket.on('add-player', /*#__PURE__*/function () { var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(username, callback) { var response; return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return server.addPlayerDb.apply(server, (0, _toConsumableArray2.default)(username)); case 2: response = _context2.sent; callback(response); socket.disconnect(false); case 5: case "end": return _context2.stop(); } } }, _callee2); })); return function (_x3, _x4) { return _ref2.apply(this, arguments); }; }()); socket.on('remove-player', /*#__PURE__*/function () { var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(username, callback) { var response; return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return server.removePlayerDb.apply(server, (0, _toConsumableArray2.default)(username)); case 2: response = _context3.sent; callback(response); socket.disconnect(false); case 5: case "end": return _context3.stop(); } } }, _callee3); })); return function (_x5, _x6) { return _ref3.apply(this, arguments); }; }()); socket.on('add-game', /*#__PURE__*/function () { var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(game, callback) { var response; return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: response = ''; _context4.prev = 1; _context4.next = 4; return server.addGameDb.apply(server, (0, _toConsumableArray2.default)(game)); case 4: response = _context4.sent; response = 'OK - inserted at id :' + response; _context4.next = 11; break; case 8: _context4.prev = 8; _context4.t0 = _context4["catch"](1); response = 'KO ' + _context4.t0.message; case 11: callback(JSON.stringify(response)); socket.disconnect(false); case 13: case "end": return _context4.stop(); } } }, _callee4, null, [[1, 8]]); })); return function (_x7, _x8) { return _ref4.apply(this, arguments); }; }()); socket.on('remove-game', /*#__PURE__*/function () { var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(options, callback) { var response; return _regenerator.default.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return server.removeGameDb.apply(server, (0, _toConsumableArray2.default)(options)); case 2: response = _context5.sent; callback(response); socket.disconnect(false); case 5: case "end": return _context5.stop(); } } }, _callee5); })); return function (_x9, _x10) { return _ref5.apply(this, arguments); }; }()); }); } }]); return ServerToolListner; }(); exports.default = ServerToolListner; //# sourceMappingURL=server-tool-listener.js.map