Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client-src/utils/createSocketURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function format(objURL) {
*/
function createSocketURL(parsedURL) {
let { hostname } = parsedURL;
let socketURLPort = parsedURL.port;

// Node.js module parses it as `::`
// `new URL(urlString, [baseURLString])` parses it as '[::]'
Expand All @@ -89,6 +90,9 @@ function createSocketURL(parsedURL) {
self.location.protocol.indexOf("http") === 0
) {
hostname = self.location.hostname;
// If we are using the location.hostname for the hostname, we should use the port from
// the location as well
socketURLPort = self.location.port;
}

let socketURLProtocol = parsedURL.protocol || self.location.protocol;
Expand Down Expand Up @@ -135,8 +139,6 @@ function createSocketURL(parsedURL) {
"localhost"
).replace(/^\[(.*)\]$/, "$1");

let socketURLPort = parsedURL.port;

if (!socketURLPort || socketURLPort === "0") {
socketURLPort = self.location.port;
}
Expand Down
10 changes: 10 additions & 0 deletions test/client/utils/createSocketURL.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ describe("'createSocketURL' function ", () => {
[null, "file:///home/user/project/index.html", "ws://localhost/ws"],
[null, "chrome-extension://localhost/", "ws://localhost/ws"],
[null, "file://localhost/", "ws://localhost/ws"],
[
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
"https://app.test.com",
"wss://app.test.com/ws",
],
[
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
"https://app.test.com:7777",
"wss://app.test.com:7777/ws",
],
];

samples.forEach(([__resourceQuery, location, expected]) => {
Expand Down