sinatra-websocketio 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d7891b6aad93861982e3e0ba15f735e06837e4a
4
- data.tar.gz: bae64259a47ea48715acc6b64b48856b3d35c982
3
+ metadata.gz: 454a37ab537ba60d23f20d1b3d28a907f6124713
4
+ data.tar.gz: 7243a6732a908bbf7efb2c48e3874e2bd09e28d1
5
5
  SHA512:
6
- metadata.gz: 5e7aa76c655ab3a5910e16b3974098a9df363e730c850eddbc9c341a252bf53c1854c5eb3ddeb55386d1ee25133e40fec724bfc1d37ba4ebde8f4bc5bb9aebcb
7
- data.tar.gz: c90d1adca5c5250d17c4f29f5d630519ce5f89c018a04f591c0019e99d887d01d571047d461bda40cd1046992d9ef8aa04817bef2c58a3e6a966bac2134b2f7c
6
+ metadata.gz: 410c6ef3758faec426ef6d8956d6af34172efe65d4d4f7900b5ec541a46fe61f58410cd227399856bac8a2e9ee9dc5c6eb7b694be35a4f855886c7a527ace91e
7
+ data.tar.gz: f0f99248f0c0691fa94b7e7e37f3bbbaf98b1b2b1898b8f2b82cb7d4277bcd548dc4fe2ee2313f87679b91137c904a7c0789034e8a6406b1f9062d7913b191be
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.3.6 2013-10-01
2
+
3
+ * store REMOTE_ADDR into Sinatra::WebSocketIO.sessions
4
+
1
5
  === 0.3.5 2013-08-09
2
6
 
3
7
  * push "__heartbeat" message from server every 300 sec
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module WebSocketIO
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
5
5
  end
@@ -15,15 +15,19 @@ module Sinatra
15
15
  end
16
16
  puts "Sinatra::WebSocketIO.start port:#{options[:port]}"
17
17
  EM::WebSocket.run :host => "0.0.0.0", :port => options[:port] do |ws|
18
- ws.onopen do |handshake|
18
+ ws.onopen do |handshake, connection|
19
19
  params = parse_handshake_params handshake.path
20
- session_id = params[:session] || (create_session Socket.unpack_sockaddr_in ws.get_peername)
20
+ remote_addr = Socket.unpack_sockaddr_in(ws.get_peername)[1]
21
+ session_id = params[:session] || create_session(remote_addr)
21
22
 
22
23
  if self.sessions.include? session_id
23
24
  ws.send({:type => :error, :data => "invalid session_id (#{session_id})"}.to_json)
24
25
  ws.close
25
26
  else
26
- self.sessions[session_id] = ws
27
+ self.sessions[session_id] = {
28
+ :websocket => ws,
29
+ :remote_addr => remote_addr
30
+ }
27
31
  ws.onclose do
28
32
  self.sessions.delete session_id
29
33
  self.emit :disconnect, session_id
@@ -52,7 +56,7 @@ module Sinatra
52
56
  def self.push(type, data, opt={})
53
57
  if opt.include? :to
54
58
  return unless self.sessions.include? opt[:to]
55
- s = self.sessions[opt[:to]]
59
+ s = self.sessions[opt[:to]][:websocket]
56
60
  begin
57
61
  s.send({:type => type, :data => data}.to_json)
58
62
  rescue => e
@@ -66,7 +70,7 @@ module Sinatra
66
70
  end
67
71
 
68
72
  def self.sessions
69
- @@sessions ||= Hash.new
73
+ @@sessions ||= Hash.new{|h,k| h[k] = {:websocket => nil, :remote_addr => nil} }
70
74
  end
71
75
 
72
76
  def self.create_session(ip_addr)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-websocketio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
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-08-09 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler