Nativescript and SignalR?

Viewed 161

I’m developing an app using NativeScript + Angular and need it to have a SignalR connection. I'm using nativescript-signalr-core plugin to connect my app with the signalR. The server side project is written by asp.net core 3.1 (this link).

According to the instructions of plugin, I want to connect to the server, it connects the first moment but it is disconnected immediately.

This is my typescript code:

    connectToServer_Core() {
        this.signalrCore.start(this.hubUrl).then((isConnected: boolean) => {
            console.log('isConnected? ', isConnected);
            console.log('status: ' + JSON.stringify(this.signalrCore.getStatus()));
        })
        .catch(error => {
            console.error(error.message);
        });
    }

This is the output of the function execution:

JS: isConnected?  true
JS: status: {"id":2,"name":"Socket Opened"}
JS: disconnected
JS: Unhandled Promise rejection: Error - Connection already close! ; Zone: <root> ; 
    Task: setTimeout ; Value: Error - Connection already close! undefined

This is the output after invoke():

JS: status: {"id":2,"name":"Socket Opened"}
JS: ERROR Error: Uncaught (in promise): Error - socket is not connected

Please help me how to solve this problem?

0 Answers
Related