Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Commit 18ca136

Browse files
committed
Inherit protocol and endpoint when not specified.
1 parent 534ba2c commit 18ca136

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Native/WebSocket.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
var _elm_lang$websocket$Native_WebSocket = function() {
22

3+
function getProtocol(){ return location.protocol.match(/^https/) ? "wss" : "ws" }
4+
5+
function getEndpointURL(uri)
6+
{
7+
if(uri.charAt(0) !== "/"){ return uri; }
8+
if(uri.charAt(1) === "/"){ return getProtocol() + ':' + uri; }
9+
10+
return getProtocol() + '://' + location.host + uri;
11+
}
12+
313
function open(url, settings)
414
{
515
return _elm_lang$core$Native_Scheduler.nativeBinding(function(callback)
616
{
717
try
818
{
9-
var socket = new WebSocket(url);
19+
var socket = new WebSocket(getEndpointURL(url));
1020
socket.elm_web_socket = true;
1121
}
1222
catch(err)

0 commit comments

Comments
 (0)