@@ -204,23 +204,23 @@ extension ActionCableClient {
204204 @warn_unused_result ( message= " You must hold on to the Channel returned from a create(_:) " )
205205 public func create( name: String , identifier: ChannelIdentifier ? , autoSubscribe: Bool = true , bufferActions: Bool = true ) -> Channel {
206206 // Look in existing channels and return that
207- if let channel = channels [ name] {
208- return channel
209- }
207+ if let channel = channels [ name] { return channel }
210208
211209 // Look in unconfirmed channels and return that
212- if let channel = unconfirmedChannels [ name] {
213- return channel
214- }
210+ if let channel = unconfirmedChannels [ name] { return channel }
215211
216212 // Otherwise create a new one
217213 let channel = Channel ( name: name,
218214 identifier: identifier,
219215 client: self ,
220216 autoSubscribe: autoSubscribe,
221217 shouldBufferActions: bufferActions)
222-
218+
223219 self . unconfirmedChannels [ name] = channel
220+
221+ if ( channel. autoSubscribe) {
222+ subscribe ( channel)
223+ }
224224
225225 return channel
226226 }
@@ -240,11 +240,12 @@ extension ActionCableClient {
240240
241241 internal func subscribe( channel: Channel ) {
242242 // Is it already added and subscribed?
243- if let existingChannel = channels [ channel. name] where ( existingChannel == channel) && ( existingChannel . subscribed ) {
243+ if let existingChannel = channels [ channel. name] where ( existingChannel == channel) {
244244 return
245245 }
246246
247- unconfirmedChannels. updateValue ( channel, forKey: channel. name)
247+ guard let channel = unconfirmedChannels [ channel. name]
248+ else { debugPrint ( " [ActionCableClient] Internal inconsistency error! " ) ; return }
248249
249250 do {
250251 try self . transmit ( channel, command: Command . Subscribe, data: nil )
0 commit comments