Unity WebRTC client implementation using Websocket & without need of TURN Server

I am working on a project, where we connect to a remote WebRTC Media source (present within our network) to receive a video stream. We don’t control the source code for the remote WebRTC Media source

We have been able to connect to the remote WebRTC Media source using three different clients [ Javascript Code (in Chrome), React Native and Flutter ] and we were successfully able to receive video stream from the remote WebRTC Media source by just knowing it’s IP address. We did not use a TURN server. We used Websocket to establish the connection to the remote WebRTC Media source.

However, when we tried the same approach in Unity using WebSocketSharp and Unity’s WebRTC library ( WebRTC | WebRTC | 3.0.0-pre.8) , we are not able to receive the video from the remote WebRTC Media source

What I really don’t understand is that we are able to successfully get the video stream in three clients [ Javascript Code (in Chrome), React Native and Flutter ]. We are having issue only in Unity.

Has anyone implemented a Unity project using Unity’s WebRTC library ( WebRTC | WebRTC | 3.0.0-pre.8) & using Websocket instead of a TURN server ?

Just wondering: is the source transmitting over http or https? In Unity you have to specifically enable and allow non-secure web requests in Player Settings.

You may want to add more details as to how it’s failing. Any error messages? Timeout? Connection refused?

@CodeSmile Thanks for your response.
The source is transmitting over ws (not wss). I am using Unity 2022.3.32f1 and in the IDE, I only see setting called

Allow downloads over http

I have enabled this for now to test code. Apart from this, I don’t see any other setting that will affect the http (or ws) transport.

We use WebSocketSharp library from Unity code to establish the WebSocket connection with the remote source. I am able to successfully establish connection using WebSocketSharp. Once websocket is established, I provide an answer to the remote source using

CreateAnswer function present in RTCPeerConnection.cs (provided as part of package com.unity.webrtc@3.0.0-pre.8)

When I send the answer to the remote source, the remote source acknowledges the answer, but closes the connection, mainly because the answer provided by Unity is very short, while the answer provided by three different clients [ Javascript Code (in Chrome), React Native and Flutter ] is long.

We believe , the main reason for the short answer from Unity is because , there is no ICE candidate detail in the answer, as there is no STUN/TURN server. Remote server serves the video only within the same LAN so STUN/TURN server is not needed

The answer provided by three different clients [ Javascript Code (in Chrome), React Native and Flutter ] included a ICE candidate detail, although there is no STUN/TURN server, while CreateAnswer function present in RTCPeerConnection.cs (provided as part of package com.unity.webrtc@3.0.0-pre.8) provides a very short answer probably because there is no STUN/TURN server.

I think if we can replicate the answer in Unity, similar to the answer generated by three different clients [ Javascript Code (in Chrome), React Native and Flutter ] we will be able to make the remote server to provide the video.

The remote server is using this library to serve the video over LAN, GitHub - paullouisageneau/libdatachannel: C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets

Hello! Have you by any chance already found a solution to this problem? I’m currently trying to connect to a webrtc stream from unity (via wss though), and also struggling despite the stream connection working for browser. I would really appreciate it if you have a working solution and can share it.

@naga1990 @kuroi_hakucho I have the exact same thing working for me. WS(not wss) connection over a WLAN to stream from Meta Quest 3 to Windows/Mac/Android Unity application. Didn’t try with a browser though. Do you have any Webrtc logs?