anycable-rack-server 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac33d07a88c1d94d982a7068f7636fc74013dd13e18a08ba29019c1b6e90bdb1
4
- data.tar.gz: c655148349178d792f6609202762845189669053a14f89aa4a5f0c6efae67ff6
3
+ metadata.gz: 1e0fb06453d826cf3c314edb0dbb6ab1f1ab8774760b40985b105aaf87ca1316
4
+ data.tar.gz: a6fc8f21bf0944cf1cacb58b779b222782e485af7fe8dcec1bf719b31e05d38f
5
5
  SHA512:
6
- metadata.gz: 4ecbcb8c30cfa5e4b79948bc37c06405068d80bb192f53d98901d7177110da4822a20eff456a12fb7da5e7a3c3f8757ad219acb0befb2d7cd705288b3b1a3b12
7
- data.tar.gz: a687c493138b5e0c7429e6a58c1b99ea4388a8b988988f0cc4bcab656db4789494e6b0fb05d59936794dfb6a99dc1b4868b90f82c551c049a2c33cf1c9c78d98
6
+ metadata.gz: cba311e11d372c3c6b42f530350bd81729102814a24209c63ae37460fc810b638db350afc82b930b5f8623acdc9423182e70489e220247f82c7c89f09efb8b74
7
+ data.tar.gz: a8541982f21133340285977c16852f3bbc41c18f4ce431e5b0261f4d3509f8bdf7f9d3816f500c8401eeac3de7223da39b8f5e008fd9c28e131322d4ab8588ad
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-2020 Yulia Oletskaya, Vladimir Dementyev
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
@@ -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 (see [the documentation](https://docs.anycable.io/#/ruby/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
- BinaryFrame.new(MessagePack.pack(ruby_obj))
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
@@ -9,7 +9,8 @@ require "anycable/rack/socket"
9
9
  module AnyCable
10
10
  module Rack
11
11
  class Middleware # :nodoc:
12
- PROTOCOLS = ["actioncable-v1-json", "actioncable-v1-msgpack", "actioncable-unsupported"].freeze
12
+ PROTOCOLS = %w[actioncable-v1-json actioncable-v1-msgpack actioncable-unsupported actioncable-v1-protobuf].freeze
13
+
13
14
  attr_reader :pinger,
14
15
  :hub,
15
16
  :coder,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AnyCable
4
4
  module Rack
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
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.0
4
+ version: 0.5.0
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: 2021-05-14 00:00:00.000000000 Z
12
+ date: 2022-04-20 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.2.15
208
+ rubygems_version: 3.3.7
207
209
  signing_key:
208
210
  specification_version: 4
209
211
  summary: AnyCable Rack Server