1

I am completely new to signalR and pretty new to javascript as well. I have a signalR hub and a demo client application that connects to the hub as well as adding specific groups to the Hub.Groups. This all seems to work correctly. On my connect I create the event handler called notifyStatusUpdate to update per specific group. However when I try to use that on the server side, the client side does absolutely nothing.

    function connect(e) {
    var env = $('#env option:selected').val();
    connection = $.hubConnection(env + '/signalr', { useDefaultPath: false });
    connection.logging = true;
    paymentsHubProxy = connection.createHubProxy('paymentsHub');

    paymentsHubProxy.on('notifyStatusUpdate', function (result) {
        console.log(result);
        receivedTxt.val(JSON.stringify(result));
    });

    connection.start()
        .done(function () {
            console.log('Now connected, connection ID=' + connection.id);

            subscribeBtn.removeProp("disabled");
            saveBillItemsBtn.removeProp("disabled");
        })
        .fail(function () {
            console.log('Could not connect');
        });


    e.preventDefault();
}

This is the client side code that should invoke this, but does not.

        public BaseApiResponse<TriggerStatusUpdateResponse> TriggerStatusUpdate(TriggerStatusUpdateRequest request) {
        try
        {
            LoggingService.LogInfo("entering...");

            var statuses = paymentsManager.GetMultipleOrderStatuses(request.OrderIds.ToArray());
            GlobalHost.ConnectionManager.GetHubContext<PaymentsHub>().Clients.Group(request.SiteId).notifyStatusUpdate(new { Statuses = statuses });

            return new BaseApiResponse<TriggerStatusUpdateResponse>("Success",ResponseStatusType.Success);
        }

I've tried to create a function on the client side to basically just catch all, display something.

paymentsHubProxy.on('notifyStatusUpdate', function (result) {
        console.log(result)
        receivedTxt.val(result.toString);
    });

Whilst server side calling something like

GlobalHost.ConnectionManager.GetHubContext<PaymentsHub>().Clients.All.notifyStatusUpdate("WORKDARNIT");

to no avail. Nothing works and I have no idea why.

Linton Caldecott
  • 449
  • 6
  • 17

0 Answers0