lib/jugglite/app.rb in jugglite-0.1.0 vs lib/jugglite/app.rb in jugglite-0.2.0
- old
+ new
@@ -99,14 +99,15 @@
end
end
def expedite_incoming_message(channel, message)
no_connection_listening = true
+ options = extract_options_from_message(message)
# Select upfront and use EM::Iterator
@subscription_map.each do |connection, channels|
if channels.include?(channel)
- connection.write message
+ connection.write message, options
no_connection_listening = false
end
end
# We stop listening to a channel whenever a message comes in from a channel
# which has no associated connections
@@ -115,8 +116,19 @@
if no_connection_listening
puts "Stop listening to channel: #{channel}"
@async_redis.unsubscribe(channel)
@redis_channels.delete(channel)
end
+ end
+
+ def extract_options_from_message(message)
+ data = JSON.parse(message)
+ options = {}
+ options['event'] = data.delete('event') if data['event']
+ options['id'] = data.delete('id') if data['id']
+ options
+ rescue JSON::ParserError
+ # The message is not valid json, so we are not able to extract options
+ {}
end
end
end