11'use strict' ;
22
3- var _assign = require ( 'babel-runtime/core-js/object/assign ' ) ;
3+ var _extends2 = require ( 'babel-runtime/helpers/extends ' ) ;
44
5- var _assign2 = _interopRequireDefault ( _assign ) ;
5+ var _extends3 = _interopRequireDefault ( _extends2 ) ;
66
77var _classCallCheck2 = require ( 'babel-runtime/helpers/classCallCheck' ) ;
88
@@ -16,21 +16,44 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1616
1717require ( 'colors' ) ;
1818var Pm2Socket = require ( './socket' ) ;
19- var getIp = require ( './getip' ) ;
2019module . exports = function ( ) {
20+ ( 0 , _createClass3 . default ) ( Pm2SocketIO , null , [ {
21+ key : 'getIp' ,
22+ value : function getIp ( ) {
23+ var os = require ( 'os' ) ;
24+ var interfaces = os . networkInterfaces ( ) ;
25+ module . exports = function ( ) {
26+ for ( var k in interfaces ) {
27+ for ( var k2 in interfaces [ k ] ) {
28+ var address = interfaces [ k ] [ k2 ] ;
29+ if ( address . family === 'IPv4' && ! address . internal ) {
30+ return address . address ;
31+ }
32+ }
33+ }
34+ return 'localhost' ;
35+ } ;
36+ }
37+ } , {
38+ key : 'getInstanceId' ,
39+ value : function getInstanceId ( ) {
40+ return parseInt ( process . env . NODE_APP_INSTANCE || 0 ) ;
41+ }
42+ } ] ) ;
43+
2144 function Pm2SocketIO ( opts ) {
2245 ( 0 , _classCallCheck3 . default ) ( this , Pm2SocketIO ) ;
2346
24- opts = ( 0 , _assign2 . default ) ( { } , {
47+ opts = ( 0 , _extends3 . default ) ( { } , {
2548 ips : [ ] ,
2649 localIp : 'localhost'
2750 } , opts ) ;
2851 this . addresses = opts . ips ;
2952 this . localIp = opts . localIp ;
30- this . instanceId = parseInt ( process . env . NODE_APP_INSTANCE || 0 ) ;
53+ this . instanceId = Pm2SocketIO . getInstanceId ( ) ;
3154 try {
3255 if ( opts . localIp != 'localhost' ) {
33- this . localIp = getIp ( ) ;
56+ this . localIp = Pm2SocketIO . getIp ( ) ;
3457 }
3558 if ( this . addresses . indexOf ( this . localIp ) == - 1 && this . addresses . length >= 2 ) {
3659 throw new Error ( '本机IP不在IP列表当中,请在第二个参数ips中添加' ) ;
0 commit comments