text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var core_1 = require("@angular/core");
  var Observable_1 = require("rxjs/Observable");
  require("rxjs/add/operator/share");
  var io = require("socket.io-client");
  var socket_io_module_1 = require("./socket-io.module");
  var WrappedSocket = /** @class */ (function () {
      function WrappedSocket(config) {
          this.subscribersCounter = 0;
          var url = config.url || '';
          var options = config.options || {};
          this.ioSocket = io(url, options);
      }
      WrappedSocket.prototype.on = function (eventName, callback) {
          this.ioSocket.on(eventName, callback);
      };
      WrappedSocket.prototype.once = function (eventName, callback) {
          this.ioSocket.once(eventName, callback);
      };
      WrappedSocket.prototype.connect = function () {
          return this.ioSocket.connect();
      };
      WrappedSocket.prototype.disconnect = function (close) {
          return this.ioSocket.disconnect.apply(this.ioSocket, arguments);
      };
      WrappedSocket.prototype.emit = function (eventName, data, callback) {
          return this.ioSocket.emit.apply(this.ioSocket, arguments);
      };
      WrappedSocket.prototype.removeListener = function (eventName, callback) {
          return this.ioSocket.removeListener.apply(this.ioSocket, arguments);
      };
      WrappedSocket.prototype.removeAllListeners = function (eventName) {
          return this.ioSocket.removeAllListeners.apply(this.ioSocket, arguments);
      };
      /** create an Observable from an event */
      WrappedSocket.prototype.fromEvent = function (eventName) {
          var _this = this;
          this.subscribersCounter++;
          return Observable_1.Observable.create(function (observer) {
              _this.ioSocket.on(eventName, function (data) {
                  observer.next(data);
              });
              return function () {
                  if (_this.subscribersCounter === 1)
                      _this.ioSocket.removeListener(eventName);
              };
          }).share();
      };
      /* Creates a Promise for a one-time event */
      WrappedSocket.prototype.fromEventOnce = function (eventName) {
          var _this = this;
          return new Promise(function (resolve) { return _this.once(eventName, resolve); });
      };
      /** @nocollapse */
      WrappedSocket.ctorParameters = function () { return [
          { type: undefined, decorators: [{ type: core_1.Inject, args: [socket_io_module_1.SOCKET_CONFIG_TOKEN,] },] },
      ]; };
      return WrappedSocket;
  }());
  exports.WrappedSocket = WrappedSocket;
  //# sourceMappingURL=socket-io.service.js.map