Reputation: 135
I am trying to integrate signal r in Aurelia client application. I already have signalr server up and running which is running with other framework like durandal. My Hub URl is like this "http://localhost/signalr/signalr/hubs"
Steps to add signalr in client
$.connection.notificationHub.connection.start().done( function () { console.log('hurray, connection established'); } ).fail(function () { console.log('oops - connection failed'); });
Now on running app following error is seen can not find notificationHub of undefined
please let me know where is the problem.
Upvotes: 3
Views: 1728
Reputation: 3758
I have added SignalR into an Aurelia app by not using the generated proxy and just doing it manually, as per the instructions on this page. I created a separate module but I guess you could use it in the app.js instead. You need to add something like:
...
// Create a connection -> create a proxy -> attach event handlers -> start
this.connection = $.hubConnection('http://my.signalr.host.here');
this.hubProxy = this.connection.createHubProxy('myHubName');
this.connection.logging = true;
// Add method handler(s)
this.hubProxy.on('myMethodCalledByTheServer', e => {
console.log('SignalR called us', e);
});
// Connect to SignalR events if required. eg:
this.connection.connectionSlow(() => {
console.log('The SignalR connection is slow');
});
// Start
this.connection.start()
.then(c => {
console.log('Started', c);
});
Call a server method using the following:
this.hubProxy.invoke('myServerMethod', args);
In the function handlers we use the Aurelia event-aggregator to publish appropriate messages to the rest of the app.
By using the manual approach you don't need to include the signalr/hubs script in index.html.
Upvotes: 6