socker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/socker.rb +16 -4
  2. data/lib/socker/helper.rb +4 -0
  3. 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(&register_handler(c))
23
+ WEBSOCKET_STANDARD_EVENTS.each(&register_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
- lambda { |ev| handle(event, opts[:socket]); events[event].call(opts[:socket], ev) }
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
@@ -10,6 +10,10 @@ module Socker
10
10
  connections.each { |c| c.ping(message, &callback) }
11
11
  end
12
12
 
13
+ def params
14
+ @env.params
15
+ end
16
+
13
17
  end
14
18
 
15
19
  end
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.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-10-15 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faye-websocket