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.



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

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

Instance Attribute Details

#token ⇒ Object (readonly)

Returns the value of attribute token.



174
175
176
# File 'lib/cable_room/room/port_management.rb', line 174

def token
  @token
end

Instance Method Details

#<<(data) ⇒ Object



186
187
188
189
190
# File 'lib/cable_room/room/port_management.rb', line 186

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

#merge!(value) ⇒ Object



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

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

#recently_seen? ⇒ Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/cable_room/room/port_management.rb', line 200

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

#tag!(*tags) ⇒ Object



208
209
210
# File 'lib/cable_room/room/port_management.rb', line 208

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

#tagged?(tag) ⇒ Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/cable_room/room/port_management.rb', line 204

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

#touch_activity! ⇒ Object



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

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