AutosoftDMS / SignalR-Swift

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

HubProxy on Event listener is not working #48

Open manikantachintapalli9 opened 4 years ago

manikantachintapalli9 commented 4 years ago

On event never listening. Can anyone have solution?

 let qs = [
        "ClientID": urlString
    ]

    hubConnection = HubConnection.init(withUrl: serverUrl, queryString: qs, sessionManager: .default, useDefault: true)

    SignalrHelper.mainShared.chatHub = hubConnection.createHubProxy(hubName: HUB_NAME)

    subscription = SignalrHelper.mainShared.chatHub.on(eventName: EVENT_GET_UPDATED_ORDER_NO) { (args) in
        print("Message: \(args)")
        if args.count > 0 {
            if let str = args[0] as? String, str.count > 0 {
                _ = BL_SAL_Management.UpdateKOTStatus(kOT: str)
            }
        }
    }
    subscription = SignalrHelper.mainShared.chatHub.on(eventName: EVENT_COMPLETE_KOT) { (args) in
        print("Message: \(args)")
        if args.count > 0 {
            if let str = args[0] as? Bool {
                _ = BL_SAL_Management.ClearAllKOT(ClearAll: str)
            }
        }
    }
    subscription = SignalrHelper.mainShared.chatHub.on(eventName: EVENT_CLEAR_ALL_KOT) { (args) in
        print("Message: \(args)")
        if args.count > 0 {
            if let str = args[0] as? Int, str > 0 {
                _ = BL_SAL_Management.fnDownloadSalesOrderForOnlineBilling(webSalesOrderNo: str)
            }
        }
    }

    SignalrHelper.mainShared.chatHub.invoke(method: SUBSCRIBE_TO_KOT_HUB, withArgs: [JBC.getSYSOrgCode() + ":" + "\(JBC.getORGUserOrgBranchID())" + ":" + JBC.getSYSDeviceCode()]) { (response, error) in
        print(response, error)
    }

    // register for connection lifecycle events
    hubConnection.started = {
        print("Connected")
    }
    hubConnection.reconnecting = {
        print("Reconnecting...")
    }
    hubConnection.reconnected = {
        print("Reconnected.")
    }
    hubConnection.closed = {
        print("Disconnected")
        if self.hubConnection != nil {
            self.hubConnection.start()
        }
    }
    hubConnection.connectionSlow = { print("Connection slow...") }
    hubConnection.error = { error in
        let anError = error as NSError
        if anError.code == NSURLErrorTimedOut {
            self.hubConnection.start()
        }
    }
    hubConnection.start()