sock-drawer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/Rakefile +8 -0
- data/examples/simple/index.html +28 -0
- data/examples/simple/readme.md +7 -0
- data/examples/simple/send_message.rb +3 -0
- data/lib/sock/drawer/version.rb +1 -1
- data/lib/sock/server.rb +6 -7
- data/sock-drawer.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db994d09442d34c3bbe8e8ceda3a29270e14d033
|
4
|
+
data.tar.gz: dcb43f57ec55b2fac092d28e8bf6ba61c27c88a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a503d9185396f95d453fee0762d409c9c42ca4cba42b86f5c3c4e93603fa4b54011e28f2a895813e18cca093be6ed7aea9d298c958f847fcfdb78d2729c2e5ec
|
7
|
+
data.tar.gz: d6827bf2e513bc32fb0e88a1c9f000a2fe2771400a829440ce1d10edf18d142ff171732eed5f5c37515c1970eef3a12ab9b8aa6aaa42fda1fff9d7743e6343a5
|
data/README.md
CHANGED
@@ -74,7 +74,7 @@ end
|
|
74
74
|
Then register your listener with the server
|
75
75
|
|
76
76
|
```Ruby
|
77
|
-
Sock::Server.new(listener:
|
77
|
+
Sock::Server.new(listener: MyListener)
|
78
78
|
```
|
79
79
|
|
80
80
|
Whenever an event is fired on the `sock-hook/echo` channel the block will be executed.
|
@@ -98,7 +98,7 @@ Current supported configuration options:
|
|
98
98
|
|
99
99
|
| keyword arg | default |
|
100
100
|
| ----------- | ------- |
|
101
|
-
| name | 'sock-hook'
|
101
|
+
| name | 'sock-hook' |
|
102
102
|
| logger | Logger.new(STDOUT) |
|
103
103
|
| socket_params | { host: '0.0.0.0', port: 8020 } |
|
104
104
|
| mode | 'default' |
|
data/Rakefile
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
|
3
|
+
<html lang="en">
|
4
|
+
<head>
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<title>Simple socket example</title>
|
7
|
+
<meta name="description" content="Simple socket example">
|
8
|
+
<meta name="author" content="HParker">
|
9
|
+
</head>
|
10
|
+
|
11
|
+
<body>
|
12
|
+
<h1>chat</h1>
|
13
|
+
<ul id="chat">
|
14
|
+
<li>chat begins under here</li>
|
15
|
+
</ul>
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
var webSocket = new WebSocket("ws://localhost:8020/my-channel");
|
19
|
+
|
20
|
+
webSocket.onmessage = function(event) {
|
21
|
+
var li = document.createElement("li");
|
22
|
+
li.innerText = event.data;
|
23
|
+
var chat = document.getElementById("chat");
|
24
|
+
chat.appendChild(li);
|
25
|
+
}
|
26
|
+
</script>
|
27
|
+
</body>
|
28
|
+
</html>
|
data/lib/sock/drawer/version.rb
CHANGED
data/lib/sock/server.rb
CHANGED
@@ -20,7 +20,7 @@ module Sock
|
|
20
20
|
# utility method used to subscribe on the default name and start the socket server
|
21
21
|
def start!
|
22
22
|
EM.run do
|
23
|
-
register!
|
23
|
+
register! if @listener
|
24
24
|
subscribe(@name)
|
25
25
|
socket_start_listening
|
26
26
|
end
|
@@ -51,7 +51,6 @@ module Sock
|
|
51
51
|
EventMachine::WebSocket.start(@socket_params) do |ws|
|
52
52
|
handle_open(ws)
|
53
53
|
handle_message(ws)
|
54
|
-
handle_close(ws)
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -69,7 +68,8 @@ module Sock
|
|
69
68
|
def handle_open(ws)
|
70
69
|
ws.onopen do |handshake|
|
71
70
|
@logger.info "sock opened on #{handshake.path}"
|
72
|
-
channel(@name + handshake.path).subscribe { |msg| ws.send(msg) }
|
71
|
+
sid = channel(@name + handshake.path).subscribe { |msg| ws.send(msg) }
|
72
|
+
handle_close(ws, sid, handshake)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -77,11 +77,10 @@ module Sock
|
|
77
77
|
ws.onmessage { |msg| channel('incoming-hook').push(msg) }
|
78
78
|
end
|
79
79
|
|
80
|
-
def handle_close(ws)
|
81
|
-
# TODO: how can I know the sid to remove this subscription?
|
80
|
+
def handle_close(ws, sid, handshake)
|
82
81
|
ws.onclose {
|
83
|
-
@logger.info "connection closed"
|
84
|
-
|
82
|
+
@logger.info "connection #{sid} closed"
|
83
|
+
channel(@name + handshake.path).unsubscribe(sid)
|
85
84
|
}
|
86
85
|
end
|
87
86
|
|
data/sock-drawer.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Super simple websocket manager. '
|
12
12
|
spec.description = 'Provide a really simple interface '\
|
13
13
|
'to manage events in ruby and via websockets using ruby and event machine.'
|
14
|
-
spec.homepage = '
|
14
|
+
spec.homepage = 'https://github.com/HParker/sock-drawer'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sock-drawer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hess
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -165,6 +165,9 @@ files:
|
|
165
165
|
- LICENSE.txt
|
166
166
|
- README.md
|
167
167
|
- Rakefile
|
168
|
+
- examples/simple/index.html
|
169
|
+
- examples/simple/readme.md
|
170
|
+
- examples/simple/send_message.rb
|
168
171
|
- lib/sock/client.rb
|
169
172
|
- lib/sock/drawer.rb
|
170
173
|
- lib/sock/drawer/version.rb
|
@@ -176,7 +179,7 @@ files:
|
|
176
179
|
- spec/server_spec.rb
|
177
180
|
- spec/spec_helper.rb
|
178
181
|
- spec/subscriber_spec.rb
|
179
|
-
homepage:
|
182
|
+
homepage: https://github.com/HParker/sock-drawer
|
180
183
|
licenses:
|
181
184
|
- MIT
|
182
185
|
metadata: {}
|