sinatra-websocketio 0.0.1 → 0.0.2

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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.2 2013-03-08
2
+
3
+ * set :websocketio, :port => 8080
4
+
1
5
  === 0.0.1 2013-03-08
2
6
 
3
7
  * release
data/README.md CHANGED
@@ -30,6 +30,7 @@ Server Side
30
30
  ```ruby
31
31
  require 'sinatra'
32
32
  require 'sinatra/websocketio'
33
+ set :websocketio, :port => 8080
33
34
 
34
35
  run Sinatra::Application
35
36
  ```
@@ -5,6 +5,7 @@ require 'digest/md5'
5
5
  require 'event_emitter'
6
6
  require 'sinatra/streaming'
7
7
  require File.expand_path '../sinatra-websocketio/version', File.dirname(__FILE__)
8
+ require File.expand_path '../sinatra-websocketio/options', File.dirname(__FILE__)
8
9
  require File.expand_path '../sinatra-websocketio/websocketio', File.dirname(__FILE__)
9
10
  require File.expand_path '../sinatra-websocketio/application', File.dirname(__FILE__)
10
11
 
@@ -1,13 +1,21 @@
1
1
 
2
2
  module Sinatra::WebSocketIO
3
3
 
4
+ def websocketio=(options)
5
+ WebSocketIO.options = options
6
+ end
7
+
8
+ def websocketio
9
+ WebSocketIO.options
10
+ end
11
+
4
12
  helpers do
5
13
  def websocketio_js
6
14
  "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}/websocketio/websocketio.js"
7
15
  end
8
16
 
9
17
  def websocketio_url
10
- "ws://#{env['SERVER_NAME']}:#{WebSocketIO.port}"
18
+ "ws://#{env['SERVER_NAME']}:#{WebSocketIO.options[:port]}"
11
19
  end
12
20
  end
13
21
 
@@ -0,0 +1,35 @@
1
+ class WebSocketIO
2
+
3
+ def self.default_options
4
+ {
5
+ :port => [8080, lambda{|v| v.kind_of? Fixnum }]
6
+ }
7
+ end
8
+
9
+ def self.options
10
+ @@options ||= (
11
+ opts = {}
12
+ default_options.each do |k,v|
13
+ opts[k] = v[0]
14
+ end
15
+ opts
16
+ )
17
+ end
18
+
19
+ def self.options=(opts)
20
+ @@options = {}
21
+ opts.each do |k,v|
22
+ k = k.to_sym
23
+ if default_options.include? k
24
+ @@options[k] = default_options[k][1].call(v) ? v : default_options[k][0]
25
+ else
26
+ @@options[k] = v
27
+ end
28
+ end
29
+ default_options.each do |k, v|
30
+ @@options[k] = v unless @@options.include? k
31
+ end
32
+ @@options
33
+ end
34
+
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module WebSocketIO
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,17 +1,12 @@
1
1
  class WebSocketIO
2
2
 
3
- def self.port
4
- @@port ||= 8080
5
- end
6
-
7
- def self.start(port=8080)
8
- @@port = port
3
+ def self.start
9
4
  EM::defer do
10
5
  while !EM::reactor_running? do
11
6
  sleep 1
12
7
  end
13
- puts "WebSocketIO.start port:#{port}"
14
- EM::WebSocket.run :host => "0.0.0.0", :port => port do |ws|
8
+ puts "WebSocketIO.start port:#{options[:port]}"
9
+ EM::WebSocket.run :host => "0.0.0.0", :port => options[:port] do |ws|
15
10
  ws.onopen do |handshake|
16
11
  params = parse_handshake_params handshake.path
17
12
  session_id = params[:session] || (create_session Socket.unpack_sockaddr_in ws.get_peername)
data/sample/config.ru CHANGED
@@ -11,5 +11,6 @@ require 'sinatra/websocketio'
11
11
  require File.dirname(__FILE__)+'/main'
12
12
 
13
13
  set :haml, :escape_html => true
14
+ set :websocketio, :port => 8080
14
15
 
15
16
  run Sinatra::Application
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.email = ["hashimoto@shokai.org"]
10
10
  gem.description = %q{Node.js like WebSocket I/O plugin for Sinatra.}
11
11
  gem.summary = gem.description
12
- gem.homepage = "http://shokai.github.com/sinatra-websocketio"
12
+ gem.homepage = "https://github.com/shokai/sinatra-websocketio"
13
13
 
14
14
  gem.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-websocketio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -140,6 +140,7 @@ files:
140
140
  - lib/js/websocketio.js
141
141
  - lib/sinatra-websocketio.rb
142
142
  - lib/sinatra-websocketio/application.rb
143
+ - lib/sinatra-websocketio/options.rb
143
144
  - lib/sinatra-websocketio/version.rb
144
145
  - lib/sinatra-websocketio/websocketio.rb
145
146
  - lib/sinatra/websocketio.rb
@@ -153,7 +154,7 @@ files:
153
154
  - sample/views/index.haml
154
155
  - sample/views/main.scss
155
156
  - sinatra-websocketio.gemspec
156
- homepage: http://shokai.github.com/sinatra-websocketio
157
+ homepage: https://github.com/shokai/sinatra-websocketio
157
158
  licenses: []
158
159
  post_install_message:
159
160
  rdoc_options: []