Skip to content

Commit

Permalink
Slightly better hostname handling (for websockets)
Browse files Browse the repository at this point in the history
  • Loading branch information
fixme committed Feb 21, 2016
1 parent 1851ee9 commit 8d54452
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions led.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>LED controller</title>
<script src="/static/led.js" type="text/javascript"></script>
<script type="text/javascript">
document.addEventListener('click', function(event) {
var target = event.target;
if (target.tagName.toLowerCase() == 'a')
{
var hostname = target.getAttribute('href').match(/^:(\d+)(.*)/);
if (hostname)
{
target.hostname = window.location.href;
}
}
}, false);
</script>

<script type="text/javascript">
// Color wheel code
Expand Down Expand Up @@ -61,7 +48,7 @@
function init(colors) {
colors = colors;
if ("WebSocket" in window) {
ws = new WebSocket("ws://localhost:8000/ws");
ws = new WebSocket("ws://" + location.hostname + ":8000/ws");
ws.onopen = function() {
console.log("Connection is opened");
}
Expand All @@ -84,7 +71,7 @@
</script>
</head>
<body onload="init();">
<a href="/static/debug.html">Debug</a>
<a href="/static/debug.html">>Debug</a>
<div id="picker2"></div>
<div id="output">
<p id="display"></p>
Expand Down

0 comments on commit 8d54452

Please sign in to comment.