Jaxel
Member
Is it possible to get a minimal example of code with websockets? I don't need Scoreboard Primer but without buying it is difficult to understand how to add websockets in my own script.
HTML:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
var websocket;
var socketUrl = 'ws://localhost:58341';
$(document).ready(function() {
websocket = new WebSocket(socketUrl);
websocket.onopen = function() {
}
websocket.onclose = function() {
$('#message').append('<blockquote>Failed to connect to ' + socketUrl + '</blockquote>');
}
websocket.onmessage = function(message) {
console.log('Recieving data... ' + socketUrl);
data = JSON.parse(message.data);
$('#message').append(data.tabID + ' (' + data.time + ')<blockquote>' + message.data + '</blockquote>');
};
});
</script>
</head>
<div id="message"></div>