cable_room 0.6.2.beta6 → 0.6.2.beta8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 696d25532db9edfcb2be4c2f47c83b12bc8d9421a4ce8325fbf734eaa113e643
4
- data.tar.gz: 2b7271965c820705aa1cef7ac8069b9902195f0c6aad6c1eb66487aa42786c15
3
+ metadata.gz: cf9bc187f61f47429b4f6d19591ae11f9ce5adc4f3e631a386543c5a4be3d31f
4
+ data.tar.gz: 7ea623c7bce5023f7eef8e9f70c7fd723dd6d4c83ffdff6e0e636bcf4a0c2085
5
5
  SHA512:
6
- metadata.gz: b8af7d51b5dcbe71a34f5d337f045648c869571aa425b2830f5c63d025d2342f47460333f8416501922f46ee268a1a32463b42b9d73f84241d1ae63c08a92b2b
7
- data.tar.gz: ab5652c45720db80ad9983fd953d2c94cab7faeae99b049732724a323a774b203e1ed49b8e96ad704d872ee920aeb7fec0f47c6802f2bc531290478aea0765f8
6
+ metadata.gz: 3ea7801344b227a3db243d32aa569427a2e721adb2c4e8894ff803834a6e60392a064cac0b9f2bf21257936109b472d99f994bb82eec3387aa490d1cf7260c1b
7
+ data.tar.gz: b0d7b8b7b054d5a45290df64691e919a9ac8d951beb06df38edf799e3c81bb955ca5444b490293fb4d20d0a09759dc4b8122334d2d041ebf52e6bbd23486d8cf
@@ -118,10 +118,7 @@ module CableRoom
118
118
  def handle_received_message(message)
119
119
  case message['type']
120
120
  when 'port_connected'
121
- mo = @_port_clients[@current_message_origin]
122
- return if mo
123
-
124
- mo = @_port_clients[@current_message_origin] = PortClient.new(self, @current_message_origin)
121
+ mo = @_port_clients[@current_message_origin] ||= PortClient.new(self, @current_message_origin)
125
122
 
126
123
  mo.touch_activity!
127
124
  mo.tag!(message['tags'])
@@ -51,7 +51,13 @@ module CableRoom
51
51
 
52
52
  def transmit_subscription_confirmation(...)
53
53
  super
54
- _room_memberships.each(&:transmit_port_connected)
54
+ # Rails invokes this from the pubsub adapter's subscribe success callback, which runs while
55
+ # SubscriberMap holds its (non-reentrant) @sync mutex. Broadcasting from that stack raises
56
+ # ThreadError: deadlock; recursive locking, and the adapter swallows it. Defer onto the event
57
+ # loop so the announce still happens after every stream is confirmed live, but off the lock.
58
+ memberships = _room_memberships.to_a
59
+ memberships.each(&:streams_live!)
60
+ connection.server.event_loop.post { memberships.each(&:transmit_port_connected) }
55
61
  end
56
62
  end
57
63
 
@@ -78,6 +84,7 @@ module CableRoom
78
84
 
79
85
  @has_left = false
80
86
  @has_established = false
87
+ @streams_live = false
81
88
 
82
89
  @cable_channel = cable_channel
83
90
  @room_class = room_class
@@ -146,6 +153,21 @@ module CableRoom
146
153
 
147
154
  def key; @room_key; end
148
155
 
156
+ # @internal
157
+ def streams_live!
158
+ @streams_live = true
159
+ end
160
+
161
+ # @internal
162
+ def transmit_port_connected
163
+ msg = {
164
+ type: 'port_connected',
165
+ tags: @tags,
166
+ }
167
+ msg[:extra] = ::ActiveJob::Arguments.serialize([@extra]) if @extra
168
+ port_transmit(room_class::ROOM_IN_CHANNEL, msg, secure_context: true)
169
+ end
170
+
149
171
  protected
150
172
 
151
173
  def port_transmit(port, data, secure_context: false)
@@ -186,7 +208,10 @@ module CableRoom
186
208
  @has_established = true
187
209
  @on_joined&.call(self) if first_acknowledgement
188
210
  when 'room_opened'
189
- transmit_port_connected
211
+ # Only safe once our own streams are confirmed; otherwise the room may acknowledge on the
212
+ # private port before anyone is listening. If we are not live yet, the subscription
213
+ # confirmation hook will announce for us.
214
+ transmit_port_connected if @streams_live
190
215
  @on_room_opened&.call(self)
191
216
  when 'room_closed'
192
217
  leave!
@@ -233,21 +258,14 @@ module CableRoom
233
258
 
234
259
  @preconfigure&.call(self)
235
260
 
236
- # transmit_port_connected
261
+ # Announcing here races the async stream subscriptions: the room can acknowledge on the
262
+ # private port before it is live and the ack is lost. transmit_subscription_confirmation
263
+ # announces instead, once every stream is confirmed.
237
264
 
238
265
  maybe_provision_room
239
266
  end
240
267
  end
241
268
 
242
- def transmit_port_connected
243
- msg = {
244
- type: 'port_connected',
245
- tags: @tags,
246
- }
247
- msg[:extra] = ::ActiveJob::Arguments.serialize([@extra]) if @extra
248
- port_transmit(room_class::ROOM_IN_CHANNEL, msg, secure_context: true)
249
- end
250
-
251
269
  def maybe_provision_room
252
270
  return if left?
253
271
  return unless @allow_create
@@ -1,3 +1,3 @@
1
1
  module CableRoom
2
- VERSION = "0.6.2.beta6".freeze
2
+ VERSION = "0.6.2.beta8".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2.beta6
4
+ version: 0.6.2.beta8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Knapp