AutosoftDMS / SignalR-Swift

SignalR client library written in pure Swift
MIT License
60 stars 55 forks source link

Calling HubProxy.invoke handler returns( Nil, Nil) #28

Closed russnettle closed 6 years ago

russnettle commented 6 years ago

Hey,

Thanks for taking the time to port this lib, I was looking to migrate away from the SwiftR framework to use something non dependant on webviews etc. However I am facing an issue when calling invoke - the handler appears to be called twice, bit both times the value for data and error are nil here's how I am attempting to use signalR.

var chatHub: HubProxy!
        var connection: HubConnection!
        connection = HubConnection(withUrl: "SERVER") 
      connection.signalRVersion = .v2_2_0

        chatHub = self.connection.createHubProxy(hubName: "HUBNAME")
        _ = chatHub.on(eventName: "SUBSCIPTIONNAME") { (args) in
            if let name = args[0] as? String, let message = args[1] as? String, let text = self.chatTextView.text {
                self.chatTextView.text = "\(text)\n\n\(name): \(message)"
            }
        }

        // SignalR events

        connection.started = { [unowned self] in
            print("Connection ID: \(self.connection!.connectionId!)")
            self.chatHub.invoke(method: "METHOD", withArgs: ["CHANNEL"], completionHandler: { (data, error) in

                //DATA ALWAYS NIL
//ERROR ALWAYS NIL :(

            })

I saw another issue someone mentioned the first call being nil, but I am seeing both nil always. Any help would be appreciated, particularly if the call order etc is incorrect for this lib (as mentioned this works in another signalR lib)

Thanks!

vldalx commented 6 years ago

Hi take a look at the similar old issue

russnettle commented 6 years ago

@vldalx thanks for the reply - the issue is similar, unfortunately it is always nil and never receives a response with data

vldalx commented 6 years ago

@russnettle you can check if the library receives any data from your backend there is the method https://github.com/AutosoftDMS/SignalR-Swift/blob/81fb366a856b33865c3fbf28d9edce289155d364/SignalR-Swift/Transports/WebSocketTransport.swift#L182 just add print(text) or set a breakpoint here. if it is invoked and text parameter is not empty, then you can verify either the data format is wrong or the library is not able to handle it

russnettle commented 6 years ago

@vldalx looks like the first response is an error message - which as per prev bug gets missed - subsequent calls are then empty

russnettle commented 6 years ago

Unfortunately the error message is {"I":"0","E":"There was an error invoking Hub method 'streaming.subscribe'."} Which is strange as I have an identical project uses the SwiftR framework and is able to invoke the method fine.

vldalx commented 6 years ago

Double check your code and the transmitted data. I use this library in my chat app. Everything is worked. I had used SignalR-ObjC before I replaced the one with SignalR-Swift. The code on the backend remained unchanged.

russnettle commented 6 years ago

Hi @vldalx thanks - was a silly mistake - the arguments needed to be an array of arrays [[String]], cannot believe I missed this!