Pra*_*rma 3 signalr-hub signalr.client aurelia aurelia-cli
我正在尝试将信号r集成到Aurelia客户端应用程序中.我已经启动并运行了signalr服务器,它正在与durandal等其他框架一起运行.我的中心URl就是这样的" http:// localhost/signalr/signalr/hubs "
在客户端添加信号器的步骤
Run Code Online (Sandbox Code Playgroud)$.connection.notificationHub.connection.start().done( function () { console.log('hurray, connection established'); } ).fail(function () { console.log('oops - connection failed'); });
现在运行应用程序跟踪错误,看不到undefined的notificationHub
请告诉我问题在哪里.
我已经将SignalR添加到Aurelia应用程序中,不使用生成的代理,只是按照本页上的说明手动执行.我创建了一个单独的模块,但我想你可以在app.js中使用它.您需要添加以下内容:
...
// 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);
});
Run Code Online (Sandbox Code Playgroud)
使用以下命令调用服务器方法:
this.hubProxy.invoke('myServerMethod', args);
Run Code Online (Sandbox Code Playgroud)
在函数处理程序中,我们使用Aurelia事件聚合器将适当的消息发布到应用程序的其余部分.
通过使用手动方法,您无需在index.html中包含signalr/hubs脚本.
归档时间: |
|
查看次数: |
1594 次 |
最近记录: |