async_cable 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -0
- data/lib/async_cable.rb +5 -0
- data/lib/async_cable/connection.rb +10 -0
- data/lib/async_cable/errors.rb +2 -0
- data/lib/async_cable/registry.rb +1 -1
- data/lib/async_cable/server.rb +0 -2
- data/lib/async_cable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 998abf5f3d5c77b7708cc89f7959e96240c41d1e9d03969b835dfe6feb3bd965
|
4
|
+
data.tar.gz: 598c96f04bd6081fbb87f4652ef5c7934e6bc0ca56f6b7fa71af3dce2413f8ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e46330cb55642128c2dc7023b93aa2137605bb5cfa3c8fbfc19c834eab67acb8a62fa2941367235d575555e2084ad7a21e2befc907582f2c57281fc1131f6b4
|
7
|
+
data.tar.gz: 93bcf416e3e8a6c116d26a2a2e66cfbb440009933712aa0155f52465e03add44057080adf7f941943215fde75881c06c8d64fd0fae85be428de2de37fd6c3a4d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -94,6 +94,11 @@ example of JS code for connecting with websocket server
|
|
94
94
|
|
95
95
|
## Development
|
96
96
|
|
97
|
+
### Building version
|
98
|
+
|
99
|
+
gem_push=false rake release
|
100
|
+
gem push pkg/async_cable-X.Y.Z.gem
|
101
|
+
|
97
102
|
will use [Semver](https://semver.org) from version `1.0.0`
|
98
103
|
|
99
104
|
## Contributing
|
data/lib/async_cable.rb
CHANGED
@@ -6,14 +6,19 @@ require 'async_cable/connection'
|
|
6
6
|
require 'async_cable/server'
|
7
7
|
|
8
8
|
module AsyncCable
|
9
|
+
|
10
|
+
# @return [Async::Config]
|
9
11
|
def config
|
10
12
|
@config ||= Config.new
|
11
13
|
end
|
12
14
|
|
15
|
+
# @yield [Async::Config]
|
13
16
|
def configure
|
14
17
|
yield config
|
15
18
|
end
|
16
19
|
|
20
|
+
# Transmit data to all WS connections.
|
21
|
+
# @param data [Hash]
|
17
22
|
def broadcast(data)
|
18
23
|
config.logger.debug { "#{name}.broadcast data=#{data.inspect}" }
|
19
24
|
Registry.each { |conn| conn.transmit(data) }
|
@@ -9,14 +9,17 @@ module AsyncCable
|
|
9
9
|
subclass.identified_as subclass.name.demodulize.underscore
|
10
10
|
end
|
11
11
|
|
12
|
+
# sets #channel_name for connection class
|
12
13
|
def identified_as(channel)
|
13
14
|
@channel_name = channel.to_s
|
14
15
|
end
|
15
16
|
|
17
|
+
# @return [String]
|
16
18
|
def channel_name
|
17
19
|
@channel_name
|
18
20
|
end
|
19
21
|
|
22
|
+
# @return [Logger]
|
20
23
|
def logger
|
21
24
|
AsyncCable.config.logger
|
22
25
|
end
|
@@ -77,6 +80,8 @@ module AsyncCable
|
|
77
80
|
@stream_name
|
78
81
|
end
|
79
82
|
|
83
|
+
# @param reason [String,NilClass] exception message.
|
84
|
+
# @raise [AsyncCable::UnauthorizedError]
|
80
85
|
def reject_unauthorized(reason = nil)
|
81
86
|
raise UnauthorizedError, reason
|
82
87
|
end
|
@@ -94,6 +99,7 @@ module AsyncCable
|
|
94
99
|
close_code == Protocol::WebSocket::Error::NO_ERROR
|
95
100
|
end
|
96
101
|
|
102
|
+
# Called when connection being opened.
|
97
103
|
# @param env [Hash]
|
98
104
|
# @raise [AsyncCable::Errors::StreamNameNotSet] if #stream_for was not called
|
99
105
|
# @raise [AsyncCable::Errors::UnauthorizedError] if #reject_unauthorized was called
|
@@ -105,6 +111,8 @@ module AsyncCable
|
|
105
111
|
Registry.add(channel_name, stream_name, self)
|
106
112
|
end
|
107
113
|
|
114
|
+
# Called when connection being closed.
|
115
|
+
# @see #close_code #close_reason for close details.
|
108
116
|
def handle_close
|
109
117
|
logger.debug { "#{self.class}#handle_close clean=#{close_clean?} code=#{close_code} reason=#{close_reason}" }
|
110
118
|
close
|
@@ -112,10 +120,12 @@ module AsyncCable
|
|
112
120
|
on_close
|
113
121
|
end
|
114
122
|
|
123
|
+
# @return [String]
|
115
124
|
def channel_name
|
116
125
|
self.class.channel_name
|
117
126
|
end
|
118
127
|
|
128
|
+
# @return [Logger]
|
119
129
|
def logger
|
120
130
|
self.class.logger
|
121
131
|
end
|
data/lib/async_cable/errors.rb
CHANGED
@@ -6,12 +6,14 @@ module AsyncCable
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
# @see AsyncCable::Connection#handle_open
|
9
10
|
class StreamNameNotSet < Error
|
10
11
|
def initialize(class_name)
|
11
12
|
super("#stream_for must be called with stream name in #{class_name}#on_open")
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
# @see AsyncCable::Connection#reject_unauthorized
|
15
17
|
class UnauthorizedError < Error
|
16
18
|
def initialize(reason = nil)
|
17
19
|
super(reason || 'unauthorized')
|
data/lib/async_cable/registry.rb
CHANGED
data/lib/async_cable/server.rb
CHANGED
data/lib/async_cable/version.rb
CHANGED