websockets in faces3.php
This commit is contained in:
parent
510f7bd442
commit
44f8d68f50
2 changed files with 28 additions and 1 deletions
1
bin/socket_server.php
Normal file → Executable file
1
bin/socket_server.php
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
chdir(__DIR__);
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ EOSNIPPET;
|
|||
<head>
|
||||
<title>Emotion Hero</title>
|
||||
</head>
|
||||
<meta http-equiv="refresh" content="30" />
|
||||
<style type="text/css">
|
||||
|
||||
html{
|
||||
|
@ -414,5 +413,32 @@ EOSVG;
|
|||
echo "</div>"; // .currentHit
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var socket = new WebSocket("ws://<?php echo $_SERVER['SERVER_NAME']; ?>:8181");
|
||||
connection.onopen = function(){
|
||||
/*Send a small message to the console once the connection is established */
|
||||
console.log('Connection open!');
|
||||
};
|
||||
connection.onclose = function(){
|
||||
console.log('Connection closed');
|
||||
connection.connect()
|
||||
}
|
||||
connection.onerror = function(error){
|
||||
// reload page
|
||||
console.log('Error detected: ' + error);
|
||||
location.reload();
|
||||
}
|
||||
connection.onmessage = function(e){
|
||||
var message = JSON.parse(e.data);
|
||||
// var server_message = e.data;
|
||||
console.log(message);
|
||||
if(message['action'] == 'update') {
|
||||
if(message['method'] == 'image' || message['method'] == 'game') {
|
||||
// reload page
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue