Skip to content

Commit 511ea98

Browse files
committed
strip port if not custom
1 parent 7607898 commit 511ea98

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

OpenFlow/src/public/WebSocketClient.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,31 @@ module openflow {
168168
}
169169
init() {
170170
this.getJSON("/config", async (error: any, data: any) => {
171-
if (location.protocol == 'https:' && data.wshost.startsWith("ws://")) {
172-
data.wshost = data.wshost.replace("ws://", "wss://");
171+
var parser = document.createElement('a');
172+
parser.href = data.wshost;
173+
parser.protocol; // => "http:"
174+
parser.hostname; // => "example.com"
175+
parser.port; // => "3000"
176+
parser.pathname; // => "/pathname/"
177+
parser.search; // => "?search=test"
178+
parser.hash; // => "#hash"
179+
parser.host; // => "example.com:3000"
180+
console.log(location.protocol);
181+
console.log(parser.protocol);
182+
console.log(data.wshost);
183+
if (location.protocol == 'https:' && data.wshost == "ws:") {
184+
data.wshost = "wss://" + parser.hostname;
185+
if (parser.port != "80") {
186+
data.wshost = "wss://" + parser.hostname + parser.port;
187+
}
173188
}
174-
if (location.protocol == 'http:' && data.wshost.startsWith("wss://")) {
175-
data.wshost = data.wshost.replace("wss://", "ws://");
189+
if (location.protocol == 'http:' && data.wshost == "wss:") {
190+
data.wshost = "ws://" + parser.hostname;
191+
if (parser.port != "443") {
192+
data.wshost = "ws://" + parser.hostname + parser.port;
193+
}
176194
}
195+
console.log(data.wshost);
177196
console.debug("WebSocketClient::onopen: connecting to " + data.wshost);
178197
this._socketObject = new ReconnectingWebSocket(data.wshost);
179198
this._socketObject.onopen = (this.onopen).bind(this);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.164
1+
0.0.165

0 commit comments

Comments
 (0)