Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ruby example with content commander to push HTML content on dem…
…and.
- Loading branch information
Showing
3 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require '../lib/pubnub' | ||
|
||
## ----------------------------------------- | ||
## SETUP API KEYS | ||
## ----------------------------------------- | ||
publish_key = "09e02e4d-5508-44fb-a615-8da69289b73c" | ||
subscribe_key = "a71204b3-ca89-11df-ba32-cfcef4a2b967" | ||
secret_key = "" | ||
|
||
## ----------------------------------------- | ||
## Create Pubnub Client API (INITIALIZATION) | ||
## ----------------------------------------- | ||
pubnub = Pubnub.new( publish_key, subscribe_key, secret_key, false ) | ||
|
||
## ---------------------- | ||
## Send Message (PUBLISH) | ||
## ---------------------- | ||
while 1 | ||
puts('Sending a message with publish() To Content Viewer') | ||
info = pubnub.publish({ | ||
'channel' => 'content_commander', | ||
'message' => { | ||
'name' => 'arb_html', | ||
'data' => "Current Time: <h1>" + Time.now.inspect + "</h1>" | ||
} | ||
}) | ||
sleep(1.0) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Content Commander </title> | ||
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> | ||
</head> | ||
<body> | ||
<div data-role="page" id="main"> | ||
<div data-theme="a" data-role="header"> | ||
<h3> | ||
Content Commander - Viewer | ||
</h3> | ||
</div><!-- /header --> | ||
<div data-role="content" id="viewer_box" class="box left"> | ||
<div id="content"></div> | ||
</div><!-- /content #viewer_box" --> | ||
</div> | ||
|
||
<!-- JQUERY --> | ||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> | ||
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> | ||
|
||
<!-- PUBNUB --> | ||
<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>(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({ | ||
channel : "content_commander", | ||
restore : false, | ||
callback : function(message) { | ||
if (message.name) { | ||
PUBNUB.events.fire(message.name, message.data); | ||
} | ||
}, | ||
disconnect : function() { | ||
console.log("Connection Lost."); | ||
}, | ||
reconnect : function() { | ||
console.log("And we're Back!"); | ||
} | ||
|
||
}); | ||
|
||
})();</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters