首页 > 解决方案 > 'instanceof' 的右侧在 SignalR 1.1.2 中不可调用

问题描述

将 @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.');
    });
}}

它曾经工作过!

标签: angularsignalr-client

解决方案


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

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

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


推荐阅读