我在我的 Angular 6 项目中安装了@aspnet/signalr
对于信号器问题,我尝试了在堆栈溢出流程中找到的所有其他选项。以下是我的服务代码:
import { Injectable } from '@angular/core';
import * as signalR from "@aspnet/signalr";
import { UserService } from 'app/@core/data/users.service';
@Injectable()
export class SignalRService {
private url = baseurl+'&users='
public data;
private hubConnection: signalR.HubConnection;
constructor(private user: UserService) { }
public startConnection = () => {
let loggedInuser = this.user.getUserEmail();
let accessToken ="some token";
var options = {
transport: signalR.HttpTransportType.WebSockets,
logging: signalR.LogLevel.Trace,
accessTokenFactory: () => accessToken
};
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(this.url + loggedInuser , options)
.build();
this.hubConnection.serverTimeoutInMilliseconds = 9999999999999;
this.hubConnection
.start()
.then(() => console.log('Connection started'))
.catch(err => {
console.log('url: ' + this.url + loggedInuser)
console.log('Error while starting connection: ', err)
})
}
public addTransferChartDataListener = () => {
this.hubConnection.on('AppNotifications', (data) => {
this.data = data;
console.log(data);
});
}
}
当我运行通知组件的 ngOninit() 时,我在控制台中收到“Websocket 未处于打开状态”消息。我哪里做错了?