cable_room 0.7.0.beta3 → 0.8.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/cable_room.gemspec CHANGED
@@ -18,17 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.summary = "Build live Rooms on top of ActionCable"
19
19
  spec.homepage = "https://instructure.com"
20
20
 
21
- spec.files = Dir["{app,config,db,exe,lib}/**/*", "README.md", "CHANGELOG.md", "*.gemspec"]
22
- spec.bindir = "exe"
23
- spec.executables = ["cable_room"]
21
+ spec.files = Dir["{app,config,db,lib}/**/*", "README.md", "*.gemspec"]
24
22
  spec.require_paths = ['lib']
25
23
 
26
24
  spec.add_dependency "rails", ">= 7.2", "< 9.0"
27
25
  spec.add_dependency "rufus-scheduler", "~> 3.6"
28
26
  spec.add_dependency "redlock", "~> 2.0"
29
27
  spec.add_dependency "rediconn", "~> 0.1.2"
30
- # rediconn builds pools of redis-rb clients but doesn't declare the gem; the Bus needs it too
31
- spec.add_dependency "redis", ">= 5.0"
32
28
 
29
+ spec.add_development_dependency "redis"
33
30
  spec.add_development_dependency 'rspec', '~> 3'
34
31
  end
@@ -0,0 +1,35 @@
1
+ module CableRoom
2
+ class Host
3
+ # How rooms receive messages: straight off ActionCable's pubsub adapter, on the same stream
4
+ # names members publish to (Room::Base.room_port_key). This is the only place the room side
5
+ # touches ActionCable for inbound traffic; anything with the same two methods can be handed to
6
+ # `Host.new(inbound:)`.
7
+ #
8
+ # `subscribe` returns a handle that `unsubscribe` needs back. Handlers receive the payload
9
+ # exactly as published (a JSON string, for ActionCable) on the adapter's own thread, so they
10
+ # must be quick and hand the real work off. Host::Runner does that by queueing it on the room.
11
+ # `on_live` runs on that same thread once the adapter confirms the subscription.
12
+ class ActionCableInbound
13
+ # Subscribes from the calling thread. ActionCable's own stream_from posts the subscribe to
14
+ # the event loop first, but the adapter registers asynchronously either way, so that extra
15
+ # hop only widens the window in which the room can't hear anything.
16
+ #
17
+ # The adapter calls `on_live` while holding its own subscriber-map lock, so it must never
18
+ # wait on anything that might be waiting on the adapter (a room's mutex, say).
19
+ def subscribe(stream, on_live: nil, &on_message)
20
+ server.pubsub.subscribe(stream, on_message, on_live)
21
+ on_message
22
+ end
23
+
24
+ def unsubscribe(stream, handle)
25
+ server.pubsub.unsubscribe(stream, handle)
26
+ end
27
+
28
+ private
29
+
30
+ def server
31
+ ActionCable.server
32
+ end
33
+ end
34
+ end
35
+ end