{"size": 2982, "ext": "js", "max_stars_repo_path": "lib/signaling/out-of-band/abstract.js", "max_stars_repo_name": "MicroMinion/1tp", "max_stars_repo_stars_event_min_datetime": "2016-06-08T20:12:32.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-27T18:40:53.000Z", "max_issues_repo_path": "lib/signaling/out-of-band/abstract.js", "max_issues_repo_name": "nicojanssens/1tp", "max_issues_repo_issues_event_min_datetime": "2016-06-17T18:46:35.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-03T11:05:06.000Z", "max_forks_repo_path": "lib/signaling/out-of-band/abstract.js", "max_forks_repo_name": "MicroMinion/1tp", "max_forks_repo_forks_event_min_datetime": "2016-08-10T23:30:17.000Z", "max_forks_repo_forks_event_max_datetime": "2017-02-02T00:23:25.000Z"}
{"max_stars_count": 8, "max_issues_count": 30, "max_forks_count": 3, "avg_line_length": 27.1090909091, "max_line_length": 109, "alphanum_fraction": 0.7401073105}
'use strict'

var events = require('events')
var myUtils = require('../../utils')
var Q = require('q')
var util = require('util')
var winston = require('winston-debug')
var winstonWrapper = require('winston-meta-wrapper')

function AbstractSignaling () {
  if (!(this instanceof AbstractSignaling)) {
    return new AbstractSignaling()
  }
  // logging
  this._log = winstonWrapper(winston)
  this._log.addMeta({
    module: '1tp:signaling:out-of-band'
  })
  // event emitter
  events.EventEmitter.call(this)
  // register _error handler
  myUtils.mixinEventEmitterErrorFunction(this)
}

// Inherit EventEmitter
util.inherits(AbstractSignaling, events.EventEmitter)

AbstractSignaling.prototype.register = function (callback, requestedRegistrationInfo, onSuccess, onFailure) {
  var notImplementedYetErrorMsg = 'AbstractSignaling.register function not implemented'
  this._log.error(notImplementedYetErrorMsg)
  this._error(notImplementedYetErrorMsg, onFailure)
}

AbstractSignaling.prototype.registerP = function (callback, requestedRegistrationInfo) {
  var deferred = Q.defer()
  this.register(
    callback,
    requestedRegistrationInfo,
    function (finalRegistrationInfo) {
      deferred.resolve(finalRegistrationInfo)
    },
    function (error) {
      deferred.reject(error)
    }
  )
  return deferred.promise
}

AbstractSignaling.prototype.deregister = function (registrationInfo, onSuccess, onFailure) {
  var notImplementedYetErrorMsg = 'AbstractSignaling.deregister function not implemented'
  this._log.error(notImplementedYetErrorMsg)
  this._error(notImplementedYetErrorMsg, onFailure)
}

AbstractSignaling.prototype.deregisterP = function (registrationInfo) {
  var deferred = Q.defer()
  this.deregister(
    registrationInfo,
    function () {
      deferred.resolve()
    },
    function (error) {
      deferred.reject(error)
    }
  )
  return deferred.promise
}

AbstractSignaling.prototype.send = function (message, destinationInfo, onSuccess, onFailure) {
  var notImplementedYetErrorMsg = 'AbstractSignaling.send function not implemented'
  this._log.error(notImplementedYetErrorMsg)
  this._error(notImplementedYetErrorMsg, onFailure)
}

AbstractSignaling.prototype.sendP = function (message, destinationInfo) {
  var deferred = Q.defer()
  this.send(
    message,
    destinationInfo,
    function () {
      deferred.resolve()
    },
    function (error) {
      deferred.reject(error)
    }
  )
  return deferred.promise
}

AbstractSignaling.prototype.close = function (onSuccess, onFailure) {
  var notImplementedYetErrorMsg = 'AbstractSignaling.close function not implemented'
  this._log.error(notImplementedYetErrorMsg)
  this._error(notImplementedYetErrorMsg, onFailure)
}

AbstractSignaling.prototype.closeP = function () {
  var deferred = Q.defer()
  this.close(
    function () {
      deferred.resolve()
    },
    function (error) {
      deferred.reject(error)
    }
  )
  return deferred.promise
}

module.exports = AbstractSignaling
