Angular 的 SinglarR:如何指定传输类型

SinglarR with Angular: How to specify transport type

我在 Angular 应用程序中使用来自 npm 的 signalr 1.0.0-rc1-update1。

这是我目前连接到集线器的方式:

this.hub = new signalR.HubConnectionBuilder()
      .withUrl(`${environment.apiUrl}operations?token=${this.user.token}`)
      .configureLogging(signalR.LogLevel.Trace)
      .build();

    this.hub.on('GetOperations', (data: OperationGetDto[]) => {
      this.data = data;
    });

    this.hub.start()
      .then(() => {
        this.hub.invoke('GetOperations');
      })
      .catch((e) => {
        this.notificationService.openSnackBar('Error while establishing connection');
      });

如何指定传输类型,例如长轮询?

withUrl 有一个重载,它接受 signalR.HttpTransportType 枚举的成员:

.withUrl(`${environment.apiUrl}operations?token=${this.user.token}`, signalR.HttpTransportType.LongPolling)