Source: node_modules/kurento-client-core/lib/abstracts/SdpEndpoint.js

/* Autogenerated with Kurento Idl */

/*
 * (C) Copyright 2013-2015 Kurento (http://kurento.org/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var inherits = require('inherits');

var kurentoClient = require('kurento-client');

var disguise = kurentoClient.disguise;

var checkType      = kurentoClient.checkType;
var ChecktypeError = checkType.ChecktypeError;


var Transaction = kurentoClient.TransactionsManager.Transaction;

var SessionEndpoint = require('./SessionEndpoint');


function noop(error, result) {
  if (error) console.trace(error);

  return result
};


/**
 * @classdesc
 *  This interface is implemented by Endpoints that require an SDP negotiation 
 *  for the setup of a networked media session with remote peers. The API 
 *  provides the following functionality:
 *        <ul>
 *          <li>Generate SDP offers.</li>
 *          <li>Process SDP offers.</li>
 *          <li>Configure SDP related params.</li>
 *        </ul>
 *
 * @abstract
 * @extends module:core/abstracts.SessionEndpoint
 *
 * @constructor module:core/abstracts.SdpEndpoint
 */
function SdpEndpoint(){
  SdpEndpoint.super_.call(this);
};
inherits(SdpEndpoint, SessionEndpoint);


//
// Public properties
//

/**
 *  Maximum bandwidth for audio reception, in kbps. The default value is 500. A 
 *  value of 0 sets this as leaves this unconstrained. <hr/><b>Note</b> This has
 *
 * @alias module:core/abstracts.SdpEndpoint#getMaxAudioRecvBandwidth
 *
 * @param {module:core/abstracts.SdpEndpoint~getMaxAudioRecvBandwidthCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.getMaxAudioRecvBandwidth = function(callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  var usePromise = false;
  
  if (callback == undefined) {
    usePromise = true;
  }
  
  if(!arguments.length) callback = undefined;

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'getMaxAudioRecvBandwidth', callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~getMaxAudioRecvBandwidthCallback
 * @param {external:Error} error
 * @param {external:Integer} result
 */

/**
 *  Maximum bandwidth for audio reception, in kbps. The default value is 500. A 
 *  value of 0 sets this as leaves this unconstrained. <hr/><b>Note</b> This has
 *
 * @alias module:core/abstracts.SdpEndpoint#setMaxAudioRecvBandwidth
 *
 * @param {external:Integer} maxAudioRecvBandwidth
 * @param {module:core/abstracts.SdpEndpoint~setMaxAudioRecvBandwidthCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.setMaxAudioRecvBandwidth = function(maxAudioRecvBandwidth, callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  checkType('int', 'maxAudioRecvBandwidth', maxAudioRecvBandwidth, {required: true});

  var params = {
    maxAudioRecvBandwidth: maxAudioRecvBandwidth
  };

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'setMaxAudioRecvBandwidth', params, callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~setMaxAudioRecvBandwidthCallback
 * @param {external:Error} error
 */

/**
 *  Maximum bandwidth for video reception, in kbps. The default value is 500. A 
 *  value of 0 sets this as unconstrained. <hr/><b>Note</b> This has to be set 
 *  before the SDP is generated.
 *
 * @alias module:core/abstracts.SdpEndpoint#getMaxVideoRecvBandwidth
 *
 * @param {module:core/abstracts.SdpEndpoint~getMaxVideoRecvBandwidthCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.getMaxVideoRecvBandwidth = function(callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  var usePromise = false;
  
  if (callback == undefined) {
    usePromise = true;
  }
  
  if(!arguments.length) callback = undefined;

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'getMaxVideoRecvBandwidth', callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~getMaxVideoRecvBandwidthCallback
 * @param {external:Error} error
 * @param {external:Integer} result
 */

/**
 *  Maximum bandwidth for video reception, in kbps. The default value is 500. A 
 *  value of 0 sets this as unconstrained. <hr/><b>Note</b> This has to be set 
 *  before the SDP is generated.
 *
 * @alias module:core/abstracts.SdpEndpoint#setMaxVideoRecvBandwidth
 *
 * @param {external:Integer} maxVideoRecvBandwidth
 * @param {module:core/abstracts.SdpEndpoint~setMaxVideoRecvBandwidthCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.setMaxVideoRecvBandwidth = function(maxVideoRecvBandwidth, callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  checkType('int', 'maxVideoRecvBandwidth', maxVideoRecvBandwidth, {required: true});

  var params = {
    maxVideoRecvBandwidth: maxVideoRecvBandwidth
  };

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'setMaxVideoRecvBandwidth', params, callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~setMaxVideoRecvBandwidthCallback
 * @param {external:Error} error
 */


//
// Public methods
//

/**
 *  Generates an SDP offer with  media capabilities of the Endpoint.
 *           Exceptions
 *           <ul>
 *             <li>
 *               SDP_END_POINT_ALREADY_NEGOTIATED If the endpoint is already 
 *               negotiated.
 *             </li>
 *             <li>
 *               SDP_END_POINT_GENERATE_OFFER_ERROR if the generated offer is 
 *               empty. This is most likely due to an internal error.
 *             </li>
 *           </ul>
 *
 * @alias module:core/abstracts.SdpEndpoint.generateOffer
 *
 * @param {module:core/abstracts.SdpEndpoint~generateOfferCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.generateOffer = function(callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  var usePromise = false;
  
  if (callback == undefined) {
    usePromise = true;
  }
  
  if(!arguments.length) callback = undefined;

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'generateOffer', callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~generateOfferCallback
 * @param {external:Error} error
 * @param {external:String} result
 *  The SDP offer.
 */

