Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pusher Swift not listening to events at all #441

Open
AdeifeTaiwo opened this issue Dec 23, 2024 · 0 comments
Open

Pusher Swift not listening to events at all #441

AdeifeTaiwo opened this issue Dec 23, 2024 · 0 comments

Comments

@AdeifeTaiwo
Copy link

Steps to reproduce

class SocketManager : PusherDelegate {
private var pusher: Pusher?
@published var receivedMessage: String = ""

init() {
    
    let options = PusherClientOptions(
        authMethod: AuthMethod.inline(secret: "XXXX"),
        autoReconnect: true,
        host: .host("XXXXX"),
        useTLS: true
        
)
    
    self.pusher = Pusher(key: "XXXX", options: options)
    self.pusher?.connection.delegate = self
    
    
    self.pusher?.connect()
    
    initPusher()
    
    
    
}

func changedConnectionState(from old: ConnectionState, to new: ConnectionState) {
    print("Connection state changed from \(old.stringValue()) to \(new.stringValue())")
}

func failedToSubscribeToChannel(name: String, response: URLResponse?, data: String?, error: NSError?){
    print("\(name) \(response.debugDescription) data: \(data) error: \(error)")
}

func receivedError(error: PusherError) {
    print("Received error: \(error.message)")
}

func debugLog(message: String) {
    print("Pusher Debug: \(message)")
}

func initPusher(){}

func subscribeToChannel(reference: String){
    
    
   
    // Subscribe to a channel
    var channel = pusher!.subscribe(reference)
    
    
    pusher?.connection.delegate = self
    print("about to subscribe")
    
    // Bind to an event
    channel.bind(eventName: "pending") { [weak self] event in
        if let data = event.data {
            self?.receivedMessage = data
            DispatchQueue.main.async {
                self?.receivedMessage = data
                print(data)
            }
        }
    }
    
    // Bind to an event
    channel.bind(eventName: "failed") { [weak self] event in
        if let data = event.data {
            self?.receivedMessage = data
            DispatchQueue.main.async {
                self?.receivedMessage = data
                print(data)
            }
        }
    }
    // Bind to an event
    channel.bind(eventName: "completed") { [weak self] event in
        if let data = event.data {
            self?.receivedMessage = data
            DispatchQueue.main.async {
                self?.receivedMessage = data
                print(data)
            }
        }
    }
    
    
    
    channel.bind(eventName: "pending", eventCallback: { event in
           print("Event received: \(event.eventName), Data: \(String(describing: event.data))")
       })
    
    
    channel.trigger(eventName: "pending", data: ["message" : "Event received"])

    self.pusher?.connect()
    
}

}

What must I do to reproduce the bug?
Do the above to reproduce the bug and

Expected behavior

Its meant to listen to events such as pending, failed, and completed and print out data, however it doesnt, and breakpoint doesnt also get into it

Actual behavior

Pusher Debug: [PUSHER DEBUG] Subscription succeeded event received without data key in payload
Pusher Debug: [PUSHER DEBUG] websocketDidReceiveMessage {"event":"pusher_internal:subscription_succeeded","channel":"AlPwdDx7rRVSR0jsBa04fJ9iMDz1Qb9Ghb6X"}
Pusher Debug: [PUSHER DEBUG] Subscription succeeded event received without data key in payload
Pusher Debug: [PUSHER DEBUG] Ping sent
Pusher Debug: [PUSHER DEBUG] Ping sent
Pusher Debug: [PUSHER DEBUG] Websocket received pong
Pusher Debug: [PUSHER DEBUG] Websocket received pong
Pusher Debug: [PUSHER DEBUG] Ping sent
Pusher Debug: [PUSHER DEBUG] Ping sent
Pusher Debug: [PUSHER DEBUG] Websocket received pong
Pusher Debug: [PUSHER DEBUG] Websocket received pong

I only receive events from pusher_internal:subscription_succeeded

Any improvements you suggest

Why isnt it listening to my public event, it is working on Android listening to this events, so i know it is working

I wait your feedback

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant