sinatra-rocketio 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c72cddee0b691d449bb7f41ffdb7644fa55adf3
4
- data.tar.gz: 2d7d82d2a7ba471e65f8cbc442fcc3aad3de0e5c
3
+ metadata.gz: 5e83f8cf2d3ec769975e49a8c87cbce77e55eb02
4
+ data.tar.gz: 35d737b0f6b92ee4ea41486cb262e5fc2ae8ad5f
5
5
  SHA512:
6
- metadata.gz: 4a8a8202c6cae1f75b86e87efe6154d804c2d24493267507ba1102f1fbe6eb6353552bc452e6dcca47da0a33e6a4152b9edc77e360bb284932e365b014272bd1
7
- data.tar.gz: 583f338b327e36a36bfb04e536fb638adc399c2dc9cd3b70dcde7d37fe7007cfbd5bb378ed783cd163b090e7ecb7df8571a390c9a7eac2c27dce49df1657e7c2
6
+ metadata.gz: 1a5cd2031b22d2119780cc0eb95ce9ff85418af7c4c97f632afe89e9ead697c6a4843c21e32f61fac130791dda4e61b5818715d477ce51b4effb2f89e25dec06
7
+ data.tar.gz: c16dab7e6f2ed676be4dff89180d7f9a74a3c87919fbf732f2f5c2439b1709312e2c970f38c7b7e1c4b476ee8008863847b9e1d7cfb217d290852591274e2cb1
@@ -1,3 +1,9 @@
1
+ === 0.2.4 2013-05-23
2
+
3
+ * bugfix RocketIO start process
4
+ * add classic style sample app
5
+ * update gem dependencies
6
+
1
7
  === 0.2.3 2013-04-03
2
8
 
3
9
  * bugfix setting
data/README.md CHANGED
@@ -184,10 +184,17 @@ end
184
184
 
185
185
  Sample App
186
186
  ----------
187
- chat app
188
187
 
188
+ ### hello world
189
+ - https://github.com/shokai/rocketio-hello-world
190
+
191
+
192
+ ### chat app
189
193
  - https://github.com/shokai/sinatra-rocketio/tree/master/sample
190
194
  - https://github.com/shokai/rocketio-chat-sample
195
+
196
+
197
+ ### arduino integration
191
198
  - https://github.com/shokai/rocketio-arduino-sample
192
199
 
193
200
 
@@ -2,34 +2,27 @@ module Sinatra
2
2
  module RocketIO
3
3
 
4
4
  def self.registered(app)
5
- app.helpers Sinatra::RocketIO::Helpers
5
+ app.register Sinatra::CometIO
6
+ app.register Sinatra::WebSocketIO
7
+ app.helpers Sinatra::RocketIO::Helpers
8
+ app.get '/rocketio/settings' do
9
+ content_type 'application/json'
10
+ @setting_json ||= (
11
+ setting = {}
12
+ setting[:websocket] = websocketio_url if Sinatra::RocketIO.options[:websocket]
13
+ setting[:comet] = cometio_url if Sinatra::RocketIO.options[:comet]
14
+ setting.to_json
15
+ )
16
+ end
17
+ app.get '/rocketio/rocketio.js' do
18
+ content_type 'application/javascript'
19
+ @js ||= ERB.new(Sinatra::RocketIO.javascript).result(binding)
20
+ end
6
21
  EM::defer do
7
22
  while !EM::reactor_running? do
8
23
  sleep 1
9
24
  end
10
- if options[:comet]
11
- app.register Sinatra::CometIO
12
- end
13
- if options[:websocket]
14
- app.register Sinatra::WebSocketIO
15
- Sinatra::WebSocketIO.start
16
- end
17
- app.get '/rocketio/rocketio.js' do
18
- content_type 'application/javascript'
19
- @js ||= ERB.new(Sinatra::RocketIO.javascript).result(binding)
20
- end
21
- app.get '/rocketio/settings' do
22
- content_type 'application/json'
23
- @setting_json ||= (
24
- setting = {}
25
- setting[:websocket] = websocketio_url if Sinatra::RocketIO.options[:websocket]
26
- setting[:comet] = cometio_url if Sinatra::RocketIO.options[:comet]
27
- setting.to_json
28
- )
29
- end
30
- app.routes["GET"].delete_if{|route|
31
- "/cometio/cometio.js" =~ route[0] or "/websocketio/websocketio.js" =~ route[0]
32
- }
25
+ Sinatra::WebSocketIO.start if Sinatra::RocketIO.options[:websocket]
33
26
  Sinatra::RocketIO.emit :start
34
27
  end
