// Generated by CoffeeScript 1.6.3
(function() {
  var Call, Client, Emitter, socketio,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  Emitter = require('emitter');

  socketio = io;

  Call = require('./Call');

  Client = (function(_super) {
    __extends(Client, _super);

    function Client(options) {
      var _this = this;
      this.options = options != null ? options : {};
      this.io = socketio.connect(this.options.host, this.options.socketio);
      this.io.on('reconnect', function() {
        return _this.emit('reconnect');
      });
      this.io.on('disconnect', function() {
        return _this.emit('disconnect');
      });
      this.io.on('error', function(err) {
        return _this.emit('error', err);
      });
      this.io.on('callRequest', function(callInfo) {
        var call;
        call = new Call(_this, callInfo.id, callInfo.caller);
        return _this.emit("call", call);
      });
      this.io.on('presenceChange', function(user, status) {
        return _this.emit('presence', user, status);
      });
    }

    Client.prototype.createCall = function(cb) {
      var _this = this;
      this.io.emit('createCall', function(err, id) {
        var call;
        if (err != null) {
          return cb(err);
        }
        call = new Call(_this, id);
        return cb(null, call);
      });
      return this;
    };

    Client.prototype.register = function(name, cb) {
      return this.io.emit('register', name, cb);
    };

    Client.prototype.unregister = function(cb) {
      return this.io.emit('unregister', cb);
    };

    return Client;

  })(Emitter);

  module.exports = Client;

}).call(this);
