lib/plezi/controller/controller_class.rb in plezi-0.14.9 vs lib/plezi/controller/controller_class.rb in plezi-0.15.0

- old
+ new

@@ -5,56 +5,17 @@ # A Ruby callback used to initialize class data for new Controllers. def self.extended(base) base._pl_init_class_data end + # Publishes a message to a channel. + def publish(args) + Iodine.publish args + end + # Returns a relative URL for the controller, placing the requested parameters in the URL (inline, where possible and as query data when not possible). def url_for(func, params = {}) ::Plezi::Base::Router.url_for self, func, params - end - - # Invokes a method on the `target` websocket connection. When using Iodine, the method is invoked asynchronously. - # - # self.unicast target, :my_method, "argument 1" - # - # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid. - def unicast(target, event_method, *args) - ::Plezi::Base::MessageDispatch.unicast(self, target, event_method, args) - end - - # Invokes a method on every websocket connection that belongs to this Controller / Type. When using Iodine, the method is invoked asynchronously. - # - # self.broadcast :my_method, "argument 1", "argument 2", 3 - # - # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid. - def broadcast(event_method, *args) - ::Plezi::Base::MessageDispatch.broadcast(self, event_method, args) - end - - # Invokes a method on every websocket connection in the application. - # - # self.multicast :my_method, "argument 1", "argument 2", 3 - # - # Methods invoked using {unicast}, {broadcast} or {multicast} will quitely fail if the connection was lost, the requested method is undefined or the 'target' was invalid. - def multicast(event_method, *args) - ::Plezi::Base::MessageDispatch.multicast(self, event_method, args) - end - # Writes a message to every client websocket connection in all controllers(!). Accepts an optional filter method using a location reference for a *static* (Class/Module/global) method. The filter method will be passerd the websocket object and it should return `true` / `false`. - # - # self.write2everyone {event: "global", message: "This will be sent to everyone"}.to_json - # # or, we can define a filter method somewhere in our code - # module Filter - # def self.should_send? ws - # true - # end - # end - # # and we can use this filter method. - # data = {event: "global", message: "This will be sent to everyone"}.to_json - # self.write2everyone data, ::Filter, :should_send? - # - # It's important that the filter method is defined statically in our code and isn't dynamically allocated. Otherwise, scaling the application would be impossible. - def write2everyone(data, filter_owner = nil, filter_name = nil) - ::Plezi::Base::MessageDispatch.write2everyone(self, data, filter_owner, filter_name) end # @private # This is used internally by Plezi, do not use. RESERVED_METHODS = [:delete, :create, :update, :new, :show, :pre_connect, :on_open, :on_close, :on_shutdown, :on_message].freeze