diff --git a/package.json b/package.json index 0d36ee9332083ec98c79c1ff0325d4821fcd88bf..22054268f2e248502cb53621264298369f5332c9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "DEFAULT_PUPPET": "web", "DEFAULT_PROFILE": "profile", "DEFAULT_PORT": 8788, - "DEFAULT_PUPPET_PORT": 18788, "DEFAULT_PROTOCOL": "io|0.0.1", "DEFAULT_TOKEN": "WECHATY_IO_TOKEN", "DEFAULT_APIHOST": "api.wechaty.io", diff --git a/src/config.spec.js b/src/config.spec.js index 5010a4b8f69415e8e0e33204a35fc98cb633be06..f5659486b47c63ca0267d2634e1c69ecc8c087d4 100644 --- a/src/config.spec.js +++ b/src/config.spec.js @@ -16,7 +16,6 @@ test('Config list vars', t => { t.truthy(Config.DEFAULT_PORT , 'should export DEFAULT_PORT') t.truthy(Config.DEFAULT_PROFILE , 'should export DEFAULT_PROFILE') t.truthy(Config.DEFAULT_HEAD , 'should export DEFAULT_HEAD') - t.truthy(Config.DEFAULT_PUPPET_PORT , 'should export DEFAULT_PUPPET_PORT') t.truthy(Config.DEFAULT_PROTOCOL , 'should export DEFAULT_PROTOCOL') t.truthy(Config.DEFAULT_APIHOST , 'should export DEFAULT_APIHOST') t.truthy(Config.CMD_CHROMIUM , 'should export CMD_CHROMIUM') diff --git a/src/puppet-web/puppet-web.js b/src/puppet-web/puppet-web.js index fcd3d10a3d5806cdfcae8580a246035a160eb8af..e1b5697c488604f654a940e4f1c584e6443c0682 100644 --- a/src/puppet-web/puppet-web.js +++ b/src/puppet-web/puppet-web.js @@ -36,6 +36,8 @@ const Watchdog = require('./watchdog') const UtilLib = require('../util-lib') const Config = require('../config') +const DEFAULT_PUPPET_PORT = 18788 // // W(87) X(88), ascii char code ;-] + class PuppetWeb extends Puppet { constructor({ head = Config.head @@ -62,7 +64,7 @@ class PuppetWeb extends Puppet { return co.call(this, function* () { - this.port = yield UtilLib.getPort(Config.DEFAULT_PUPPET_PORT) + this.port = yield UtilLib.getPort(DEFAULT_PUPPET_PORT) log.verbose('PuppetWeb', 'init() getPort %d', this.port) yield this.initAttach(this) diff --git a/src/puppet-web/server.js b/src/puppet-web/server.js index a05c8ad719e373eb4ced978d12aa2f2e8403ba2d..9e5f48883405602d6c815742cea09052138742c0 100644 --- a/src/puppet-web/server.js +++ b/src/puppet-web/server.js @@ -23,9 +23,14 @@ const EventEmitter = require('events') class Server extends EventEmitter { constructor({ - port = Config.DEFAULT_PUPPET_PORT // W(87) X(88), ascii char code ;-] - } = {}) { + port + }) { super() + + if (!port) { + throw new Error('port not found') + } + this.port = port } diff --git a/test/wechaty.spec.js b/test/wechaty.spec.js index 5e51cf0d6c76de3f74cd3f3ecbd906065c3e7693..bda9d1f0d9c82aef1c08d71715112eb6c1ad67b5 100644 --- a/test/wechaty.spec.js +++ b/test/wechaty.spec.js @@ -26,5 +26,4 @@ test('Wechaty Config setting', t => { t.truthy(Config.DEFAULT_HEAD , 'should has DEFAULT_HEAD') t.truthy(Config.DEFAULT_PUPPET , 'should has DEFAULT_PUPPET') t.truthy(Config.DEFAULT_PORT , 'should has DEFAULT_PORT') - t.truthy(Config.DEFAULT_PUPPET_PORT, 'should has DEFAULT_PUPPET_PORT') })