/**
 * This method returns the local SDP. The output depends on the negotiation 
 * stage:
 *           <ul>
 *             <li>
 *               No offer has been generated: returns null.
 *             </li>
 *             <li>
 *               Offer has been generated: return the SDP offer.
 *             </li>
 *             <li>
 *               Offer has been generated and answer processed: retruns the 
 *               agreed SDP.
 *             </li>
 *           </ul>
 *
 * @alias module:core/abstracts.SdpEndpoint.getLocalSessionDescriptor
 *
 * @param {module:core/abstracts.SdpEndpoint~getLocalSessionDescriptorCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.getLocalSessionDescriptor = function(callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  var usePromise = false;
  
  if (callback == undefined) {
    usePromise = true;
  }
  
  if(!arguments.length) callback = undefined;

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'getLocalSessionDescriptor', callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~getLocalSessionDescriptorCallback
 * @param {external:Error} error
 * @param {external:String} result
 *  The last agreed SessionSpec
 */

/**
 * This method returns the remote SDP. If the negotiation process is not 
 * complete, it will return NULL.
 *
 * @alias module:core/abstracts.SdpEndpoint.getRemoteSessionDescriptor
 *
 * @param {module:core/abstracts.SdpEndpoint~getRemoteSessionDescriptorCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.getRemoteSessionDescriptor = function(callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  var usePromise = false;
  
  if (callback == undefined) {
    usePromise = true;
  }
  
  if(!arguments.length) callback = undefined;

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'getRemoteSessionDescriptor', callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~getRemoteSessionDescriptorCallback
 * @param {external:Error} error
 * @param {external:String} result
 *  The last agreed User Agent session description
 */

/**
 *  Generates an SDP offer with  media capabilities of the Endpoint.
 *           Exceptions
 *           <ul>
 *             <li>
 *               SDP_PARSE_ERROR If the offer is empty or has errors.
 *             </li>
 *             <li>
 *               SDP_END_POINT_ALREADY_NEGOTIATED If the endpoint is already 
 *               negotiated.
 *             </li>
 *             <li>
 *               SDP_END_POINT_PROCESS_ANSWER_ERROR if the result of processing 
 *               the answer is an empty string. This is most likely due to an 
 *               internal error.
 *             </li>
 *             <li>
 *               SDP_END_POINT_NOT_OFFER_GENERATED If the method is invoked 
 *               before the generateOffer method.
 *             </li>
 *           </ul>
 *
 * @alias module:core/abstracts.SdpEndpoint.processAnswer
 *
 * @param {external:String} answer
 *  SessionSpec answer from the remote User Agent
 *
 * @param {module:core/abstracts.SdpEndpoint~processAnswerCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.processAnswer = function(answer, callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  checkType('String', 'answer', answer, {required: true});

  var params = {
    answer: answer
  };

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'processAnswer', params, callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~processAnswerCallback
 * @param {external:Error} error
 * @param {external:String} result
 *  Updated SDP offer, based on the answer received.
 */

/**
 *  Processes SDP offer of the remote peer, and generates an SDP answer based on
 *           Exceptions
 *           <ul>
 *             <li>
 *               SDP_PARSE_ERROR If the offer is empty or has errors.
 *             </li>
 *             <li>
 *               SDP_END_POINT_ALREADY_NEGOTIATED If the endpoint is already 
 *               negotiated.
 *             </li>
 *             <li>
 *               SDP_END_POINT_PROCESS_OFFER_ERROR if the generated offer is 
 *               empty. This is most likely due to an internal error.
 *             </li>
 *           </ul>
 *
 * @alias module:core/abstracts.SdpEndpoint.processOffer
 *
 * @param {external:String} offer
 *  SessionSpec offer from the remote User Agent
 *
 * @param {module:core/abstracts.SdpEndpoint~processOfferCallback} [callback]
 *
 * @return {external:Promise}
 */
SdpEndpoint.prototype.processOffer = function(offer, callback){
  var transaction = (arguments[0] instanceof Transaction)
                  ? Array.prototype.shift.apply(arguments)
                  : undefined;

  checkType('String', 'offer', offer, {required: true});

  var params = {
    offer: offer
  };

  callback = (callback || noop).bind(this)

  return disguise(this._invoke(transaction, 'processOffer', params, callback), this)
};
/**
 * @callback module:core/abstracts.SdpEndpoint~processOfferCallback
 * @param {external:Error} error
 * @param {external:String} result
 *  The chosen configuration from the ones stated in the SDP offer
 */


/**
 * @alias module:core/abstracts.SdpEndpoint.constructorParams
 */
SdpEndpoint.constructorParams = {
};

/**
 * @alias module:core/abstracts.SdpEndpoint.events
 *
 * @extends module:core/abstracts.SessionEndpoint.events
 */
SdpEndpoint.events = SessionEndpoint.events;


/**
 * Checker for {@link module:core/abstracts.SdpEndpoint}
 *
 * @memberof module:core/abstracts
 *
 * @param {external:String} key
 * @param {module:core/abstracts.SdpEndpoint} value
 */
function checkSdpEndpoint(key, value)
{
  if(!(value instanceof SdpEndpoint))
    throw ChecktypeError(key, SdpEndpoint, value);
};


module.exports = SdpEndpoint;

SdpEndpoint.check = checkSdpEndpoint;