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 +4 -4
- data/History.txt +4 -0
- data/lib/sinatra-websocketio/version.rb +1 -1
- data/lib/sinatra-websocketio/websocketio.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 454a37ab537ba60d23f20d1b3d28a907f6124713
|
4
|
+
data.tar.gz: 7243a6732a908bbf7efb2c48e3874e2bd09e28d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 410c6ef3758faec426ef6d8956d6af34172efe65d4d4f7900b5ec541a46fe61f58410cd227399856bac8a2e9ee9dc5c6eb7b694be35a4f855886c7a527ace91e
|
7
|
+
data.tar.gz: f0f99248f0c0691fa94b7e7e37f3bbbaf98b1b2b1898b8f2b82cb7d4277bcd548dc4fe2ee2313f87679b91137c904a7c0789034e8a6406b1f9062d7913b191be
|
data/History.txt
CHANGED
@@ -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
|
-
|
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] =
|
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.
|
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-
|
11
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|