Class: Glib::Channel::OnlineChannel

Inherits:
ApplicationCable::Channel
  • Object
show all
Defined in:
app/channels/glib/channel/online_channel.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.channel_nameObject

Returns the value of attribute channel_name.



5
6
7
# File 'app/channels/glib/channel/online_channel.rb', line 5

def channel_name
  @channel_name
end

Instance Method Details

#channel_nameObject



8
9
10
# File 'app/channels/glib/channel/online_channel.rb', line 8

def channel_name
  self.class.channel_name
end

#online_status(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/channels/glib/channel/online_channel.rb', line 16

def online_status(data)
  if data['status'] == true
    text = "#{User.find(data['user_id']).full_name} is online"
  else
    text = "#{User.find(data['user_id']).full_name} is offline"
  end

  ActionCable.server.broadcast \
    "#{self.class.channel_name}_#{params['conversation_id']}",
    action: {
      action: 'component/set',
      text: text,
      status: data['status'],
      value: data['reset_value'],
      event: 'online_status'
    },
    filterKey: data['user_id']
end

#subscribedObject



12
13
14
# File 'app/channels/glib/channel/online_channel.rb', line 12

def subscribed
  stream_from "#{self.class.channel_name}_#{params['conversation_id']}"
end