35
28
  end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module RocketIO
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require
4
+ require 'sinatra'
5
+ if development?
6
+ $stdout.sync = true
7
+ require 'sinatra/reloader'
8
+ $:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
9
+ end
10
+ require 'sinatra/rocketio'
11
+ require 'haml'
12
+ require 'sass'
13
+ require File.dirname(__FILE__)+'/main'
14
+
15
+ set :haml, :escape_html => true
16
+ set :cometio, :timeout => 120, :post_interval => 2
17
+ set :websocketio, :port => (ENV['WS_PORT'] || 8080).to_i
18
+ set :rocketio, :comet => true, :websocket => true
19
+
20
+ case RUBY_PLATFORM
21
+ when /linux/i then EM.epoll
22
+ when /bsd/i then EM.kqueue
23
+ end
24
+ EM.set_descriptor_table_size 10000
25
+
26
+ run Sinatra::Application
@@ -0,0 +1,38 @@
1
+ io = Sinatra::RocketIO
2
+
3
+ io.once :start do
4
+ puts "RocketIO start!!!"
5
+ end
6
+
7
+ io.on :connect do |client|
8
+ puts "new client - #{client}"
9
+ push :chat, {:name => "system", :message => "new #{client.type} client <#{client.session}>"}, :channel => client.channel
10
+ push :chat, {:name => "system", :message => "welcome <#{client.session}>"}, :to => client.session
11
+ end
12
+
13
+ io.on :disconnect do |client|
14
+ puts "disconnect client - #{client}"
15
+ push :chat, {:name => "system", :message => "bye <#{client.session}>"}, :channel => client.channel
16
+ end
17
+
18
+ io.on :chat do |data, client|
19
+ puts "#{data['name']} : #{data['message']} - #{client}"
20
+ push :chat, data, :channel => client.channel
21
+ end
22
+
23
+ io.on :error do |err|
24
+ STDERR.puts "error!! #{err}"
25
+ end
26
+
27
+ get '/' do
28
+ redirect '/chat/1'
29
+ end
30
+
31
+ get '/chat/:channel' do
32
+ @channel = params[:channel]
33
+ haml :chat
34
+ end
35
+
36
+ get '/:source.css' do
37
+ scss params[:source].to_sym
38
+ end
@@ -0,0 +1,30 @@
1
+ WebSocket/Comet Chat
2
+ ====================
3
+
4
+ * Ruby 1.8.7 or 1.9.2 or 1.9.3 or 2.0.0
5
+ * sinatra-rocketio with Sinatra1.3+
6
+
7
+
8
+ Install Dependencies
9
+ --------------------
10
+
11
+ % gem install bundler
12
+ % bundle install
13
+
14
+
15
+ Run
16
+ ---
17
+
18
+ % export PORT=5000
19
+ % export WS_PORT=8080
20
+ % rackup config.ru -p 5000
21
+
22
+ => http://localhost:5000
23
+
24
+
25
+ Ruby Client
26
+ -----------
27
+
28
+ % ruby bin/cui_chat_client.rb
29
+ % ruby bin/cui_chat_client.rb http://localhost:5000 websocket
30
+ % ruby bin/cui_chat_client.rb http://localhost:5000 comet
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ $:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
5
+ require 'sinatra/rocketio/client'
6
+
7
+ name = `whoami`.strip || 'shokai'
8
+ url = ARGV.shift || 'http://localhost:5000'
9
+ type = ARGV.shift || :websocket
10
+
11
+ io = Sinatra::RocketIO::Client.new(url, :type => type, :channel => "1").connect
12
+ #io = Sinatra::RocketIO::Client.new('http://localhost:5000', :type => :comet).connect
13
+
14
+ io.on :connect do
15
+ puts "#{io.type} connect!! (session_id:#{io.session})"
16
+ end
17
+
18
+ io.on :chat do |data|
19
+ puts "<#{data['name']}> #{data['message']}"
20
+ end
21
+
22
+ io.on :error do |err|
23
+ STDERR.puts err
24
+ end
25
+
26
+ io.on :disconnect do
27
+ puts "disconnected!!"
28
+ end
29
+
30
+ loop do
31
+ line = STDIN.gets.strip
32
+ next if line.empty?
33
+ io.push :chat, {:message => line, :name => name}
34
+ end
@@ -6,7 +6,7 @@ require 'sinatra/base'
6
6
  if development?
7
7
  $stdout.sync = true
8
8
  require 'sinatra/reloader'
9
- $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
9
+ $:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
10
10
  end
11
11
  require 'sinatra/rocketio'
12
12
  require 'haml'
@@ -15,7 +15,7 @@ require File.dirname(__FILE__)+'/main'
15
15
 
16
16
  set :haml, :escape_html => true
17
17
  set :cometio, :timeout => 120, :post_interval => 2
18
- set :websocketio, :port => (ENV['WS_PORT'].to_i || 8080)
18
+ set :websocketio, :port => (ENV['WS_PORT'] || 8080).to_i
19
19
  set :rocketio, :comet => true, :websocket => true
20
20
 
21
21
  case RUBY_PLATFORM
