diff --git a/package.json b/package.json index 5381b9a9..8bf166f7 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@types/ws": "^7.4.0", "async": "^3.0.1", "buffer": "^6.0.3", + "net": "^1.0.2", "node-fetch": "^2.6.1", "process": "^0.11.10", "punycode": "^2.1.1", @@ -23,6 +24,7 @@ "readable-stream": "^2.3.6", "sdp": "^3.0.2", "stanza-shims": "^1.1.1", + "tls": "^0.0.1", "tslib": "^2.2.0", "ws": "^7.4.4" }, diff --git a/rollup.config.js b/rollup.config.js index c467bfcd..0a991356 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,6 +6,7 @@ export default { 'crypto', 'events', 'net', + 'tls', 'node-fetch', 'punycode', 'sdp', diff --git a/scripts/build.ts b/scripts/build.ts index 717179ec..4f590d2c 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -24,7 +24,12 @@ fileReplace('dist/es/Constants.js', '__STANZAJS_VERSION__', Pkg.version); Child('npm run compile:rollup'); -Child('mkdir dist/npm'); +if (!FS.existsSync("dist")) { + FS.mkdirSync("dist"); +} +if (!FS.existsSync("dist/npm")) { + FS.mkdirSync("dist/npm"); +} Child('cp -r dist/cjs/* dist/npm/'); Child('cp dist/es/index.module.js dist/npm/module.js'); Child(`cp ${__dirname}/../*.md dist/npm`); diff --git a/src/Client.ts b/src/Client.ts index 17e26f9c..c728aac0 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -104,8 +104,10 @@ export default class Client extends EventEmitter { this.transports = { bosh: BOSH, websocket: WebSocket, - tcp: TCP, }; + if (typeof window === 'undefined') { + this.transports.tcp = TCP; + } this.incomingDataQueue = priorityQueue(async (task, done) => { const { kind, stanza } = task; @@ -287,7 +289,7 @@ export default class Client extends EventEmitter { transports: { bosh: true, websocket: true, - tcp: true, + tcp: false, }, useStreamManagement: true, ...currConfig, @@ -351,7 +353,7 @@ export default class Client extends EventEmitter { let endpoints: { [key: string]: string[] } | undefined; for (const name of transportPref) { let conf = this.config.transports![name]; - if (!conf) { + if (!conf || !this.transports[name]) { continue; } if (typeof conf === 'string') { diff --git a/src/transports/tcp.ts b/src/transports/tcp.ts index 05dbbd4c..d6fd746c 100644 --- a/src/transports/tcp.ts +++ b/src/transports/tcp.ts @@ -124,7 +124,7 @@ export default class TCP extends Duplex implements Transport { public _read(): void { return; } - public disconnect(cleanly: boolean = true): void { + public disconnect(cleanly = true): void { if (cleanly) this.write(``); setTimeout(() => { this.hasStream = false; @@ -164,7 +164,7 @@ export default class TCP extends Duplex implements Transport { this.initParser(); this.tlssocket.on('secureConnect', () => this.openStream()); this.tlssocket.on('data', chunk => { - let data = chunk.toString('utf8'); + const data = chunk.toString('utf8'); this.client.emit('raw', 'incoming', data); this.parser!.write(data); }); diff --git a/webpack.config.js b/webpack.config.js index 3571ca5b..089a0cb4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,4 +23,4 @@ module.exports = { reportFilename: 'webpack-stats.html' }) ] -}; +}; \ No newline at end of file