Last active
August 29, 2015 14:17
-
-
Save stenehall/c4a1127ef11c1713f9b1 to your computer and use it in GitHub Desktop.
Websockets on Safari ios 8.2 - Home screen not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<title>WebSocket Test</title> | |
<script language="javascript" type="text/javascript"> | |
var server = "<replace with your server - for example weechat.mydomain.tld>"; | |
var port = "<replace with your port - most likely 9001>"; | |
var password = "<replace with your passowrd>"; | |
var output; | |
var wsUri; | |
function init() { | |
output = document.getElementById("output"); | |
wsUri = "wss://echo.websocket.org" | |
testWebSocket(); | |
setTimeout(function() { | |
wsUri = "wss://"+server+":"+port+"/weechat" | |
testWebSocket(); | |
}, 5000); | |
} | |
function testWebSocket() { | |
websocket = new WebSocket(wsUri); | |
websocket.onopen = function(evt) { | |
onOpen(); | |
}; | |
websocket.onclose = function(evt) { | |
onClose() | |
}; | |
websocket.onmessage = function(evt) { | |
onMessage(evt); | |
}; | |
websocket.onerror = function(evt) { | |
onError(evt); | |
}; | |
} | |
function onOpen(evt) { | |
writeToScreen("CONNECTED TO: " + wsUri); | |
doSend("(1) init password="+password+"\n"); | |
doSend("(2) info version\n"); | |
} | |
function onClose(evt) { | |
writeToScreen("DISCONNECTED"); | |
} | |
function onMessage(evt) { | |
writeToScreen('<span style="color: blue;">RESPONSE: ' + wsUri + evt.data+'</span>'); | |
websocket.close(); | |
} | |
function onError(evt) { | |
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); | |
} | |
function doSend(message) { | |
writeToScreen("SENT: " + message); | |
websocket.send(message); | |
} | |
function writeToScreen(message) { | |
console.log(message); | |
var pre = document.createElement("p"); | |
pre.style.wordWrap = "break-word"; | |
pre.innerHTML = message; | |
output.appendChild(pre); | |
} | |
window.addEventListener("load", init, false); | |
</script> | |
</head> | |
<body> | |
<h2>WebSocket Test</h2> | |
<p>This will connect using a regulare browser or safari on iphone</p> | |
<p>Add this to your homescreen on your iphone and it will not work.</p> | |
<p>If you get a RESPONSE it means it works.</p> | |
<div id="output"></div> | |
</body> | |
</html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment