Class: Loco::Broadcaster
- Inherits:
-
Object
- Object
- Loco::Broadcaster
- Defined in:
- lib/loco/broadcaster.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#recipients ⇒ Object
readonly
Returns the value of attribute recipients.
Instance Method Summary collapse
- #emit ⇒ Object
-
#initialize(obj, event = nil, opts = {}) ⇒ Broadcaster
constructor
A new instance of Broadcaster.
- #prepare ⇒ Object
- #signals ⇒ Object
Constructor Details
#initialize(obj, event = nil, opts = {}) ⇒ Broadcaster
Returns a new instance of Broadcaster.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/loco/broadcaster.rb', line 5 def initialize obj, event = nil, opts = {} recipient_key = opts[:for] ? :for : :to @obj = obj @event = event @recipients = opts[recipient_key] ? [*opts[recipient_key]] : [nil] @data = opts[:data] @notifications = [] @sent_via_ws = 0 @connected_resources_manager = WsConnectedResourcesManager.new @recipients.compact end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/loco/broadcaster.rb', line 3 def data @data end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
3 4 5 |
# File 'lib/loco/broadcaster.rb', line 3 def event @event end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
3 4 5 |
# File 'lib/loco/broadcaster.rb', line 3 def notifications @notifications end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
3 4 5 |
# File 'lib/loco/broadcaster.rb', line 3 def obj @obj end |
#recipients ⇒ Object (readonly)
Returns the value of attribute recipients.
3 4 5 |
# File 'lib/loco/broadcaster.rb', line 3 def recipients @recipients end |
Instance Method Details
#emit ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/loco/broadcaster.rb', line 23 def emit init_notifications if notifications.empty? send_notifications if notify_about_xhr_notifications? notify_about_xhr_notifications else set_sync_time_via_ws end end |
#prepare ⇒ Object
18 19 20 21 |
# File 'lib/loco/broadcaster.rb', line 18 def prepare init_notifications if notifications.empty? prepare_notifications end |
#signals ⇒ Object
16 |
# File 'lib/loco/broadcaster.rb', line 16 def signals; notifications end |