Class: CableRoom::Room::PortManagement::PortClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cable_room/room/port_management.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(room, token) ⇒ PortClient

Returns a new instance of PortClient.



165
166
167
168
169
170
171
# File 'lib/cable_room/room/port_management.rb', line 165

def initialize(room, token)
  @room = room
  @token = token
  @metadata = HashWithIndifferentAccess.new
  @metadata[:tags] = Set.new
  touch_activity!
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



163
164
165
# File 'lib/cable_room/room/port_management.rb', line 163

def token
  @token
end

Instance Method Details

#<<(data) ⇒ Object



175
176
177
178
179
# File 'lib/cable_room/room/port_management.rb', line 175

def <<(data)
  @room.with_port_scope(client_port: @token) do
    @room.broadcast(data)
  end
end

#merge!(value) ⇒ Object



181
182
183
# File 'lib/cable_room/room/port_management.rb', line 181

def merge!(value)
  @metadata.merge!(value || {})
end

#recently_seen?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/cable_room/room/port_management.rb', line 189

def recently_seen?
  self[:last_seen_at] && self[:last_seen_at] > PORT_TIMEOUT.ago
end

#tag!(*tags) ⇒ Object



197
198
199
# File 'lib/cable_room/room/port_management.rb', line 197

def tag!(*tags)
  self[:tags].merge(tags.flatten.map(&:to_sym))
end

#tagged?(tag) ⇒ Boolean

Returns:

  • (Boolean)


193
194
195
# File 'lib/cable_room/room/port_management.rb', line 193

def tagged?(tag)
  self[:tags].include?(tag)
end

#touch_activity!Object



185
186
187
# File 'lib/cable_room/room/port_management.rb', line 185

def touch_activity!
  self[:last_seen_at] = Time.now
end