node-ipc/entities/Defaults.js

81 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-01-11 15:59:40 +11:00
'use strict';
2016-01-12 09:25:48 +11:00
/*eslint no-magic-numbers: ["error", { "ignore": [ 0] }]*/
/**
* @module entities
*/
2016-01-11 15:59:40 +11:00
const os = require('os');
/**
* @class Defaults
* @description Defaults Entity
*/
2016-01-11 15:59:40 +11:00
class Defaults{
/**
* @constructor
* @method constructor
* @return {void}
*/
2016-01-11 15:59:40 +11:00
constructor(){
this.appspace='app.';
this.socketRoot='/tmp/';
this.id=os.hostname();
this.encoding='utf8';
this.rawBuffer=false;
this.sync=false;
this.unlink=true;
2017-04-16 14:13:15 +10:00
this.delimiter='\f';
this.silent=false;
this.logDepth=5;
this.logInColor=true;
2017-06-26 11:22:16 +10:00
this.logger=console.log.bind(console);
this.maxConnections=100;
this.retry=500;
this.maxRetries=Infinity;
this.stopRetrying=false;
this.IPType=getIPType();
this.tls=false;
this.networkHost = (this.IPType == 'IPv6') ? '::1' : '127.0.0.1';
this.networkPort = 8000;
this.interface={
localAddress:false,
localPort:false,
family:false,
hints:false,
lookup:false
}
}
}
/**
* method to get ip type
*
* @method getIPType
* @return {string} ip type
*/
function getIPType() {
const networkInterfaces = os.networkInterfaces();
let IPType = '';
if (networkInterfaces
&& Array.isArray(networkInterfaces)
&& networkInterfaces.length > 0) {
// getting the family of first network interface available
IPType = networkInterfaces [
Object.keys( networkInterfaces )[0]
][0].family;
2016-01-11 15:59:40 +11:00
}
return IPType;
2016-01-11 15:59:40 +11:00
}
module.exports=Defaults;