我试图在SignalR应用程序中使用.NET库(带有棱角版本的.NET Core3.1),但是当我谈到正式文档中提到的最后一步时,我不知道该把代码放在哪里:
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
});我不知道,我应该把上面的代码放在哪里?
发布于 2020-06-03 16:32:18
你可以用ngOnInit of AppComponent in app.component.ts来做。
export class AppComponent extends AppComponentBase implements OnInit {
...
ngOnInit(): void {
...
// SignalRAspNetCoreHelper.initSignalR(); // Replace this line with the block below
SignalRAspNetCoreHelper.initSignalR(() => {
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
});
});
...
}
...
}https://stackoverflow.com/questions/62177445
复制相似问题