Skip to content

Commit

Permalink
Added ability to refresh current page & redirect to new url if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpshr committed Dec 30, 2012
1 parent 005b03f commit 8433d3e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
18 changes: 16 additions & 2 deletions README.md
@@ -1,15 +1,15 @@
[Holler.js](http://bitpshr.info/holler)
=================

real-time, in-app notifications for web and mobile via the command line. [see it in action](http://bitpshr.info/holler)
real-time, in-app notifications and admin for web and mobile via the command line. [see it in action](http://bitpshr.info/holler)

##Usage
Sending notifications with Holler is as easy as four steps:

###1. Install a module
Holler is built with <a href="http://nodejs.org/">Node</a> and is distributed as an <a href="http://npmjs.org">npm</a> module. If you don't have Node yet, <a href="http://nodejs.org/">install the hell out of it</a>. Next we just install holler:
```console
npm install holler
npm install holler -g
```

###2. Add a script tag
Expand Down Expand Up @@ -53,6 +53,20 @@ holler http://yourServerUrl:port success "This is a success message."
holler http://yourServerUrl:port error "This is an error message."
```

* Refresh Page

Now you can use holler to perform admin tasks such as refreshing the current page. Again, all users using the app will have their page refreshed in real-time.
```console
holler http://yourServerUrl:port refresh
```

* Error Messages

You can also redirect the current page to a new url. Again, all users using the app will have their page redirected in real-time.
```console
holler http://yourServerUrl:port redirect http://someOtherUrl
```

##Going forward
I definitely need to address the following:

Expand Down
10 changes: 5 additions & 5 deletions bin/holler
Expand Up @@ -6,8 +6,8 @@
//

// make sure we have the right number of options
if(process.argv.length!=5){
console.error("usage: node holler.js [url] [type] [message]");
if(process.argv.length<4){
console.error("usage: holler [url:port] [type] [message|redirectUrl]?");
process.exit();
}

Expand All @@ -19,16 +19,16 @@ var faye = require('faye'),
url = p.substring(p.length-1) == "/" ? p.substring(0,p.length-1) : p;

// validate notification type
if(type!="log" && type!="success" && type!="error"){
console.error("uh oh: [type] must be one of [log, success, error]");
if(type!="log" && type!="success" && type!="error" && type!="refresh" && type!="redirect"){
console.error("uh oh: [type] must be one of [log, success, error, refresh, redirect]");
process.exit();
}

// create a regular old client just like a browser would
var client = new faye.Client(url+'/faye');
var notification = client.publish('/holler', {
type: type,
message: process.argv[4]
message: type != "refresh" ? process.argv[4] : null
});

// when done, kill this sucker
Expand Down
2 changes: 1 addition & 1 deletion bin/holler-server
Expand Up @@ -7,7 +7,7 @@

// make sure we have only one arg
if(process.argv.length>3){
console.error("usage: node holler-server.js [port]");
console.error("usage: holler-server [port]");
process.exit();
}

Expand Down
24 changes: 19 additions & 5 deletions demo/index.html
Expand Up @@ -4,7 +4,7 @@
<meta lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="real-time, in-app notifications for web and mobile via the command line">
<meta name="description" content="real-time, in-app notifications and admin for web and mobile via the command line">
<meta name="author" content="Paul Bouchon">
<title>holler.js</title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
Expand All @@ -20,7 +20,7 @@
<div class="container-fluid top">
<div class="jumbotron">
<h1>Holler.js</h1>
<p class="lead">real-time, in-app notifications for web and mobile via the command line</p>
<p class="lead">real-time, in-app notifications and admin for web and mobile via the command line</p>
<div class="container-really-narrow hidden-phone">
<iframe src="http://player.vimeo.com/video/55747016?badge=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen ></iframe>
</div>
Expand Down Expand Up @@ -79,8 +79,11 @@ <h1 class="sectionTitle"><span class="accent">3.</span> Start a server</h1>
<div class="container-narrow">
<h1 class="sectionTitle"><span class="accent">4.</span> Holler stuff</h1>
<p>
Show notifications to <strong>all users currently using your app in real-time</strong> using <code>holler.js</code>. Notifications use <a href="http://fabien-d.github.com/alertify.js/">Alertify</a> so they look nice and sexy. <a href="https://vimeo.com/55747016">See it in action</a>.
Show notifications to <strong>all users currently using your app in real-time</strong> using <code>holler</code>. You can also refresh the current page, or redirect to a new url. Notifications use <a href="http://fabien-d.github.com/alertify.js/">Alertify</a> so they look nice and sexy. <a href="https://vimeo.com/55747016">See it in action</a>.
</p>
<p>
<span class="label label-info">Try this!</span> Open up multiple browser windows all pointing to your test page. All windows should receive the notification in real-time.
</p>
<p>
<h3>Log Messages</h3>
<img src="css/img/log.png" class="sample"/>
Expand All @@ -96,8 +99,19 @@ <h3>Error Messages</h3>
<img src="css/img/error.png" class="sample"/>
<pre>holler http://yourServerUrl:port error "This is an error message."</pre>
</p>
<p>
<span class="label label-success">Try this!</span> Open up multiple browser windows all pointing to your test page. All windows should receive the notification in real-time.
<p>
<h3>Refresh Page</h3>
<p>
<span class="label label-success">New!</span> Now you can use holler to perform admin tasks such as refreshing the current page. Again, all users using the app will have their page refreshed in real-time.
</p>
<pre>holler http://yourServerUrl:port refresh</pre>
</p>
<p>
<h3>Redirect to URL</h3>
<p>
<span class="label label-success">New!</span> You can also redirect the current page to a new url. Again, all users using the app will have their page redirected in real-time.
</p>
<pre>holler http://yourServerUrl:port redirect http://someOtherUrl</pre>
</p>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion dist/holler-client.concat.js
Expand Up @@ -517,7 +517,13 @@
});
// subscribe to notification channel
var subscription = client.subscribe('/holler',function(obj) {
alertify.log(obj.message, obj.type);
if(obj.type=="redirect"){
window.location = obj.message;
}else if(obj.type=="refresh"){
window.location.reload(true);
}else{
alertify.log(obj.message, obj.type);
}
});
});

Expand Down
2 changes: 1 addition & 1 deletion dist/holler-client.min.js

Large diffs are not rendered by default.

150 changes: 0 additions & 150 deletions npm-debug.log

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
@@ -1,8 +1,8 @@
{
"name": "holler",
"version": "1.0.7",
"version": "1.0.8",
"author": "Paul Bouchon (@bitpshr)",
"description": "real-time, in-app notifications for web and mobile via the command line",
"description": "real-time, in-app notifications and admin for web and mobile via the command line",
"homepage": "http://bitpshr.info/holler",
"keywords": [
"notifications",
Expand Down
8 changes: 7 additions & 1 deletion src/holler-client.js
Expand Up @@ -44,7 +44,13 @@
});
// subscribe to notification channel
var subscription = client.subscribe('/holler',function(obj) {
alertify.log(obj.message, obj.type);
if(obj.type=="redirect"){
window.location = obj.message;
}else if(obj.type=="refresh"){
window.location.reload(true);
}else{
alertify.log(obj.message, obj.type);
}
});
});

Expand Down

0 comments on commit 8433d3e

Please sign in to comment.