Skip to content

Commit b0b50f5

Browse files
committed
add object-assign plugin
1 parent 065b4ab commit b0b50f5

File tree

4 files changed

+105
-41
lines changed

4 files changed

+105
-41
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"presets": ["es2015", "stage-2"],
3-
"plugins": ["transform-runtime"],
3+
"plugins": ["transform-runtime","transform-object-assign"],
44
"comments": false
55
}

.idea/workspace.xml

Lines changed: 73 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

master.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

77
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
88

@@ -16,21 +16,44 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1616

1717
require('colors');
1818
var Pm2Socket = require('./socket');
19-
var getIp = require('./getip');
2019
module.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中添加');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socketio-with-pm2",
3-
"version": "0.1.0",
3+
"version": "0.1.3",
44
"description": "This is an nodejs plugin for socketio, which support socketio run with the cluster mode of pm2",
55
"main": "index.js",
66
"scripts": {
@@ -19,6 +19,7 @@
1919
"homepage": "https://github.com/coderrorer/socketio-with-pm2#readme",
2020
"devDependencies": {
2121
"babel-cli": "^6.23.0",
22+
"babel-plugin-transform-object-assign": "^6.22.0",
2223
"babel-plugin-transform-runtime": "^6.23.0",
2324
"babel-preset-es2015": "^6.22.0",
2425
"babel-preset-stage-2": "^6.22.0"

0 commit comments

Comments
 (0)