adamhartford / SwiftR

Swift client for SignalR (iOS and Mac)
MIT License
174 stars 74 forks source link

hub.invoke(...) Won't handle any response. #111

Open F-Forget opened 6 years ago

F-Forget commented 6 years ago

Hi! 😄

First of all, I want to say thanks to @adamhartford for giving us this amazing Signal R wrapper!

Alright, I’m really stuck with something here. I need to handle a response from my C# server that return an IEnumerable of Guid (IEnumerable). Here’s my code:

    do {
        if let hub = drawView.drawingHub {

            try hub.invoke("AddStrokes", arguments: [[strokeDataDictionary]]) { (result, error) in
                if let e = error {
                    print("Error: \(e)")
                } else {
                    print("Success!")
                    if let r = result {
                        // Assing Stroke Is's...
                        // currentStroke.Id = result...
                    }
                }
            }
        }
    }
    catch {
        //handle error
        print(error)
    }

After trying couple of times, my code after the invoke is never getting called, even if my server returns an answer on is the side.

Does anyone have any advice? I know my server is working find on other C# clients. After debugging on the server side, I should correctly return a List of GUIDs. For debugging purposes, here’s my server code:

    public IEnumerable<Guid> AddStrokes(List<StrokeData> strokes)
    {
        string drawingSession = DrawingSessionService.Instance.GetCurrentDrawingSession(Context.ConnectionId);
        if(!String.IsNullOrEmpty(drawingSession))
        {
            List<Guid> strokeGuids = new List<Guid>();
            foreach(StrokeData stroke in strokes)
            {
                if (stroke.Id == Guid.Empty)
                {
                    stroke.Id = Guid.NewGuid();
                }
                strokeGuids.Add(stroke.Id);
            }
            DrawingSessionService.Instance.GetDrawingData(drawingSession)?.AddStrokes(strokes);
            Clients.Group(drawingSession, Context.ConnectionId).AddStrokes(strokes);
            return strokeGuids;
        }
        return null;
    }

Does anyone have any idea?

Thank you very much!