lib/plezi/handlers/ws_identity.rb in plezi-0.12.17 vs lib/plezi/handlers/ws_identity.rb in plezi-0.12.18

- old
+ new

@@ -2,10 +2,12 @@ module Base module WSObject + # Used to emulate the Redis connection when the Identoty API + # is used on a single process with no Redis support. module RedisEmultaion public def lrange key, first, last = -1 sync do return [] unless @cache[key] @@ -57,11 +59,11 @@ @cache[key].push value @cache[key].count end end def expire key, seconds - Iodine.warn "Identity API requires Redis - no persistent storage!" + @warning_sent ||= Iodine.warn "Identity API requires Redis - no persistent storage!".freeze sync do return 0 unless @cache[key] if @timers[key] @timers[key].stop! end @@ -166,15 +168,24 @@ # @!visibility public # returns true if the Identity in question is registered to receive notifications. def registered? identity self.class.registered? identity end + # # handles websocket being closed. + # def on_close + # super if defined? super + # redis = Plezi.redis || ::Plezi::Base::WSObject::RedisEmultaion + # @___identity.each { |identity| redis.lrem "#{identity}_uuid".freeze, 0, uuid } + # end end module ClassMethods end module SuperInstanceMethods protected + + # this is the identity event and ittells the connection to "read" the messages in the "mailbox", + # and forward the messages to the rest of the connections. def ___review_identity identity redis = Plezi.redis || ::Plezi::Base::WSObject::RedisEmultaion identity = identity.to_s.freeze return Iodine.warn("Identity message reached wrong target (ignored).").clear unless @___identity[identity] messages = redis.multi do @@ -190,10 +201,10 @@ next unless msg Iodine.error("Notification recieved but no method can handle it - dump:\r\n #{msg.to_s}") && next unless self.class.has_super_method?(msg[:method]) Iodine.run do targets.each {|target| unicast(target, msg[:method], *msg[:data]) } end - self.method(msg[:method]).call(*msg[:data]) + self.__send__(msg[:method], *msg[:data]) end # ___extend_lifetime identity end # # re-registers the Identity, extending it's lifetime