lib/plezi/handlers/ws_object.rb in plezi-0.12.14 vs lib/plezi/handlers/ws_object.rb in plezi-0.12.15
- old
+ new
@@ -95,20 +95,23 @@
end
alias :unicast_id :uuid
protected
+ # @!visibility public
# allows writing of data to the websocket (if opened). Otherwise appends the message to the Http response.
def write data
(@ws_io || @response) << data
end
+ # @!visibility public
# Performs a websocket unicast to the specified target.
def unicast target_uuid, method_name, *args
self.class.unicast target_uuid, method_name, *args
end
+ # @!visibility public
# Use this to brodcast an event to all 'sibling' objects (websockets that have been created using the same Controller class).
#
# Accepts:
# method_name:: a Symbol with the method's name that should respond to the broadcast.
# args*:: The method's argumenst - It MUST be possible to stringify the arguments into a YAML string, or broadcasting and unicasting will fail when scaling beyond one process / one machine.
@@ -117,10 +120,12 @@
#
def broadcast method_name, *args
return false unless self.class.has_method? method_name
self.class._inner_broadcast({ method: method_name, data: args, type: self.class}, __get_io )
end
+
+ # @!visibility public
# Use this to multicast an event to ALL websocket connections on EVERY controller, including Placebo controllers.
#
# Accepts:
# method_name:: a Symbol with the method's name that should respond to the broadcast.
# args*:: The method's argumenst - It MUST be possible to stringify the arguments into a YAML string, or broadcasting and unicasting will fail when scaling beyond one process / one machine.
@@ -236,10 +241,10 @@
# WebSockets
# sends the broadcast
def _inner_broadcast data, ignore_io = nil
if data[:target]
- if data[:target] && (data[:to_server] == Plezi::Settings.uuid )
+ if data[:to_server] == Plezi::Settings.uuid
return ( ::Iodine::Http::Websockets.unicast( data[:target], data ) || ___faild_unicast( data ) )
end
return ( data[:to_server].nil? && ::Iodine::Http::Websockets.unicast(data[:target], data) ) || ( Plezi::Base::AutoRedis.away?(data[:to_server]) && ___faild_unicast( data ) ) || __inner_redis_broadcast(data)
else
::Iodine::Http::Websockets.broadcast data, ignore_io