1

将 @aspnet/signalr 从1.0.0升级到1.1.2后,调用startConnection() 时出现以下错误:

解析握手响应时出错:TypeError:'instanceof' 的右侧不可调用

这是我的服务:

@Injectable()
export class SignalRService {

  careworkerTrckInfo = new EventEmitter<GeoLocationCareWorkerTrackSignalR>();
  connectionEstablished = new EventEmitter<Boolean>();

  private connectionIsEstablished = false;
  private serverTimeoutInMilliseconds = 50000; // 50 Second

  private _hubConnection: HubConnection;

constructor(
    @Inject(APP_CONFIG) private appConfig: IAppConfig) {
    this.createConnection();
    this.startConnection();
}

private createConnection() {
    const url = `${this.appConfig.apiEndpoint}/notifications`;
    this._hubConnection = new HubConnectionBuilder()
        .withUrl(url)
        .build();
    this._hubConnection.serverTimeoutInMilliseconds = this.serverTimeoutInMilliseconds;
}

private startConnection() {
    this._hubConnection
    .start()
    .then(() => {
        this.connectionIsEstablished = true;
        this.connectionEstablished.emit(true);
    })
    .catch(err => {
        console.log('Error while establishing connection.');
    });
}}

它曾经工作过!

4

1 回答 1

0

以下代码在我的 index.html 中:

<script>
    var global = global || window;
    // var Buffer = Buffer || []; --> remove or comment this line
    var process = process || {
        env: {
            DEBUG: undefined
        },
        version: []
    };
</script>

我删除(评论)缓冲区,它解决了我的问题。

于 2020-12-08T12:42:19.873 回答