@@ -0,0 +1,38 @@
1
+ var io = new RocketIO({channel: channel}).connect();
2
+
3
+ $(function(){
4
+ $("#chat #btn_send").click(post);
5
+ $("#chat #message").keydown(function(e){
6
+ if(e.keyCode == 13) post();
7
+ });
8
+ });
9
+
10
+ io.on("chat", function(data){
11
+ var m = $("<li>").text(data.name + " : " +data.message);
12
+ $("#chat #timeline").prepend(m);
13
+ });
14
+
15
+ io.on("connect", function(){
16
+ console.log("connect!! "+io.session);
17
+ $("#type").text("type : "+io.type);
18
+ });
19
+
20
+ io.on("disconnect", function(){
21
+ console.log("disconnect!!");
22
+ });
23
+
24
+ io.on("*", function(event, data){ // catch all events
25
+ console.log(event + " - " + JSON.stringify(data));
26
+ });
27
+
28
+ io.on("error", function(err){
29
+ console.error(err);
30
+ });
31
+
32
+ var post = function(){
33
+ var name = $("#chat #name").val();
34
+ var message = $("#chat #message").val();
35
+ if(message.length < 1) return;
36
+ io.push("chat", {name: name, message: message});
37
+ $("#chat #message").val("");
38
+ };
@@ -0,0 +1,29 @@
1
+ !!! XHTML
2
+ %html
3
+ %head
4
+ %meta{'http-equiv' => 'Content-Type', :content => 'text/html', :charset => 'UTF-8'}
5
+ %title sinatra-rocketio chat
6
+ %link{:rel => 'stylesheet', :href => "/main.css", :type => 'text/css'}
7
+ :javascript
8
+ var channel = "#{@channel}";
9
+ %script{:type => 'text/javascript', :src => "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"}
10
+ %script{:type => 'text/javascript', :src => rocketio_js}
11
+ %script{:type => 'text/javascript', :src => "/js/chat.js"}
12
+
13
+ %body
14
+ %div#content
15
+ %div#header
16
+ %h1 rocketio chat [ch:#{@channel}]
17
+ %span#type
18
+ %div#main
19
+ %div#chat
20
+ %input{:id => 'name', :value => 'name', :size => 20}
21
+ %input{:id => 'message', :value => 'hello!!', :size => 80}
22
+ %input{:id => 'btn_send', :type => 'button', :value => 'post'}
23
+ %ul#timeline
24
+
25
+ %hr
26
+ %div#footer
27
+ sinatra-rocketio v#{Sinatra::RocketIO::VERSION} -
28
+ - src_url = 'https://github.com/shokai/sinatra-rocketio'
29
+ %a{:href => src_url} #{src_url}
@@ -0,0 +1,15 @@
1
+
2
+ $font_black : #222;
3
+
4
+ @mixin content {
5
+ div {
6
+ margin : 10px;
7
+ font-size : 95%;
8
+ }
9
+ }
10
+
11
+ body {
12
+ @include content;
13
+ background-color : #EEE;
14
+ color : $font_black;
15
+ }
@@ -25,8 +25,8 @@ Gem::Specification.new do |gem|
25
25
  gem.add_development_dependency "httparty"
26
26
  gem.add_development_dependency "json"
27
27
 
28
- gem.add_dependency "sinatra-cometio", ">= 0.5.3"
29
- gem.add_dependency "sinatra-websocketio", ">= 0.2.6"
28
+ gem.add_dependency "sinatra-cometio", ">= 0.5.4"
29
+ gem.add_dependency "sinatra-websocketio", ">= 0.2.9"
30
30
  gem.add_dependency "sinatra"
31
31
  gem.add_dependency "eventmachine", ">= 1.0.0"
32
32
  gem.add_dependency "event_emitter", ">= 0.2.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-rocketio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - '>='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.5.3
131
+ version: 0.5.4
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.5.3
138
+ version: 0.5.4
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sinatra-websocketio
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '>='
144
144
  - !ruby/object:Gem::Version
145
- version: 0.2.6
145
+ version: 0.2.9
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
- version: 0.2.6
152
+ version: 0.2.9
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: sinatra
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -232,13 +232,20 @@ files:
232
232
  - lib/sinatra-rocketio/version.rb
233
233
  - lib/sinatra/rocketio.rb
234
234
  - lib/sinatra/rocketio/client.rb
235
- - sample/README.md
236
- - sample/bin/cui_chat_client.rb
237
- - sample/config.ru
238
- - sample/main.rb
239
- - sample/public/js/chat.js
240
- - sample/views/chat.haml
241
- - sample/views/main.scss
235
+ - sample/classic_style/README.md
236
+ - sample/classic_style/bin/cui_chat_client.rb
237
+ - sample/classic_style/config.ru
238
+ - sample/classic_style/main.rb
239
+ - sample/classic_style/public/js/chat.js
240
+ - sample/classic_style/views/chat.haml
241
+ - sample/classic_style/views/main.scss
242
+ - sample/modular_style/README.md
243
+ - sample/modular_style/bin/cui_chat_client.rb
244
+ - sample/modular_style/config.ru
245
+ - sample/modular_style/main.rb
246
+ - sample/modular_style/public/js/chat.js
247
+ - sample/modular_style/views/chat.haml
248
+ - sample/modular_style/views/main.scss
242
249
  - sinatra-rocketio.gemspec
243
250
  - test/app.rb
244
251
  - test/app/config.ru
@@ -280,3 +287,4 @@ test_files:
280
287
  - test/test_push_multi_client.rb
281
288
  - test/test_rocketio.rb
282
289
  - test/test_settings.rb
290
+ has_rdoc: