Module: CableRoom::Room::PortManagement

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/cable_room/room/port_management.rb

Defined Under Namespace

Classes: PortClient

Constant Summary collapse

PORT_TIMEOUT =
30.seconds

Instance Method Summary collapse

Instance Method Details

#_apply_port_scope(client_port: nil, tag: nil, **kwargs) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/cable_room/room/port_management.rb', line 51

def _apply_port_scope(client_port: nil, tag: nil, **kwargs)
  if client_port && tag
    client_port = resolve_client_port(client_port)
    throw :abort unless client_port && (client_port[:tags]&.include?(tag) || client_port[:as] == tag)
  end

  { client_port: client_port || tag, **kwargs }
end

#initializeObject



46
47
48
49
# File 'lib/cable_room/room/port_management.rb', line 46

def initialize(...)
  super
  @_port_clients = {}
end

#reply(message = nil, **kwargs) ⇒ Object

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cable_room/room/port_management.rb', line 60

def reply(message = nil, **kwargs)
  raise ArgumentError, "Can only use reply when handling a message" unless message_origin
  raise ArgumentError, "Must provide message or block" unless message || block_given?
  raise ArgumentError, "Cannot specify client_port: when using reply" if kwargs.key?(:client_port)

  if block_given?
    with_port_scope(client_port: message_origin) do
      yield
    end
  else
    broadcast(message, **kwargs, client_port: message_origin)
  end
end