Skip to content
Browse files

Update examples and Rakefile

  • Loading branch information...
1 parent a6341fe commit 20829f760125aca701160db19bbf162332c39a56 @glejeune glejeune committed
Showing with 93 additions and 51 deletions.
  1. +27 −6 README.rdoc
  2. +1 −0 Rakefile
  3. +9 −8 examples/chart/chart-cometd.rb
  4. +8 −9 examples/soapbox/soapbox-cometd.rb
  5. +48 −28 examples/soapbox/static/soapbox.rhtml
View
33 README.rdoc
@@ -1,7 +1,5 @@
= rcomet
-* FIX (url)
-
== DESCRIPTION:
RComet is an implementation of the Bayeux protocol in Ruby.
@@ -9,17 +7,40 @@ Bayeux Protocol : http://svn.cometd.org/trunk/bayeux/bayeux.html
== FEATURES/PROBLEMS:
-RComet use webrick but it would use eventmachine
+* RComet does not work with Thin !
+* It was tested only with Dojo
== SYNOPSIS:
- FIX (code sample of usage)
+ require 'rcomet'
+
+ # We create a new RComer server
+ server = RComet::Server.new( :host => '0.0.0.0', :port => 8990, :server => :mongrel, :mount => '/' ) {
+ # We create a new channel (/graph) with a callback to manipulate recieved data
+ channel['/graph'].callback do |data|
+ # Someone have send data on channel /graph
+ # We push the data to the same channel
+ # We don't need to do this... But it's an example
+ channel['/graph'].data( data )
+ end
+ }
+
+ # Let's start the server
+ server.start
+
+ # Then we start for a infinity loop
+ while true
+ # We push new data to the channel /graph every 5 second
+ server.channel['/graph'].data( [rand(10),rand(10),rand(10),rand(10),rand(10),rand(10),rand(10),rand(10)] )
+ sleep(5)
+ end
+
+See <tt>examples</tt>...
== REQUIREMENTS:
* json
-* Capcode for example
-* Dojo Framework for example
+* rack
== INSTALL:
View
1 Rakefile
@@ -11,6 +11,7 @@ begin
gem.homepage = "http://github.com/glejeune/rcomet"
gem.authors = ["Guillaume Dorchies", "Grégoire Lejeune"]
gem.add_development_dependency "rspec", ">= 1.2.9"
+ gem.add_dependency('rack')
gem.bindir = "bin"
gem.executables = ["rcomet"]
gem.rubyforge_project = 'rcomet'
View
17 examples/chart/chart-cometd.rb
@@ -1,14 +1,15 @@
$:.unshift( "../../lib" )
require 'rcomet'
-server = RComet::Server.new( :host => '0.0.0.0', :port => 8990, :server => :mongrel, :mount => '/' )
-server.channel['/graph'] = [1,1,2,2,3,3,4,4]
-server.channel['/graph'].callback do |data|
- puts "someone send "
- p data
- puts 'on channel /graph'
- server.channel['/graph'].data( data )
-end
+server = RComet::Server.new( :host => '0.0.0.0', :port => 8990, :server => :mongrel, :mount => '/' ) {
+ channel['/graph'] = [1,1,2,2,3,3,4,4]
+ channel['/graph'].callback do |data|
+ puts "someone send "
+ p data
+ puts 'on channel /graph'
+ server.channel['/graph'].data( data )
+ end
+}
server.start
while true
View
17 examples/soapbox/soapbox-cometd.rb
@@ -1,15 +1,14 @@
$:.unshift( "../../lib" )
require 'rcomet'
-server = RComet::Server.new( :host => '0.0.0.0', :port => 8990, :mount => '/' )
-server.channel['/login'].callback do |data|
- puts "someone send "
- p data
- puts 'on channel /login'
- server.channel["/from/#{data}"]
-end
-
-server.start
+RComet::Server.new( :host => '0.0.0.0', :port => 8990, :mount => '/', :server => :mongrel ) {
+ channel['/login'].callback do |data|
+ puts "someone send "
+ p data
+ puts 'on channel /login'
+ channel["/from/#{data}"]
+ end
+}.start
while true
end
View
76 examples/soapbox/static/soapbox.rhtml
@@ -7,6 +7,7 @@
<script language="JavaScript" type="text/javascript">
dojo.require("dojox.cometd");
+ dojo.require("dojo.fx");
var comet = dojox.cometd;
comet.init("http://<%= @ip %>:8990");
@@ -16,27 +17,7 @@
current = dojo.byId("stream").innerHTML
dojo.byId("stream").innerHTML = "<li><b>"+msg.data.username+"</b>: "+msg.data.message+"</li>"+current;
}
- }
-
- var username = null;
- function login( ) {
- username = dojo.byId("username").value;
- comet.publish( '/login', username );
-
- return( false );
- }
-
- function follow() {
- followee = dojo.byId("followee").value;
- comet.subscribe( '/from/'+followee, message, "publish" );
-
- return( false );
- }
-
- function send() {
- message = dojo.byId("message").value;
- comet.publish( '/from/'+username, { "username":username, "message":message } );
- }
+ }
</script>
</head>
@@ -45,14 +26,18 @@
<h1><em>Soapbox</em> | a Twitter-style chat app</h1>
- <form id="enterUsername" onSubmit="return login();">
- <label for="username">Pick a username</label>
- <input type="text" name="username" id="username">
- <input type="submit" value="Go">
- </form>
+ <!-- <form id="enterUsername" onSubmit="return login();"> -->
+ <div id="login">
+ <form id="enterUsername">
+ <label for="username">Pick a username</label>
+ <input type="text" name="username" id="username">
+ <input type="submit" value="Go">
+ </form>
+ </div>
<div id="app">
- <form id="addFollowee" onSubmit="return follow();">
+ <!-- <form id="addFollowee" onSubmit="return follow();"> -->
+ <form id="addFollowee">
<label for="followee">Follow</label>
<input type="text" name="followee" id="followee">
<input type="submit" value="Go">
@@ -61,12 +46,47 @@
<form id="postMessage">
<label for="message">Post a message</label><br>
<textarea name="message" id="message" rows="3" cols="40"></textarea>
- <input type="button" value="Go" onClick="javascript:send();">
+ <!-- <input type="button" value="Go" onClick="javascript:send();"> -->
+ <input type="submit" value="Send">
</form>
<ul id="stream">
</ul>
</div>
</div>
+ <script language="JavaScript" type="text/javascript">
+ var username = null;
+ dojo.connect(dojo.byId("enterUsername"), "onsubmit", function(evt) {
+ evt.preventDefault();
+ dojo.stopEvent(evt);
+ username = dojo.byId("username").value;
+ comet.publish( '/login', username );
+
+ dojo.fadeOut({node:dojo.byId("enterUsername")}).play( );
+ dojo.animateProperty({
+ node: dojo.byId("login"),
+ properties: { height: { end: 0 } }
+ }).play( );
+ return false;
+ })
+
+ var addFolloweeForm = dojo.byId("addFollowee");
+ dojo.connect(addFolloweeForm, "onsubmit", function(evt) {
+ evt.preventDefault();
+ dojo.stopEvent(evt);
+ followee = dojo.byId("followee").value;
+ comet.subscribe( '/from/'+followee, message, "publish" );
+ return false;
+ })
+
+ var postMessageForm = dojo.byId("postMessage");
+ dojo.connect(postMessageForm, "onsubmit", function(evt) {
+ evt.preventDefault();
+ dojo.stopEvent(evt);
+ message = dojo.byId("message").value;
+ comet.publish( '/from/'+username, { "username":username, "message":message } );
+ return false;
+ })
+ </script>
</body>
</html>

0 comments on commit 20829f7

Please sign in to comment.
Something went wrong with that request. Please try again.