danielrhodes / Swift-ActionCableClient

ActionCable is a new WebSocket server being released with Rails 5 which makes it easy to add real-time features to your app. This Swift client makes it dead-simple to connect with that server, abstracting away everything except what you need to get going.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onConnect is not being called

waleedmahmood opened this issue · comments

Hi,
I have a this simple connection function

`func initializeActionCabel()
{
self.client = ActionCableClient(url: URL(string: "ws://ip.of.my.server:3000.tld/cable")!)

    self.client.willConnect = {
        print("Will Connect")
    }
    
    self.client.onConnected = {
        print("Action Cable Connected!")
        self.channel = self.client.create("ChatChannel")
    }
    
    self.client.onDisconnected = {(error: ConnectionError?) in
        print("Action Cable Disconnected! \(error.debugDescription)")
    }
    
    self.client.onRejected = {
        print("Action Cable Connection Rejected!")
    }
    
    self.client.willReconnect = {
        print("Reconnecting to \(self.client.url)")
        return true
    }
    
    self.client.onPing = {
        print("On Ping")
    }
    
    self.channel?.onSubscribed = {
        print("Subscribed to 'ChatChannel'")
    }
    
    self.channel?.onReceive = {(data: Any?, error: Error?) in
        print("On Receive")
        if let _ = error {
            print(error)
            return
        }
    }
    
    // Connect!
    self.client.connect()
}`

Problem is: willReconnect and onDisconnected are being called just fine. But onConnected callback is not called ever.

Can you please comment or see if i'm missing something? Thanks in advance.

Cheers.

We are having a similar issue - is there any resolution?

In my case there was some thing wrong on our server side setup. What i did was to connect to a public url as follows:
ws://actioncable-echo.herokuapp.com/cable
This actually made sure that, everything was working on Client side.