Skip to content

Commit

Permalink
added code shine for ruby commander viewer HTML Push example.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlb committed May 9, 2012
1 parent dfd3951 commit 50ca892
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
9 changes: 3 additions & 6 deletions ruby/commander/commander.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
## Send Message (PUBLISH) ## Send Message (PUBLISH)
## ---------------------- ## ----------------------
while 1 while 1
puts('Sending a message with publish() To Content Viewer') puts('Sending a HTML via PUBNUB...')
info = pubnub.publish({ pubnub.publish({
'channel' => 'content_commander', 'channel' => 'content_commander',
'message' => { 'message' => "Current Time: <h1>" + Time.now.inspect + "</h1>"
'name' => 'arb_html',
'data' => "Current Time: <h1>" + Time.now.inspect + "</h1>"
}
}) })
sleep(1.0) sleep(1.0)
end end
Expand Down
28 changes: 7 additions & 21 deletions ruby/commander/viewer.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h3>
<div data-role="content" id="viewer_box" class="box left"> <div data-role="content" id="viewer_box" class="box left">
<div id="content"></div> <div id="content"></div>
</div><!-- /content #viewer_box" --> </div><!-- /content #viewer_box" -->
</div> </div>


<!-- JQUERY --> <!-- JQUERY -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
Expand All @@ -26,28 +26,14 @@ <h3>
<div sub-key="a71204b3-ca89-11df-ba32-cfcef4a2b967" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div> <div sub-key="a71204b3-ca89-11df-ba32-cfcef4a2b967" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
<script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script> <script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script>
<script>(function(){ <script>(function(){
$(document).data('uuid', (((1+Math.random())*0x10000)|0).toString(16).substring(1));

PUBNUB.events.bind('arb_html', function(html) {
$("#content").remove();
$("#viewer_box").append("<div id='content'>"+ html + "</div>");
});


PUBNUB.subscribe({ PUBNUB.subscribe({
channel : "content_commander", channel : "content_commander",
restore : false, restore : false,
callback : function(message) { callback : function(html) {
if (message.name) { $("#content").remove();
PUBNUB.events.fire(message.name, message.data); $("#viewer_box").append("<div id='content'>"+ html + "</div>");
} },
},
disconnect : function() {
console.log("Connection Lost.");
},
reconnect : function() {
console.log("And we're Back!");
}

}); });


})();</script> })();</script>
Expand Down

0 comments on commit 50ca892

Please sign in to comment.