Skip to content

Instantly share code, notes, and snippets.

@andreloty
Created February 23, 2018 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreloty/16a8a285e784a9c476c7db47f6239e6b to your computer and use it in GitHub Desktop.
Save andreloty/16a8a285e784a9c476c7db47f6239e6b to your computer and use it in GitHub Desktop.
layout.vash com script conectando com o socket.io
<!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