Created
February 23, 2018 01:34
-
-
Save andreloty/16a8a285e784a9c476c7db47f6239e6b to your computer and use it in GitHub Desktop.
layout.vash com script conectando com o socket.io
This file contains hidden or 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> | |
<title>@model.title</title> | |
<link rel='stylesheet' href='/stylesheets/style.css' /> | |
</head> | |
<body> | |
@html.block('content') | |
@if (process.env.NODE_ENV !== 'prodution') { | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var waitingToReconnect = false; | |
var socket = io(window.location.host); | |
socket.on('connect', function () { | |
if (waitingToReconnect) | |
location.reload(); | |
}); | |
socket.on('disconnect', function () { | |
waitingToReconnect = true; | |
}); | |
/** | |
* This code is more efficient, you can use this too instead of above. | |
* But it makes browser stop displaying page if the server goes down. | |
io(window.location.host).on('disconnect', function(){ | |
location.reload(); | |
});*/ | |
</script> | |
} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment