litecable 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +20 -3
- data/lib/lite_cable/anycable.rb +0 -2
- data/lib/lite_cable/broadcast_adapters/base.rb +0 -2
- data/lib/lite_cable/broadcast_adapters.rb +0 -2
- data/lib/lite_cable/channel/registry.rb +2 -0
- data/lib/lite_cable/config.rb +1 -1
- data/lib/lite_cable/connection/subscriptions.rb +12 -1
- data/lib/lite_cable/server/client_socket/base.rb +3 -5
- data/lib/lite_cable/server/heart_beat.rb +0 -2
- data/lib/lite_cable/version.rb +1 -1
- data/lib/lite_cable.rb +4 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce37cbd6931242e4cc18f8679e3131e3b7e1dab3b589576408b7a8b3d70737ae
|
4
|
+
data.tar.gz: e12346809a6b05538edb6d417ba99fa72ae465bfb79775a0f7e046cc8070e2fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3a5bd03cb018458eb5c9c447e3f2ae240cf92d91c071c6aec89c067753bd63b023f23a7c1dea6261b2457236466e1b8dcd07f27413d7dd1aeeeb70bb5579ef
|
7
|
+
data.tar.gz: 1972ce3fd5adc6305a22fbfcd174ee5ec5f74fba22e553e714159b5b9c822fd3d1bcbbc774a9630292e9002bfb61e4d80c0c0916a1001d3462a84433002b8651
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -55,6 +55,21 @@ end
|
|
55
55
|
App.cable.subscriptions.create('chat', ...)
|
56
56
|
```
|
57
57
|
|
58
|
+
### Using a custom channel registry
|
59
|
+
|
60
|
+
Alternatively to eager loading all channel classes and providing identifiers, you can build a custom _channel registry_ object, which can perform channel class lookups:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# DummyRegistry which always returns a predefined channel class
|
64
|
+
class DummyRegistry
|
65
|
+
def lookup(channel_id)
|
66
|
+
DummyChannel
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
LiteCable.channel_registry = DummyRegistry.new
|
71
|
+
```
|
72
|
+
|
58
73
|
### Using built-in server (middleware)
|
59
74
|
|
60
75
|
Lite Cable comes with a simple Rack middleware for development/testing usage.
|
@@ -78,9 +93,11 @@ end
|
|
78
93
|
|
79
94
|
### Using with AnyCable
|
80
95
|
|
81
|
-
Lite Cable is AnyCable-compatible out-of-the-box
|
96
|
+
Lite Cable is AnyCable-compatible out-of-the-box.
|
97
|
+
|
98
|
+
If AnyCable gem is loaded, you don't need to configure Lite Cable at all.
|
82
99
|
|
83
|
-
|
100
|
+
Otherwise, you must configure broadcast adapter manually:
|
84
101
|
|
85
102
|
```ruby
|
86
103
|
LiteCable.broadcast_adapter = :any_cable
|
@@ -88,7 +105,7 @@ LiteCable.broadcast_adapter = :any_cable
|
|
88
105
|
|
89
106
|
You can also do this via configuration, e.g., env var (`LITECABLE_BROADCAST_ADAPTER=any_cable`) or `broadcast_adapter: any_cable` in a YAML config.
|
90
107
|
|
91
|
-
|
108
|
+
**At the AnyCable side**, you must configure a connection factory:
|
92
109
|
|
93
110
|
```ruby
|
94
111
|
AnyCable.connection_factory = MyApp::Connection
|
data/lib/lite_cable/anycable.rb
CHANGED
@@ -23,7 +23,6 @@ module LiteCable # :nodoc:
|
|
23
23
|
@request ||= Rack::Request.new(socket.env)
|
24
24
|
end
|
25
25
|
|
26
|
-
# rubocop: disable Metrics/MethodLength
|
27
26
|
def handle_channel_command(identifier, command, data)
|
28
27
|
channel = subscriptions.add(identifier, false)
|
29
28
|
case command
|
@@ -45,7 +44,6 @@ module LiteCable # :nodoc:
|
|
45
44
|
close
|
46
45
|
false
|
47
46
|
end
|
48
|
-
# rubocop: enable Metrics/MethodLength
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -6,7 +6,6 @@ module LiteCable
|
|
6
6
|
module BroadcastAdapters # :nodoc:
|
7
7
|
module_function
|
8
8
|
|
9
|
-
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength
|
10
9
|
def lookup_adapter(args)
|
11
10
|
adapter, options = Array(args)
|
12
11
|
path_to_adapter = "lite_cable/broadcast_adapters/#{adapter}"
|
@@ -30,6 +29,5 @@ module LiteCable
|
|
30
29
|
|
31
30
|
BroadcastAdapters.const_get(adapter_class_name, false).new(**(options || {}))
|
32
31
|
end
|
33
|
-
# rubocop: enable Metrics/AbcSize, Metrics/MethodLength
|
34
32
|
end
|
35
33
|
end
|
data/lib/lite_cable/config.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module LiteCable
|
4
|
+
class UnknownChannelError < StandardError
|
5
|
+
attr_reader :channel_id
|
6
|
+
|
7
|
+
def initialize(channel_id)
|
8
|
+
@channel_id = channel_id
|
9
|
+
super("Unknown channel: #{channel_id}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
module Connection
|
5
14
|
# Manage the connection channels and route messages
|
6
15
|
class Subscriptions
|
@@ -30,7 +39,9 @@ module LiteCable
|
|
30
39
|
|
31
40
|
channel_id = params.delete("channel")
|
32
41
|
|
33
|
-
channel_class =
|
42
|
+
channel_class = LiteCable.channel_registry.lookup(channel_id)
|
43
|
+
|
44
|
+
raise UnknownChannelError, channel_id unless channel_class
|
34
45
|
|
35
46
|
subscriptions[identifier] = channel_class.new(connection, identifier, params)
|
36
47
|
subscribe ? subscribe_channel(subscriptions[identifier]) : subscriptions[identifier]
|
@@ -64,7 +64,6 @@ module LiteCable
|
|
64
64
|
@error_handlers << block
|
65
65
|
end
|
66
66
|
|
67
|
-
# rubocop: disable Metrics/MethodLength
|
68
67
|
def listen
|
69
68
|
keepalive
|
70
69
|
Thread.new do
|
@@ -74,7 +73,7 @@ module LiteCable
|
|
74
73
|
each_frame do |data|
|
75
74
|
@message_handlers.each do |h|
|
76
75
|
h.call(data)
|
77
|
-
rescue => e
|
76
|
+
rescue => e
|
78
77
|
log(:error, "Socket receive failed: #{e}")
|
79
78
|
@error_handlers.each { |eh| eh.call(e, data) }
|
80
79
|
close if close_on_error
|
@@ -85,7 +84,6 @@ module LiteCable
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
end
|
88
|
-
# rubocop: enable Metrics/MethodLength
|
89
87
|
|
90
88
|
def close
|
91
89
|
return unless @active
|
@@ -116,7 +114,7 @@ module LiteCable
|
|
116
114
|
frame = WebSocket::Frame::Outgoing::Server.new(version: version, type: :close, code: 1000)
|
117
115
|
@socket.write(frame.to_s) if frame.supported?
|
118
116
|
@socket.close
|
119
|
-
rescue IOError, Errno::EPIPE, Errno::ETIMEDOUT
|
117
|
+
rescue IOError, Errno::EPIPE, Errno::ETIMEDOUT
|
120
118
|
# already closed
|
121
119
|
end
|
122
120
|
|
@@ -137,7 +135,7 @@ module LiteCable
|
|
137
135
|
def each_frame
|
138
136
|
framebuffer = WebSocket::Frame::Incoming::Server.new(version: version)
|
139
137
|
|
140
|
-
while
|
138
|
+
while socket.wait_readable
|
141
139
|
data = socket.respond_to?(:recv) ? socket.recv(2000) : socket.readpartial(2000)
|
142
140
|
break if data.empty?
|
143
141
|
|
@@ -23,7 +23,6 @@ module LiteCable
|
|
23
23
|
@stopped = true
|
24
24
|
end
|
25
25
|
|
26
|
-
# rubocop: disable Metrics/MethodLength
|
27
26
|
def run
|
28
27
|
Thread.new do
|
29
28
|
Thread.current.abort_on_exception = true
|
@@ -41,7 +40,6 @@ module LiteCable
|
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
44
|
-
# rubocop: enable Metrics/MethodLength
|
45
43
|
|
46
44
|
private
|
47
45
|
|
data/lib/lite_cable/version.rb
CHANGED
data/lib/lite_cable.rb
CHANGED
@@ -23,6 +23,8 @@ module LiteCable
|
|
23
23
|
@config ||= Config.new
|
24
24
|
end
|
25
25
|
|
26
|
+
attr_accessor :channel_registry
|
27
|
+
|
26
28
|
# Broadcast encoded message to the stream
|
27
29
|
def broadcast(stream, message, coder: LiteCable.config.coder)
|
28
30
|
broadcast_adapter.broadcast(stream, message, coder: coder)
|
@@ -47,4 +49,6 @@ module LiteCable
|
|
47
49
|
@broadcast_adapter = adapter
|
48
50
|
end
|
49
51
|
end
|
52
|
+
|
53
|
+
self.channel_registry = Channel::Registry
|
50
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litecable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '6.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '6.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,14 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
195
|
requirements:
|
196
196
|
- - ">="
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version: 2.
|
198
|
+
version: 2.7.0
|
199
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
200
|
requirements:
|
201
201
|
- - ">="
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
205
|
+
rubygems_version: 3.4.6
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Fat-free ActionCable implementation
|