'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _printTools = require('../utils/print-tools');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

class SocketPublishCmd {
  constructor(context) {
    this.session = context.session;
    this.Socket = context.Socket;
  }

  run([socketName, cmd]) {
    var _this = this;

    return _asyncToGenerator(function* () {
      _this.Socket.publish(socketName, cmd.version).then(function (resp) {
        (0, _printTools.echo)();
        (0, _printTools.echo)(4)(`Socket ${_chalk2.default.cyan(socketName)} is now publicly available!`);
        (0, _printTools.echo)();
      }).catch(function (err) {
        if (err.response && err.response.data) {
          (0, _printTools.echo)();
          (0, _printTools.error)(4)(err.response.data.message);
          (0, _printTools.echo)();
        } else {
          (0, _printTools.echo)();
          (0, _printTools.error)(4)(err.message);
          (0, _printTools.echo)();
        }
      });
    })();
  }
}
exports.default = SocketPublishCmd;
module.exports = exports['default'];
//# sourceMappingURL=socket-publish.js.map