Permalink
Browse files

app: refresh on deployment

  • Loading branch information...
indutny committed Feb 15, 2012
1 parent 0b7a3a9 commit 8c8e685269201341aa5e116c682fb6f786447b6c
Showing with 22 additions and 5 deletions.
  1. +3 −1 app.js
  2. +2 −1 home/realtime.js
  3. +9 −0 public/javascripts/main.js
  4. +6 −1 routes/index.js
  5. +2 −2 views/index.jade
View
4 app.js
@@ -3,7 +3,8 @@
* Module dependencies.
*/
-var sticky = require('sticky-session'),
+var package = require('./package'),
+ sticky = require('sticky-session'),
os = require('os'),
express = require('express'),
io = require('socket.io'),
@@ -40,6 +41,7 @@ sticky(function() {
// App-Specific stuff
require('./home/realtime').init(io, {
+ version: package.version,
redis: {
port: +process.env['DB-MAIN-PORT'] || 6379,
host: +process.env['DB-MAIN-HOST'] || 'localhost',
View
@@ -61,6 +61,7 @@ PMap.prototype.remove = function remove() {
function GuysPool(io, options) {
process.EventEmitter.call(this);
+ this.version = options.version;
this.id = ~~(Math.random() * 1e9);
this.io = io;
this.options = options;
@@ -245,7 +246,7 @@ GuysPool.prototype.manageIo = function manageIo(io) {
var self = this;
io.sockets.on('connection', function(socket) {
- var bulk = [];
+ var bulk = [ ['version', self.version] ];
self.pool.forEach(function(guy) {
self.notifyEnter(guy, bulk);
});
@@ -400,11 +400,20 @@
ghostsMap[guy.id].stopSaying();
};
+ var serverVersion;
socket.on('bulk', function(bulk) {
bulk.forEach(function(msg) {
var type = msg[0],
data = msg[1];
+ if (type === 'version') {
+ if (serverVersion === undefined) {
+ serverVersion = data;
+ } else if (serverVersion != data) {
+ // Update was deployed
+ location.reload(true);
+ }
+ }
if (type === 'enter') return onGuyEnter(data);
if (type === 'leave') return onGuyLeave(data);
if (type === 'mode') return onGuyMode(data);
View
@@ -1,8 +1,13 @@
+var package = require('../package');
/*
* GET home page.
*/
exports.index = function(req, res){
- res.render('index', { title: 'Fedor Indutny', layout: null })
+ res.render('index', {
+ title: 'Fedor Indutny',
+ layout: null,
+ version: package.version
+ });
};
View
@@ -2,7 +2,7 @@
html
head
title= title
- link(rel='stylesheet', href='/stylesheets/style.css')
+ link(rel='stylesheet', href='/stylesheets/style.css?v=' + version)
body
section#content-wrap
section#content
@@ -25,5 +25,5 @@ html
script(src='/javascripts/paper.js')
script(src='/socket.io/socket.io.js')
- script(src='/javascripts/main.js')
+ script(src='/javascripts/main.js?v=' + version)
script var _gaq =_gaq||[];_gaq.push(['_setAccount', 'UA-29169083-1']);_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();

0 comments on commit 8c8e685

Please sign in to comment.