socker 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/lib/socker.rb +16 -4
- data/lib/socker/helper.rb +4 -0
- metadata +2 -2
data/lib/socker.rb
CHANGED
@@ -20,9 +20,12 @@ module Socker
|
|
20
20
|
@application = lambda do |env|
|
21
21
|
return [501, {}, ['Sorry, but I am websocket app.']] unless is_websocket?(env)
|
22
22
|
connection(env) do |c|
|
23
|
-
WEBSOCKET_STANDARD_EVENTS.each(®ister_handler(c))
|
23
|
+
WEBSOCKET_STANDARD_EVENTS.each(®ister_handler(c, env))
|
24
24
|
end
|
25
25
|
end
|
26
|
+
@application.class.instance_eval {
|
27
|
+
define_method(:log) { |message| Socker::App.log(message) }
|
28
|
+
}
|
26
29
|
@application.freeze
|
27
30
|
@application
|
28
31
|
end
|
@@ -59,13 +62,22 @@ module Socker
|
|
59
62
|
Faye::WebSocket.websocket?(env)
|
60
63
|
end
|
61
64
|
|
62
|
-
def register_handler(connection)
|
63
|
-
lambda { |event| connection.on(event, &handle_with(event, socket: connection)) }
|
65
|
+
def register_handler(connection, env)
|
66
|
+
lambda { |event| connection.on(event, &handle_with(event, socket: connection, env: env)) }
|
64
67
|
end
|
65
68
|
|
66
69
|
def handle_with(event, opts={})
|
67
70
|
if events[event]
|
68
|
-
|
71
|
+
current_class = self.class
|
72
|
+
lambda do |ev|
|
73
|
+
@env = Rack::Request.new(opts[:env])
|
74
|
+
begin
|
75
|
+
handle(event, opts[:socket])
|
76
|
+
events[event].call(opts[:socket], ev)
|
77
|
+
rescue => error
|
78
|
+
current_class.log("[#{error.class}] #{error.message}\n#{error.backtrace.join("\n")}", :error)
|
79
|
+
end
|
80
|
+
end
|
69
81
|
else
|
70
82
|
method(:handle_undefined)
|
71
83
|
end
|
data/lib/socker/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socker
|
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-10-
|
12
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faye-websocket
|