Skip to content

Commit

Permalink
Automated reconnection to websocket - dirty hack but works (when subs…
Browse files Browse the repository at this point in the history
…cribers / publishers registered)
  • Loading branch information
missxa committed Apr 22, 2018
1 parent 61c4da0 commit 1b07fb6
Show file tree
Hide file tree
Showing 4 changed files with 7,039 additions and 17,935 deletions.
23 changes: 23 additions & 0 deletions Assets/ROSBridgeLib/ROSBridgeWebSocketConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SimpleJSON;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
Expand Down Expand Up @@ -69,6 +70,7 @@ public string getTopic()
private List<RenderTask> _taskQ = new List<RenderTask>();
// Adjustment to be able to add ros objects at runtime while connected
private bool _running = false;

private bool _sendErrorMessage = false;

private object _queueLock = new object();
Expand Down Expand Up @@ -389,7 +391,28 @@ private void OnError(object sender, WebSocketSharp.ErrorEventArgs e)
Debug.Log(e.Message);
_sendErrorMessage = true;
}
if (_ws.IsAlive)
return;
while (true)
{
try
{
List<Type> preservedSubscribers = new List<Type>(_subscribers);
List<Type> preservedPublishers = new List<Type>(_publishers);

Disconnect();
Connect();
_subscribers = preservedSubscribers;
_publishers = preservedPublishers;
AnnouncePublishersAndSubscribers();
// restore subscribers and publishers
break;
}
catch (Exception ex)
{
Debug.LogError("[ROSBridgeWebsocketConnection] Error while reconnecting: " + ex.ToString());
}
}
}

private void OnMessage(string s)
Expand Down

0 comments on commit 1b07fb6

Please sign in to comment.