Problem when use SignalR with ASP.NET Boilerplate - Connection ID required

24 views Asked by At

I'm creating a SignalR to notify people who are logged in about CRUD events, but I don't understand the ASP.NET Boilerplate documentation very well. What should I do with JS in the final step? I used the code to create a message.js file stored in wwwroot/js. I want to simply test SignalR, so I register the endpoint, but when accessing the link. "/signalr-myChatHub" gives an error "Connection ID required". What I want to ask is that when I create such a JS file, when entering the correct path in the "abp.signalr.startConnection(abp.appPath + 'signalr-myChatHub', function (connection) {" declaration, I can use SignalR , is it necessary to call a JS file from an HTML file? Please help me with an example of it so I can refer to it, I would like to thank you very much.

The code in the last step in the document makes me not understand how to use it

var chatHub = null;

abp.signalr.startConnection(abp.appPath + 'signalr-myChatHub', function (connection) {
    chatHub = connection; // Save a reference to the hub

    connection.on('getMessage', function (message) { // Register for incoming messages
        console.log('received message: ' + message);
    });
}).then(function (connection) {
    abp.log.debug('Connected to myChatHub server!');
    abp.event.trigger('myChatHub.connected');
});

abp.event.on('myChatHub.connected', function() { // Register for connect event
    chatHub.invoke('sendMessage', "Hi everybody, I'm connected to the chat!"); // Send a message to the server
});
0

There are 0 answers