0

I am trying to implement Group using signal r I am able to join the group but not receiving a callback in javascript

Here is my Hub

  public class ChatHub : Hub
{
    public void Send(string name, string message)
    {
         Clients.Group("Group1").message(name, message);
    }
    public void Join(string groupName,string id)
    {
       Groups.Add(id, groupName);
    }
    public override Task OnDisconnected(bool stopCalled)
    {

        return base.OnDisconnected(stopCalled);
    }
    public override Task OnConnected()
    {
        return base.OnConnected();
    }
    public override Task OnReconnected()
    {
        return base.OnReconnected();
    }
}

And Here is my Javascript

  $(document).ready(function () {
        var _name = window.prompt("Enter Your Name");
        //I am giving Id as 1
        var _Id = window.prompt("EnterId");
        $('#spnName').text(_name);
        $('#txtMsg').val('');

        var chatproxy = $.connection.chatHub;

        chatproxy.client.message = function (name, msg) {
            console.log(name);
            $('#divChat').append('<li><strong>' + name + '</strong>:&nbsp;&nbsp;' + msg + '</li>')
        };
        $.connection.hub.start().done(function () {
            chatproxy.server.join("Group1",_Id).done(function () {
                $('#btnsend').click(function (e) {
                    e.preventDefault();
                    chatproxy.server.send($('#spnName').text(), $('#txtMsg').val());
                    $('#txtMsg').val('').focus();
                });
            });
        });
    });

I am calling the callback before starting the hub according to different search results but still its never hitting the call back I have added the scripts also mentioned

<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery.signalR-2.2.2.js"></script>
<script src="/signalr/hubs"></script>

what is the error and a fix

kaido
  • 314
  • 1
  • 13

1 Answers1

0

Checkout this question Group Chat Signal R with Web API

Deniz Gokce
  • 71
  • 1
  • 6