Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set delayed page-refreshes #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ But hotcode will fallback to a "dumb" reload of the iframe on file change when t

## Args

hotcode -p 8000 -u vhost.local -s
hotcode -p 8000 -u vhost.local -d 0 -s

* -p [int] , port, `8080`
* -h [str] , host, `vhost.local`
* -d [int] , refresh delay in milliseconds, `0`
* -s, silent, doesn't open a browser window on start

# Helper file (predefined paths for urls)
Expand Down
9 changes: 8 additions & 1 deletion lib/socket-io-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ var helperRules = [];
try {
helperRules = require(process.env.HOME+'/.hotcode');
} catch(e) {}
var delay = 0;

module.exports = function Server(expressInstance) {
if (expressInstance.delay != undefined) {
delay = expressInstance.delay;
}
var io = require('socket.io').listen(expressInstance, {
'log level': 0
});
Expand Down Expand Up @@ -92,7 +96,10 @@ function Watch(path) {
if (files.length == 1 && files[0].match(/\.monitor/)) {
// Do nothing because this is nodemon..
} else {
self.broadcast('reload', files[0]);
function reload() {
self.broadcast('reload', files[0])
}
setTimeout(reload, delay);
}
}
self.timeoutWatching = setTimeout(watching, 300);
Expand Down
5 changes: 4 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node
process.title = 'hotcode';

var argv = require('optimist').usage('Usage: $0 -p [num] -h [host.local] -s').argv;
var argv = require('optimist').usage('Usage: $0 -p [num] -h [host.local] -d [refresh_delay] -s')
.default('d', 0)
.argv;

process.addListener('uncaughtException', function (err, stack) {
console.log('Caught exception: '+err+'\n'+err.stack);
Expand All @@ -28,6 +30,7 @@ console.log('Inject js: '+host+'/static/injected.js');

var app = module.exports = express.createServer();
app.listen(port, null);
app.delay = argv.d;

// Setup socket.io server
var socketIo = new require('./lib/socket-io-server.js')(app);
Expand Down