Skip to content

Commit

Permalink
Fixed a bug not able to reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Juniverse committed Dec 15, 2023
1 parent b46a0f8 commit a3c6c2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Assets/Inworld/Inworld.AI/Scripts/InworldWebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ string _GetSessionFullName(string sceneFullName)
protected IEnumerator _StartSession()
{
string url = m_ServerConfig.SessionURL(m_Token.sessionId);
if (!IsTokenValid || WebSocketManager.Instance.Contains(url))
if (!IsTokenValid)
yield break;
yield return new WaitForEndOfFrame();
string[] param = {m_Token.type, m_Token.token};
m_Socket = new WebSocket(url, param);
m_Socket = WebSocketManager.Instance.GetWebSocket(url);
if (m_Socket == null)
m_Socket = new WebSocket(url, param);
m_Socket.OnOpen += OnSocketOpen;
m_Socket.OnMessage += OnMessageReceived;
m_Socket.OnClose += OnSocketClosed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void CreateInstance()
readonly List<WebSocket> sockets = new List<WebSocket>();

public bool Contains(string sessionURL) => sockets.Any(s => s.Address == sessionURL);
public WebSocket GetWebSocket(string sessionURL) => sockets.FirstOrDefault(s => s.Address == sessionURL);
public void Add(WebSocket socket)
{
if (!Contains(socket.Address))
Expand Down

0 comments on commit a3c6c2d

Please sign in to comment.