Skip to content

Commit

Permalink
fix TCP transport for web
Browse files Browse the repository at this point in the history
  • Loading branch information
00drip committed Jun 7, 2021
1 parent 9be5fba commit 6490781
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"@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",
"react-native-randombytes": "^3.6.0",
"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"
},
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
'crypto',
'events',
'net',
'tls',
'node-fetch',
'punycode',
'sdp',
Expand Down
7 changes: 6 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
8 changes: 5 additions & 3 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StreamData>(async (task, done) => {
const { kind, stanza } = task;
Expand Down Expand Up @@ -287,7 +289,7 @@ export default class Client extends EventEmitter {
transports: {
bosh: true,
websocket: true,
tcp: true,
tcp: false,
},
useStreamManagement: true,
...currConfig,
Expand Down Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ module.exports = {
reportFilename: 'webpack-stats.html'
})
]
};
};

0 comments on commit 6490781

Please sign in to comment.