AS-Devs / signalr_flutter

A flutter plugin for .net SignalR client.
https://pub.dev/packages/signalr_flutter
MIT License
19 stars 27 forks source link

hubCallback method not working in flutter android and .net signalr2 #38

Open Zafoid opened 3 years ago

Zafoid commented 3 years ago

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);
        }
    }
}
rsyd29 commented 2 years ago

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

gongwangjie commented 5 months ago

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