anycable-rack-server 0.4.0 → 0.5.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/LICENSE +1 -1
- data/README.md +3 -2
- data/lib/anycable/rack/coders/msgpack.rb +6 -2
- data/lib/anycable/rack/coders/proto/message_pb.rb +35 -0
- data/lib/anycable/rack/coders/protobuf.rb +38 -0
- data/lib/anycable/rack/connection.rb +6 -0
- data/lib/anycable/rack/middleware.rb +2 -1
- data/lib/anycable/rack/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4297bef5c67ff80f26274def5beb36a1211132cd1ac4ad83f71d787527a706f3
|
4
|
+
data.tar.gz: f60d4fbb02cab97d1b598fd9fffb4d082394977a8ab758060a901276b866d7c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 690b6ce367c468485028a01234af402978bc47fb992bd63ba3c6c37d23041eaf501f8dc1be4d992be26be6b91a7ea252e1cd26cd66c80ef081cc6fe98d894c76
|
7
|
+
data.tar.gz: a6f1fc52911181c219c72feba59994644abe36dff7bfdc2060254e833cdee7809128a9fe3c4b96e2ca821c2a754e80e97eb9dd0d775c63e2f603280d6f70a31d
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2019-
|
3
|
+
Copyright (c) 2019-2022 Yulia Oletskaya, Vladimir Dementyev
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ run app
|
|
26
26
|
|
27
27
|
## Usage with Rails
|
28
28
|
|
29
|
-
Add `gem "anycable-rack-server"` to you `Gemfile` and make sure your Action Cable adapter is set to `:any_cable`. That's it! We automatically start AnyCable Rack server for
|
29
|
+
Add `gem "anycable-rack-server"` to you `Gemfile` and make sure your Action Cable adapter is set to `:any_cable`. That's it! We automatically start AnyCable Rack server for you at `/cable` path.
|
30
30
|
|
31
31
|
## Configuration
|
32
32
|
|
@@ -74,7 +74,8 @@ config.any_cable_rack.rpc_port = 50051
|
|
74
74
|
|
75
75
|
## Broadcast adapters
|
76
76
|
|
77
|
-
AnyCable Rack supports Redis (default) and HTTP broadcast adapters
|
77
|
+
AnyCable Rack supports Redis (default) and HTTP broadcast adapters
|
78
|
+
(see [the documentation](https://docs.anycable.io/ruby/broadcast_adapters)).
|
78
79
|
|
79
80
|
Broadcast adapter is inherited from AnyCable configuration (so, you don't need to configure it twice).
|
80
81
|
|
@@ -12,8 +12,12 @@ module AnyCable
|
|
12
12
|
MessagePack.unpack(bin)
|
13
13
|
end
|
14
14
|
|
15
|
-
def encode(ruby_obj)
|
16
|
-
|
15
|
+
def encode(ruby_obj, binary_frame_wrap: true)
|
16
|
+
message_packed = MessagePack.pack(ruby_obj)
|
17
|
+
|
18
|
+
return message_packed unless binary_frame_wrap
|
19
|
+
|
20
|
+
BinaryFrame.new(message_packed)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "google/protobuf"
|
4
|
+
|
5
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
6
|
+
add_message "action_cable.Message" do
|
7
|
+
optional :type, :enum, 1, "action_cable.Type"
|
8
|
+
optional :command, :enum, 2, "action_cable.Command"
|
9
|
+
optional :identifier, :string, 3
|
10
|
+
optional :data, :string, 4
|
11
|
+
optional :message, :bytes, 5
|
12
|
+
optional :reason, :string, 6
|
13
|
+
optional :reconnect, :bool, 7
|
14
|
+
end
|
15
|
+
add_enum "action_cable.Type" do
|
16
|
+
value :no_type, 0
|
17
|
+
value :welcome, 1
|
18
|
+
value :disconnect, 2
|
19
|
+
value :ping, 3
|
20
|
+
value :confirm_subscription, 4
|
21
|
+
value :reject_subscription, 5
|
22
|
+
end
|
23
|
+
add_enum "action_cable.Command" do
|
24
|
+
value :unknown_command, 0
|
25
|
+
value :subscribe, 1
|
26
|
+
value :unsubscribe, 2
|
27
|
+
value :message, 3
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module ActionCable
|
32
|
+
Message = Google::Protobuf::DescriptorPool.generated_pool.lookup("action_cable.Message").msgclass
|
33
|
+
Type = Google::Protobuf::DescriptorPool.generated_pool.lookup("action_cable.Type").enummodule
|
34
|
+
Command = Google::Protobuf::DescriptorPool.generated_pool.lookup("action_cable.Command").enummodule
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
gem "google-protobuf", "~> 3.19", ">= 3.19.1"
|
4
|
+
require_relative "./proto/message_pb"
|
5
|
+
require_relative "./msgpack"
|
6
|
+
|
7
|
+
module AnyCable
|
8
|
+
module Rack
|
9
|
+
module Coders
|
10
|
+
module Protobuf # :nodoc:
|
11
|
+
class << self
|
12
|
+
def decode(bin)
|
13
|
+
decoded_message = ActionCable::Message.decode(bin).to_h
|
14
|
+
|
15
|
+
decoded_message[:command] = decoded_message[:command].to_s
|
16
|
+
if decoded_message[:message].present?
|
17
|
+
decoded_message[:message] = Msgpack.decode(decoded_message[:message])
|
18
|
+
end
|
19
|
+
|
20
|
+
decoded_message.each_with_object({}) { |(k, v), h| h[k.to_s] = v }
|
21
|
+
end
|
22
|
+
|
23
|
+
def encode(ruby_obj)
|
24
|
+
message = ruby_obj.delete(:message)
|
25
|
+
|
26
|
+
data = ActionCable::Message.new(ruby_obj)
|
27
|
+
|
28
|
+
if message
|
29
|
+
data.message = Msgpack.encode(message, binary_frame_wrap: false)
|
30
|
+
end
|
31
|
+
|
32
|
+
BinaryFrame.new(ActionCable::Message.encode(data))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -57,6 +57,7 @@ module AnyCable
|
|
57
57
|
when "subscribe" then subscribe(channel_identifier)
|
58
58
|
when "unsubscribe" then unsubscribe(channel_identifier)
|
59
59
|
when "message" then send_message(channel_identifier, decoded["data"])
|
60
|
+
when "history" then send_history(channel_identifier, decoded["history"])
|
60
61
|
else
|
61
62
|
log(:error, "Command not found #{command}")
|
62
63
|
end
|
@@ -133,6 +134,11 @@ module AnyCable
|
|
133
134
|
process_command(response, identifier)
|
134
135
|
end
|
135
136
|
|
137
|
+
def send_history(identifier, history)
|
138
|
+
log(:debug) { "History is not truly supported. Responding with reject_history" }
|
139
|
+
transmit({"type" => "reject_history"})
|
140
|
+
end
|
141
|
+
|
136
142
|
def process_command(response, identifier)
|
137
143
|
response.transmissions.each { |transmission| transmit(decode_transmission(transmission)) }
|
138
144
|
hub.remove_channel(socket, identifier) if response.stop_streams
|
@@ -9,7 +9,8 @@ require "anycable/rack/socket"
|
|
9
9
|
module AnyCable
|
10
10
|
module Rack
|
11
11
|
class Middleware # :nodoc:
|
12
|
-
PROTOCOLS = [
|
12
|
+
PROTOCOLS = %w[actioncable-v1-json actioncable-v1-ext-json actioncable-v1-msgpack actioncable-unsupported actioncable-v1-protobuf].freeze
|
13
|
+
|
13
14
|
attr_reader :pinger,
|
14
15
|
:hub,
|
15
16
|
:coder,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anycable-rack-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yulia Oletskaya
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: anyway_config
|
@@ -171,6 +171,8 @@ files:
|
|
171
171
|
- lib/anycable/rack/broadcast_subscribers/redis_subscriber.rb
|
172
172
|
- lib/anycable/rack/coders/json.rb
|
173
173
|
- lib/anycable/rack/coders/msgpack.rb
|
174
|
+
- lib/anycable/rack/coders/proto/message_pb.rb
|
175
|
+
- lib/anycable/rack/coders/protobuf.rb
|
174
176
|
- lib/anycable/rack/config.rb
|
175
177
|
- lib/anycable/rack/connection.rb
|
176
178
|
- lib/anycable/rack/errors.rb
|
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
- !ruby/object:Gem::Version
|
204
206
|
version: '0'
|
205
207
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
208
|
+
rubygems_version: 3.4.8
|
207
209
|
signing_key:
|
208
210
|
specification_version: 4
|
209
211
|
summary: AnyCable Rack Server
|