websockets in faces3.php

This commit is contained in:
Ruben 2016-11-01 22:36:23 +01:00
parent 44f8d68f50
commit 36be41bafc
1 changed files with 6 additions and 5 deletions

View File

@ -415,20 +415,21 @@ echo "</div>"; // .currentHit
?>
<script type="text/javascript">
var socket = new WebSocket("ws://<?php echo $_SERVER['SERVER_NAME']; ?>:8181");
connection.onopen = function(){
socket.onopen = function(){
/*Send a small message to the console once the connection is established */
console.log('Connection open!');
};
connection.onclose = function(){
socket.onclose = function(){
console.log('Connection closed');
connection.connect()
location.reload();
// socket.connect()
}
connection.onerror = function(error){
socket.onerror = function(error){
// reload page
console.log('Error detected: ' + error);
location.reload();
}
connection.onmessage = function(e){
socket.onmessage = function(e){
var message = JSON.parse(e.data);
// var server_message = e.data;
console.log(message);