signalr_flutter icon indicating copy to clipboard operation
signalr_flutter copied to clipboard

hubCallback method not working in flutter android and .net signalr2

Open Zafoid opened this issue 3 years ago • 2 comments

I am having some problems getting the hub callback method to trigger in flutter.

I am able to connect to the signalr server and send a message to the server, but on the broadcastMessage it does not hit the flutter client hubcallback.

Please see my code below.

Flutter / Android:

Future<void> initPlatformState() async {
    signalR = SignalR(
        "ServerURL",
        "ChatHub",
        hubMethods: ["broadcastMessage"],
        statusChangeCallback: _onStatusChange,
        hubCallback: _onNewMessage);
  }

_onNewMessage(String? methodName, dynamic message) {
    print('MethodName = $methodName, Message = $message');
  }

_buttonTapped() async {
    await signalR.invokeMethod("Send", arguments: <dynamic>["Name", "Message"]).catchError((error) {
      print(error.toString());
    });
  }

ChatHub Server :

using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace SignalRChat
{
    public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(name, message);
        }
    }
}

Zafoid avatar Sep 08 '21 09:09 Zafoid

I also have the same problem, do you have a solution? @Zafoid

rsyd29 avatar Dec 20 '21 08:12 rsyd29

I also have the same problem, but everything is normal in the debug environment, and the release version received hubCallback @AyonAB @Zafoid @rsyd29 @mohas

gongwangjie avatar Apr 18 '24 15:04 gongwangjie