Module: CableRoom::Ports

Extended by:
ActiveSupport::Concern
Included in:
Room::Base, RoomMembership
Defined in:
lib/cable_room/ports.rb

Defined Under Namespace

Classes: PortProxy, PortsProxy

Instance Method Summary collapse

Instance Method Details

#close_streamed_ports!Object



24
25
26
27
28
29
# File 'lib/cable_room/ports.rb', line 24

def close_streamed_ports!
  _streamed_ports.each do |port|
    @cable_channel.stop_stream_from(room_port_key(port))
  end
  _streamed_ports.clear
end

#port_transmit(port, data) ⇒ Object



31
32
33
# File 'lib/cable_room/ports.rb', line 31

def port_transmit(port, data)
  ActionCable.server.broadcast(room_port_key(port), data)
end

#portsObject



5
6
7
# File 'lib/cable_room/ports.rb', line 5

def ports
  @ports_proxy ||= PortsProxy.new(self)
end

#stream_port(port, auto_close: true, on_live: nil, &blk) ⇒ Object

Subscribe the channel to port, delivering each decoded message to the block.

on_live, when given, runs once the pubsub adapter has confirmed the subscription — the first moment a message published to the port is guaranteed to reach the block. Subscribing is asynchronous, so anything published before then can be lost.



14
15
16
17
18
19
20
21
22
# File 'lib/cable_room/ports.rb', line 14

def stream_port(port, auto_close: true, on_live: nil, &blk)
  broadcasting = room_port_key(port)
  if on_live
    _stream_from_observing_liveness(broadcasting, on_live, &blk)
  else
    @cable_channel.stream_from(broadcasting, coder: ActiveSupport::JSON, &blk)
  end
  _streamed_ports << port if auto_close
end