sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.42k stars 431 forks source link

Issue with WebRTC example - Delegate 'Func<WebRTCWebSocketPeer>' does not take 1 arguments #1033

Closed W3AXL closed 8 months ago

W3AXL commented 9 months ago

I might just be doing something wrong, but I'm trying to get the basic WebRTC example up and running and hitting an error when defining the WebRTCWebSocketPeer websocket service and trying to assign the CreatePeerConnection function:

Wss = new WebSocketServer(address, port);
Wss.AddWebSocketService<WebRTCWebSocketPeer>("/", (peer) => peer.CreatePeerConnection = CreatePeerConnection);

Error: Delegate 'Func<WebRTCWebSocketPeer>' does not take 1 arguments

Am I missing something or has the instantiation for the WebRTC peer changed since the docs were last updated? This is on a .NET 6 project in VS 2022.

W3AXL commented 9 months ago

It appears the example in the root README conflicts with the example program in how this is supposed to be done, however both result in the same error mentioned above.

From README.md:

webSocketServer.AddWebSocketService<WebRTCWebSocketPeer>("/", (peer) => peer.CreatePeerConnection = () => CreatePeerConnection());

From WebRTCGetStarted:

webSocketServer.AddWebSocketService<WebRTCWebSocketPeer>("/", (peer) => peer.CreatePeerConnection = CreatePeerConnection);
W3AXL commented 9 months ago

For reference, here's the entire class as it is currently. I'm aware this would not represent a working WebRTC example, but I need to resolve this error before I can continue.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using SIPSorcery.Net;
using WebSocketSharp.Server;

namespace daemon
{
    internal class ClientProtocol
    {
        public static WebSocketServer Wss {  get; set; }

        public static void StartWsServer(IPAddress address, int port)
        {
            Log.Information($"Starting websocket server on {address}:{port}");
            Wss = new WebSocketServer(address, port);
            Wss.AddWebSocketService<WebRTCWebSocketPeer>("/", (peer) => peer.CreatePeerConnection = CreatePeerConnection());
            Wss.Start();
        }

        private static Task<RTCPeerConnection> CreatePeerConnection()
        {
            var pc = new RTCPeerConnection(null);

            pc.onconnectionstatechange += async (state) =>
            {
                Log.Debug($"WebRTC peer connection state changed to {state}");
            };

            return Task.FromResult(pc);
        }
    }
}
W3AXL commented 8 months ago

Any assistance? This seems to be a pretty major and breaking bug. I've tried .NET6 and .NET8 with the same result - there's no way to properly instantiate the WebRTCWebSocketPeer.

sipsorcery commented 8 months ago

Will take a look.

W3AXL commented 8 months ago

I think I figured out the issue.

Originally, I was using the sta/websocket-sharp package and that resulted in the error above. I then tried switching to the sipsorcery/websocket-sharp package but the error did not resolve.

However, this morning I removed and reinstalled all packages in my solution and it seems to have fixed the issue. I'm not sure if it was a package cache issue or what, but nothing else seemed to resolve it (including switching around to a bunch of different .NET versions).

It should probably be noted somewhere in the docs (and apologies if it is and I missed it) that you must use the sipsorcery version of websocket-sharp in order for things to work properly.