Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal R client javascript funtion not being called nor executed #1891

Closed
oghaleetomu opened this issue Feb 26, 2017 · 10 comments
Closed

Signal R client javascript funtion not being called nor executed #1891

oghaleetomu opened this issue Feb 26, 2017 · 10 comments
Assignees
Milestone

Comments

@oghaleetomu
Copy link

oghaleetomu commented Feb 26, 2017

I am currently developing a web application using asp.net MVC and asp.net boilerplate framework. Recently I just tried implementing real time updates using Signal R 2.2.1, But my callbacks on my JavaScript client are not been called nor executed. I don't know where I have gone wrong, please how do I get my client callback to be excited. Thanks, Below are my code.

My Signal R hub

public class WallHub : Hub, ITransientDependency
{
     public async Task WallInit()
     {
         var wallItems = await ItemManager.GetAllItemsAsync();
         Clients.Caller.ItemListInitialized(wallItems);
     }
}

My JavaScript Code

$(function () {
    var wallHubProxy = $.connection.wallHub;
    wallHubProxy.client.itemListInitialized = function (itemLsts) {
    console.log(itemLsts);
  };

$.connection.hub.start()
       .done(function () {
            wallHubProxy.server.wallInit();
       })
       .fail(function () {
            console.log("Could Not Connect");
       });
});

and my owin startup

        //Enable the use of signal R
        var hubConfiguration = new HubConfiguration();
        hubConfiguration.EnableDetailedErrors = true;
        app.MapSignalR(hubConfiguration);`

Currently using the version 1.4.2

@BoeseB
Copy link

BoeseB commented Feb 27, 2017

Hi dablaz,
I had a similar Problem with SignalR and ABP two years ago. My Methods in Javascript weren't called.
The Problem was with the dependency resolver. See the answer on Stackoverflow for details. Maybe this helps you find the solution to your Problem.

@hikalkan
Copy link
Member

Have you followed the documentation: http://www.aspnetboilerplate.com/Pages/Documents/SignalR-Integration

I'm asking this since you are using $.connection.hub.start() to connect to the server which should not be done since abp.signalr.js is already doing it.

I ask you to follow the documentation and implement your feature step by step to understand which step you have a problem.

Also, Abp writes some logs to the browser console like Connected to SignalR server and Registered to the SignalR server. Do you see these logs? I suggest you to remove your code, see these logs and add your hub and scripts step by step.

@oghaleetomu
Copy link
Author

@hikalkan I already did follow the documentation still did not work

@hikalkan
Copy link
Member

So, can you describe on what step you get which error? I can not help for "just does not works" because "it just works" for me :)

@oghaleetomu
Copy link
Author

@hikalkan My Client Methods on my javascripts are not been called.

@hikalkan
Copy link
Member

Is it connecting to signalr?
Can you make same code working without ABP?

Or, can you just create a new template from http://www.aspnetboilerplate.com/Templates and add your simplified code to see it if works. If not works then share the project. It would be easier for me to investigate if there is a problem.

@oghaleetomu
Copy link
Author

Still having the issue of my client callback not working, and am not getting any errors

@chrisb92
Copy link

chrisb92 commented Sep 19, 2017

I've been having this issue too. I think I may have narrowed it down to abp.signalr.js connecting to the server before the client side events have been established. It seems you need to call $.connection.hub.start() after you have set up your events. I'm guessing it is so that it can do some bindings.

If I set abp.signalr.autoConnect = false and then manually call abp.signalr.connect() at the end of my controller, all clients start receiving calls from the server as expected.

@easyest
Copy link
Contributor

easyest commented Apr 23, 2023

Same problem here. Although I am using an old 4.8.1 ABP, I have the same problem - abp.signalr.connect() needs to be called manually AFTER I bind to hub methods.
Ms guide at https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client:

Add the event handler before you call the start method to establish the connection. (If you want to add event handlers after calling the start method, see the note in How to establish a connection earlier in this document, and use the syntax shown for defining a method without using the generated proxy.)

So, that is indeed true - connect should be made AFTER adding all event handlers. Unfortunately this is still mentioned nowhere in the documents. Please mention, that You need to get the hub in another way (maybe this is only for old versions of ABP, but hey, this problem took me almost a complete working day to find out):

var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');
contosoChatHubProxy.on('addContosoChatMessageToPage', function(userName, message) {
    console.log(userName + ' ' + message);
});
connection.start()
    .done(function(){ console.log('Now connected, connection ID=' + connection.id); })
    .fail(function(){ console.log('Could not connect'); });

@ismcagdas
Copy link
Member

I have added a note about this to SignalR documentation #6785

@ismcagdas ismcagdas self-assigned this Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants