Skip to content

Commit 08123b3

Browse files
authored
fix: Add warning about conflict signaling URL (#887)
* add warning about conflict signaling settings * Revert "add warning about conflict signaling settings" This reverts commit 6fbbc71. * add warning when same url signaling instance
1 parent b164082 commit 08123b3

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

com.unity.renderstreaming/Runtime/Scripts/Signaling/HttpSignaling.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using System.Net;
46
using System.Threading;
57
using Unity.WebRTC;
@@ -9,9 +11,11 @@ namespace Unity.RenderStreaming.Signaling
911
{
1012
public class HttpSignaling : ISignaling
1113
{
12-
private string m_url;
13-
private int m_timeout;
14-
private SynchronizationContext m_mainThreadContext;
14+
private static HashSet<HttpSignaling> instances = new HashSet<HttpSignaling>();
15+
16+
private readonly string m_url;
17+
private readonly int m_timeout;
18+
private readonly SynchronizationContext m_mainThreadContext;
1519
private bool m_running;
1620
private Thread m_signalingThread;
1721

@@ -35,11 +39,19 @@ public HttpSignaling(SignalingSettings signalingSettings, SynchronizationContext
3539
ServicePointManager.ServerCertificateValidationCallback =
3640
(sender, certificate, chain, errors) => true;
3741
}
42+
43+
if (instances.Any(x => x.Url == m_url))
44+
{
45+
Debug.LogWarning($"Other {nameof(HttpSignaling)} exists with same URL:{m_url}. Signaling process may be in conflict.");
46+
}
47+
48+
instances.Add(this);
3849
}
3950

4051
~HttpSignaling()
4152
{
4253
Stop();
54+
instances.Remove(this);
4355
}
4456

4557
public void Start()

com.unity.renderstreaming/Runtime/Scripts/Signaling/WebSocketSignaling.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using System.Security.Authentication;
35
using System.Text;
46
using System.Threading;
@@ -10,12 +12,14 @@ namespace Unity.RenderStreaming.Signaling
1012
{
1113
public class WebSocketSignaling : ISignaling
1214
{
13-
private string m_url;
14-
private float m_timeout;
15-
private SynchronizationContext m_mainThreadContext;
15+
private static HashSet<WebSocketSignaling> instances = new HashSet<WebSocketSignaling>();
16+
17+
private readonly string m_url;
18+
private readonly float m_timeout;
19+
private readonly SynchronizationContext m_mainThreadContext;
1620
private bool m_running;
1721
private Thread m_signalingThread;
18-
private AutoResetEvent m_wsCloseEvent;
22+
private readonly AutoResetEvent m_wsCloseEvent;
1923
private WebSocket m_webSocket;
2024

2125
public string Url { get { return m_url; } }
@@ -30,12 +34,21 @@ public WebSocketSignaling(SignalingSettings signalingSettings, SynchronizationCo
3034
m_timeout = 5.0f;
3135
m_mainThreadContext = mainThreadContext;
3236
m_wsCloseEvent = new AutoResetEvent(false);
37+
38+
if (instances.Any(x => x.Url == m_url))
39+
{
40+
Debug.LogWarning($"Other {nameof(WebSocketSignaling)} exists with same URL:{m_url}. Signaling process may be in conflict.");
41+
}
42+
43+
instances.Add(this);
3344
}
3445

3546
~WebSocketSignaling()
3647
{
3748
if (m_running)
3849
Stop();
50+
51+
instances.Remove(this);
3952
}
4053

4154
public void Start()

0 commit comments

Comments
 (0)