Uncaught (in promise) Error: Failed to invoke 'XXXXX' due to an error on the server
Asked Answered
Y

2

5

I created a .net core chat application using SignalR and I used WebRTC for video calls. As I need to send the SDP to the receiver using server method so I created a hub method call "SendOffer". When I click Video call button I have invoked this "SendOffer" method. I have put the client side code below

var connection = new signalR.HubConnectionBuilder()
    .withUrl('/chat')
    .build();

const Peer = new RTCPeerConnection();

const video = document.querySelector('video');

const constraints = {
    'video': true,
    'audio': true
}

document.getElementById("sendVideo").addEventListener("click", function (event) {

    navigator.mediaDevices.getUserMedia({
        video: true,
        audio: true,
    }).then(function (stream) {
        video.srcObject = stream
        video.play();
        //Peer.addStream(stream);
        Peer.createOffer()
            .then(sdp => Peer.setLocalDescription(sdp))
            .then(function () {
                console.log(Peer.localDescription);
                //connection.invoke("SendOffer", Peer.localDescription).catch(function (err) {
                //    return console.error(err.toString());
                connection.invoke("SendOffer", Peer.localDescription);
            })
    });
})

But this gives an error in the console log and not working. blow is the error

signalr.js:2088 Uncaught (in promise) Error: Failed to invoke 'SendOffer' due to an error on the server. at _this.callbacks. (signalr.js:2088) at HubConnection.processIncomingData (signalr.js:2182) at WebSocketTransport.HubConnection.connection.onreceive (signalr.js:1905) at WebSocket.webSocket.onmessage (signalr.js:3949)

Can any one please help me to solve this error.

Yeh answered 5/4, 2020 at 21:15 Comment(1)
Have you found the reason?Scissors
A
10

Had the same error. In my case that was because of type mismatch. Server expected string. Client was sending value from variable with value '1234', that was sending as a int.

Amphitheater answered 4/6, 2020 at 12:52 Comment(3)
thank you. faced the same issue is there any way to debug server-side codeAstrosphere
It's not my case. And I still cannot figure out what's wrong...Scissors
@DulangaHeshan Late to the party, but you can add logging to help debug, you'll see the server side errors in detail in the Output tab of VS. learn.microsoft.com/en-us/aspnet/core/signalr/…Basidiospore
T
1

Had a similar problem, and @Vita1ij answer helped me figure out what was the issue. Everything worked perfectly fine until i've added a CancellationToken as a parameter for my hub methods:

public class MyHub : Hub
{
    public async Task HubAction(YourType param, CancellationToken cancellationToken)
    {
        await Clients.All.SendAsync(nameof(HubAction), param, cancellationToken);
    }
}

I didn't realize what has caused this error at first, because i figured that a cancellation token should be included automatically, but unfortunately no.

So, removing this cancellation token solved the issue for me:

public class MyHub : Hub
{
    public async Task HubAction(YourType param)
    {
        await Clients.All.SendAsync(nameof(HubAction), param);
    }
}
Tunicate answered 14/11, 2023 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.