Typescript 与ABP角度版本的信号机集成

Typescript 与ABP角度版本的信号机集成,typescript,signalr,aspnetboilerplate,.net-core-3.1,asp.net-boilerplate,Typescript,Signalr,Aspnetboilerplate,.net Core 3.1,Asp.net Boilerplate,我试图将SignalR库与ABP应用程序(.NET Core 3.1,Angular版本)一起使用,但当我谈到官方文档中提到的最后一步时,我不知道应该将代码放在哪里: var chatHub = null; abp.signalr.startConnection(abp.appPath + 'signalr-myChatHub', function (connection) { chatHub = connection; // Save a reference to the hub

我试图将SignalR库与ABP应用程序(.NET Core 3.1,Angular版本)一起使用,但当我谈到官方文档中提到的最后一步时,我不知道应该将代码放在哪里:

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
});

我不知道,我应该把上面的代码放在哪里?

你可以在
AppComponent
ngOnInit
中做:

导出类AppComponent扩展AppComponentBase实现OnInit{
...
ngOnInit():void{
...
//SignalAspNetCoreHelper.initSignalR();//用下面的块替换此行
SignalRAspNetCoreHelper.initSignalR(()=>{
var chatHub=null;
abp.signer.startConnection(abp.appPath+'signer myChatHub',函数(连接){
chatHub=connection;//保存对中心的引用
connection.on('getMessage',函数(message){//注册传入消息
console.log('收到的消息:'+消息);
});
}).然后(功能(连接){
abp.log.debug('连接到myChatHub服务器!');
abp.event.trigger('myChatHub.connected');
});
abp.event.on('myChatHub.connected',function(){//注册连接事件
调用('sendMessage',“大家好,我已连接到聊天室!”;//向服务器发送消息
});
});
...
}
...
}

您可以在
AppComponent
ngOnInit
中执行此操作,具体操作步骤如下:

导出类AppComponent扩展AppComponentBase实现OnInit{
...
ngOnInit():void{
...
//SignalAspNetCoreHelper.initSignalR();//用下面的块替换此行
SignalRAspNetCoreHelper.initSignalR(()=>{
var chatHub=null;
abp.signer.startConnection(abp.appPath+'signer myChatHub',函数(连接){
chatHub=connection;//保存对中心的引用
connection.on('getMessage',函数(message){//注册传入消息
console.log('收到的消息:'+消息);
});
}).然后(功能(连接){
abp.log.debug('连接到myChatHub服务器!');
abp.event.trigger('myChatHub.connected');
});
abp.event.on('myChatHub.connected',function(){//注册连接事件
调用('sendMessage',“大家好,我已连接到聊天室!”;//向服务器发送消息
});
});
...
}
...
}

我不知道为什么会出现此异常==>未处理的承诺拒绝:由于服务器上出现错误,无法调用“注册”。HubException:方法不存在;区域:;任务:承诺;值:我不知道为什么会出现此异常==>未处理的承诺拒绝:由于服务器上的错误,无法调用“register”。HubException:方法不存在;区域:;任务:承诺;价值: