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.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/loco/broadcaster.rb', line 7 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 @conn_res_manager = WsConnectedResourcesManager.new @recipients.compact end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/loco/broadcaster.rb', line 5 def data @data end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
5 6 7 |
# File 'lib/loco/broadcaster.rb', line 5 def event @event end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
5 6 7 |
# File 'lib/loco/broadcaster.rb', line 5 def notifications @notifications end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
5 6 7 |
# File 'lib/loco/broadcaster.rb', line 5 def obj @obj end |
#recipients ⇒ Object (readonly)
Returns the value of attribute recipients.
5 6 7 |
# File 'lib/loco/broadcaster.rb', line 5 def recipients @recipients end |
Instance Method Details
#emit ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/loco/broadcaster.rb', line 27 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
22 23 24 25 |
# File 'lib/loco/broadcaster.rb', line 22 def prepare init_notifications if notifications.empty? prepare_notifications end |
#signals ⇒ Object
18 19 20 |
# File 'lib/loco/broadcaster.rb', line 18 def signals notifications end |