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

roomChannel.onReceive method not getting called

mansishah278 opened this issue · comments

I am sending two parameters while creating the roomChannel and it is successfully subscribed, so onSubscribed is called but I am not able to receive messages, i.e onReceive method is not getting called.
@danielrhodes

     client.onConnected = {

        // Create the Room Channel
        let parameters = [
            "token": token,
            "id": aID
        ]
        let roomChannel = client.create("myRoom", identifier: parameters, autoSubscribe: true, bufferActions: true)
        
        // Channel callbacks
        roomChannel.onReceive = { dict in
            print(dict)
        }
        roomChannel.onSubscribed = {
            print("subscribed")
        }
        roomChannel.onUnsubscribed = {
            print("Unsubscribed")
        }
        roomChannel.onRejected = {
            print("Rejected")
        }
        
    }

I'm having the same issue. @mansishah278 Did you solve this issue? Thanks

@ngbsoftware Nope, I am not able to solve it

@ngbsoftware @mansishah278 Are you both using identifier parameters when creating the channel? If you don't include these parameters, does it work? From what I've seen in the past, the parameters included when creating a channel make that combination unique. Therefore, to send a message that will be received by that channel, you would have to send a message to that channel with those parameters.

@danielrhodes
1 - yes I am using identifier params
It was observed as you stated, any how we could not pass same identifier params while sending message to the channel but got a work around for it

So concluding, to receive data in onReceive method, we need to send message to the channel with the same identifier params that we used while subscribing. Thanks 👍