Class: Loco::Broadcaster

Inherits:
Object
  • Object
show all
Defined in:
lib/loco/broadcaster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/loco/broadcaster.rb', line 5

def data
  @data
end

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/loco/broadcaster.rb', line 5

def event
  @event
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



5
6
7
# File 'lib/loco/broadcaster.rb', line 5

def notifications
  @notifications
end

#objObject (readonly)

Returns the value of attribute obj.



5
6
7
# File 'lib/loco/broadcaster.rb', line 5

def obj
  @obj
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



5
6
7
# File 'lib/loco/broadcaster.rb', line 5

def recipients
  @recipients
end

Instance Method Details

#emitObject



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

#prepareObject



22
23
24
25
# File 'lib/loco/broadcaster.rb', line 22

def prepare
  init_notifications if notifications.empty?
  prepare_notifications
end

#signalsObject



18
19
20
# File 'lib/loco/broadcaster.rb', line 18

def signals
  notifications
end