Initial support for TLS.

RLGWebD now serves via encrypted connections on port 8081.

The client-side script now uses secure WebSockets if the page is being
accessed via HTTPS.
This commit is contained in:
John "Elwin" Edwards 2017-01-01 20:18:01 -05:00
parent 2baaad79dd
commit 37bd2e8c28
2 changed files with 31 additions and 4 deletions

View file

@ -396,7 +396,10 @@ function wsCurrent() {
}
if (statsock)
return;
statsock = new WebSocket("ws://" + window.location.host + "/status");
var wsproto = "ws://";
if (window.location.protocol == "https:")
wsproto = "wss://";
statsock = new WebSocket(wsproto + window.location.host + "/status");
statsock.onmessage = function (ev) {
var msg;
try {
@ -618,7 +621,10 @@ function startgame(game) {
if (!window.WebSocket) {
return;
}
var sockurl = "ws://" + window.location.host + "/play/" + game.uname;
var wsproto = "ws://";
if (window.location.protocol == "https:")
wsproto = "wss://";
var sockurl = wsproto + window.location.host + "/play/" + game.uname;
sockurl += "?key=" + sessionStorage.getItem("lcred") + "&w=80&h=24";
ws = new WebSocket(sockurl);
ws.onopen = function (event) {
@ -653,7 +659,10 @@ function makeWatcher(t) {
function startwatching(tag) {
if (session.connect)
return;
var sockurl = "ws://" + window.location.host + "/watch/" + tag;
var wsproto = "ws://";
if (window.location.protocol == "https:")
wsproto = "wss://";
var sockurl = wsproto + window.location.host + "/watch/" + tag;
var ws = new WebSocket(sockurl);
ws.onopen = function (event) {
session.connect = true;