lib/submodules/ably-ruby/lib/ably/rest/channel.rb in ably-rest-1.1.6 vs lib/submodules/ably-ruby/lib/ably/rest/channel.rb in ably-rest-1.1.7
- old
+ new
@@ -21,10 +21,11 @@
# @return [Ably::Rest::Channel::PushChannel]
# @api private
attr_reader :push
IDEMPOTENT_LIBRARY_GENERATED_ID_LENGTH = 9 # See spec RSL1k1
+ MAX_MESSAGE_SIZE = 65536 # See spec TO3l8
# Initialize a new Channel object
#
# @param client [Ably::Rest::Client]
# @param name [String] The name of the channel
@@ -83,10 +84,16 @@
# RSL1h - attributes as an extra method parameter is extra-spec but need to
# keep it for backcompat until version 2
[[{ name: first, data: second }.merge(third)], nil]
end
- payload = messages.each_with_index.map do |message, index|
+ messages.map! { |message| Ably::Models::Message(message.dup) }
+
+ if messages.sum(&:size) > Ably::Rest::Channel::MAX_MESSAGE_SIZE
+ raise Ably::Exceptions::MaxMessageSizeExceeded.new("Maximum message size exceeded #{Ably::Rest::Channel::MAX_MESSAGE_SIZE}.")
+ end
+
+ payload = messages.map do |message|
Ably::Models::Message(message.dup).tap do |msg|
msg.encode client.encoders, options
next if msg.client_id.nil?
if msg.client_id == '*'