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 +4 -0
- data/README.md +1 -0
- data/lib/sinatra/websocketio.rb +1 -0
- data/lib/sinatra-websocketio/application.rb +9 -1
- data/lib/sinatra-websocketio/options.rb +35 -0
- data/lib/sinatra-websocketio/version.rb +1 -1
- data/lib/sinatra-websocketio/websocketio.rb +3 -8
- data/sample/config.ru +1 -0
- data/sinatra-websocketio.gemspec +1 -1
- metadata +4 -3
data/History.txt
CHANGED
data/README.md
CHANGED
data/lib/sinatra/websocketio.rb
CHANGED
@@ -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,17 +1,12 @@
|
|
1
1
|
class WebSocketIO
|
2
2
|
|
3
|
-
def self.
|
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
data/sinatra-websocketio.gemspec
CHANGED
@@ -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 = "
|
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.
|
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-
|
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:
|
157
|
+
homepage: https://github.com/shokai/sinatra-websocketio
|
157
158
|
licenses: []
|
158
159
|
post_install_message:
|
159
160
|
rdoc_options: []
|