text: /* ------------------------------------------------------------------
  * node-onvif - service-events.js
  *
  * Copyright (c) 2016 - 2017, Futomi Hatano, All rights reserved.
  * Released under the MIT license
  * Date: 2017-08-26
  * ---------------------------------------------------------------- */
  'use strict';
  const mUrl    = require('url');
  const mOnvifSoap = require('./soap.js');
  
  /* ------------------------------------------------------------------
  * Constructor: OnvifServiceEvents(params)
  * - params:
  *    - xaddr   : URL of the entry point for the media service
  *                (Required)
  *    - user  : User name (Optional)
  *    - pass  : Password (Optional)
  *    - time_diff: ms
  * ---------------------------------------------------------------- */
  function OnvifServiceEvents(params) {
  	this.xaddr = '';
  	this.user = '';
  	this.pass = '';
  
  	let err_msg = '';
  
  	if(err_msg = mOnvifSoap.isInvalidValue(params, 'object')) {
  		throw new Error('The value of "params" was invalid: ' + err_msg);
  	}
  
  	if('xaddr' in params) {
  		if(err_msg = mOnvifSoap.isInvalidValue(params['xaddr'], 'string')) {
  			throw new Error('The "xaddr" property was invalid: ' + err_msg);
  		} else {
  			this.xaddr = params['xaddr'];
  		}
  	} else {
  		throw new Error('The "xaddr" property is required.');
  	}
  
  	if('user' in params) {
  		if(err_msg = mOnvifSoap.isInvalidValue(params['user'], 'string', true)) {
  			throw new Error('The "user" property was invalid: ' + err_msg);
  		} else {
  			this.user = params['user'] || '';
  		}
  	}
  
  	if('pass' in params) {
  		if(err_msg = mOnvifSoap.isInvalidValue(params['pass'], 'string', true)) {
  			throw new Error('The "pass" property was invalid: ' + err_msg);
  		} else {
  			this.pass = params['pass'] || '';
  		}
  	}
  
  	this.oxaddr = mUrl.parse(this.xaddr);
  	if(this.user) {
  		this.oxaddr.auth = this.user + ':' + this.pass;
  	}
  
  	this.time_diff = params['time_diff'];
  	this.name_space_attr_list = [
  		'xmlns:wsa="http://www.w3.org/2005/08/addressing"',
  		'xmlns:tev="http://www.onvif.org/ver10/events/wsdl"'
  	];
  }
  
  OnvifServiceEvents.prototype._createRequestSoap = function(body) {
  	let soap = mOnvifSoap.createRequestSoap({
  		'body': body,
  		'xmlns': this.name_space_attr_list,
  		'diff': this.time_diff,
  		'user': this.user,
  		'pass': this.pass
  	});
  	return soap;
  };
  
  /* ------------------------------------------------------------------
  * Method: setAuth(user, pass)
  * ---------------------------------------------------------------- */
  OnvifServiceEvents.prototype.setAuth = function(user, pass) {
  	this.user = user || '';
  	this.pass = pass || '';
  	if(this.user) {
  		this.oxaddr.auth = this.user + ':' + this.pass;
  	} else {
  		this.oxaddr.auth = '';
  	}
  };
  
  /* ------------------------------------------------------------------
  * Method: getEventProperties([callback])
  * ---------------------------------------------------------------- */
  OnvifServiceEvents.prototype.getEventProperties = function(callback) {
  	let promise = new Promise((resolve, reject) => {
  		let soap_body = '';
  		soap_body += '<tev:GetEventProperties/>';
  		let soap = this._createRequestSoap(soap_body);
  		mOnvifSoap.requestCommand(this.oxaddr, 'GetEventProperties', soap).then((result) => {
  			resolve(result);
  		}).catch((error) => {
  			reject(error);
  		});
  	});
  	if(callback) {
  		promise.then((result) => {
  			callback(null, result);
  		}).catch((error) => {
  			callback(error);
  		});
  	} else {
  		return promise;
  	}
  };
  
  module.exports = OnvifServiceEvents;
  
  
  
  
  
  
  
  
  