Class: CableRoom::Room::Base
- Inherits:
-
Object
- Object
- CableRoom::Room::Base
- Includes:
- Ports, Broadcasting, Callbacks, ChannelAdapter, InputHandling, Lifecycle, PortManagement, PortScoping, Reaping, Threading, UserManagement
- Defined in:
- lib/cable_room/room/base.rb
Constant Summary collapse
- ROOM_OUT_CHANNEL =
One-to-many: messages the Room broadcasts out to its members
:from_room- ROOM_IN_CHANNEL =
Many-to-one: messages members send in to the Room
:to_room- LOCK_DURATION =
15.seconds
- WATCH_DOG_INTERVAL =
15.seconds
Constants included from PortManagement
Constants included from ChannelAdapter
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
- .ensure(key = nil) ⇒ Object
- .locally_running_instances ⇒ Object
- .room_port_key(room_key, port = nil) ⇒ Object
- .send_message(room_key, data, port: ROOM_IN_CHANNEL) ⇒ Object
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#initialize(vchannel, key = nil) ⇒ Base
constructor
A new instance of Base.
Methods included from Broadcasting
Methods included from UserManagement
#on_user_joined, #on_user_left
Methods included from PortManagement
Methods included from PortScoping
#simplify_port_scope, #with_port_scope, #with_port_scope!, #without_port_scope
Methods included from Threading
Methods included from Ports
#close_streamed_ports!, #port_transmit, #ports, #stream_port
Constructor Details
#initialize(vchannel, key = nil) ⇒ Base
Returns a new instance of Base.
79 80 81 82 83 |
# File 'lib/cable_room/room/base.rb', line 79 def initialize(vchannel, key = nil) super() @key = key @cable_channel = vchannel end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
75 76 77 |
# File 'lib/cable_room/room/base.rb', line 75 def key @key end |
Class Method Details
.ensure(key = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cable_room/room/base.rb', line 11 def ensure(key = nil) lock_key = room_port_key(key) lock_info = CableRoom.lock_manager.lock(lock_key, self::LOCK_DURATION.in_milliseconds) return false unless lock_info vchannel = self::Channel.new( lock_info, self, key, { watchdog_interval: self::WATCH_DOG_INTERVAL, lock_duration: self::LOCK_DURATION, } ) vchannel.subscribe_to_channel true rescue => e CableRoom.lock_manager.unlock(lock_info) if lock_info raise e end |
.locally_running_instances ⇒ Object
43 44 45 46 47 |
# File 'lib/cable_room/room/base.rb', line 43 def locally_running_instances ChannelTracker.instance.room_channels.select do |chan| chan.room_class == self end.map(&:room) end |
.room_port_key(room_key, port = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/cable_room/room/base.rb', line 33 def room_port_key(room_key, port = nil) full_key = [room_key] full_key << port if port self::Channel.broadcasting_for(full_key) end |
.send_message(room_key, data, port: ROOM_IN_CHANNEL) ⇒ Object
39 40 41 |
# File 'lib/cable_room/room/base.rb', line 39 def (room_key, data, port: ROOM_IN_CHANNEL) ActionCable.server.broadcast(room_port_key(room_key, port), data) end |
Instance Method Details
#<<(data) ⇒ Object
85 86 87 |
# File 'lib/cable_room/room/base.rb', line 85 def <<(data) port_transmit(ROOM_OUT_CHANNEL, data) end |