Skip to content

Commit

Permalink
fix: Add warning about conflict signaling URL (#887)
Browse files Browse the repository at this point in the history
* add warning about conflict signaling settings

* Revert "add warning about conflict signaling settings"

This reverts commit 6fbbc71.

* add warning when same url signaling instance
  • Loading branch information
kannan-xiao4 authored Feb 21, 2023
1 parent b164082 commit 08123b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using Unity.WebRTC;
Expand All @@ -9,9 +11,11 @@ namespace Unity.RenderStreaming.Signaling
{
public class HttpSignaling : ISignaling
{
private string m_url;
private int m_timeout;
private SynchronizationContext m_mainThreadContext;
private static HashSet<HttpSignaling> instances = new HashSet<HttpSignaling>();

private readonly string m_url;
private readonly int m_timeout;
private readonly SynchronizationContext m_mainThreadContext;
private bool m_running;
private Thread m_signalingThread;

Expand All @@ -35,11 +39,19 @@ public HttpSignaling(SignalingSettings signalingSettings, SynchronizationContext
ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, errors) => true;
}

if (instances.Any(x => x.Url == m_url))
{
Debug.LogWarning($"Other {nameof(HttpSignaling)} exists with same URL:{m_url}. Signaling process may be in conflict.");
}

instances.Add(this);
}

~HttpSignaling()
{
Stop();
instances.Remove(this);
}

public void Start()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using System.Threading;
Expand All @@ -10,12 +12,14 @@ namespace Unity.RenderStreaming.Signaling
{
public class WebSocketSignaling : ISignaling
{
private string m_url;
private float m_timeout;
private SynchronizationContext m_mainThreadContext;
private static HashSet<WebSocketSignaling> instances = new HashSet<WebSocketSignaling>();

private readonly string m_url;
private readonly float m_timeout;
private readonly SynchronizationContext m_mainThreadContext;
private bool m_running;
private Thread m_signalingThread;
private AutoResetEvent m_wsCloseEvent;
private readonly AutoResetEvent m_wsCloseEvent;
private WebSocket m_webSocket;

public string Url { get { return m_url; } }
Expand All @@ -30,12 +34,21 @@ public WebSocketSignaling(SignalingSettings signalingSettings, SynchronizationCo
m_timeout = 5.0f;
m_mainThreadContext = mainThreadContext;
m_wsCloseEvent = new AutoResetEvent(false);

if (instances.Any(x => x.Url == m_url))
{
Debug.LogWarning($"Other {nameof(WebSocketSignaling)} exists with same URL:{m_url}. Signaling process may be in conflict.");
}

instances.Add(this);
}

~WebSocketSignaling()
{
if (m_running)
Stop();

instances.Remove(this);
}

public void Start()
Expand Down

0 comments on commit 08123b3

Please sign in to comment.