public BroadcastProxy ConnectToBroadcaster() { if (broadcastProxy == null) { // Request headtracking endpoint address bool success = controlSocket.TrySendAsJson(new RequestEndpoint(EndpointNames.Broadcast), 1000); if (!success) { HandleControlConnectionException(new Exception("API server timeout.")); } EndpointCreated response; success = controlSocket.TryReceiveJson(out response, 1000); if (!success) { HandleControlConnectionException(new Exception("API server timeout.")); } // Initialize the proxy broadcastProxy = new BroadcastProxy(response.EndpointAddress); } return(broadcastProxy); }
private void ConnectOrReconnect() { try { // Close active connections (if restarting) apiClient.DisconnectHeadTrackingProxy(); apiClient.DisconnectControllerProxy(); apiClient.DisconnectBroadcastProxy(); controllerService?.Dispose(); // Give it some time to clean up Thread.Sleep(10); // Connect to the services headTrackingService = new TrackingService(apiClient.ConnectHeadTrackingProxy()); controllerService = new ControllerService(apiClient.ConnectToControllerProxy()); broadcastProxy = apiClient.ConnectToBroadcaster(); broadcastProxy.HapticPulseReceived += OnHapticFeedbackReceived; headTrackingService.ChangeStatus(IsControllingHeadTracking); } catch (Exception x) { MessageBox.Show(x.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void DisconnectAllEndpoints() { controller?.Dispose(); head?.Dispose(); broadcasts?.Dispose(); controller = null; head = null; broadcasts = null; }
public void DisconnectBroadcastProxy() { if (controllerProxy == null) { return; } broadcastProxy.Disconnect(); broadcastProxy = null; }
public void ConnectOrReconnect() { try { // Connect to the services headTrackingService = new TrackingService(apiClient.CreateProxy <HeadTrackingProxy>()); controllerService = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); controllerService2 = new ControllerService(apiClient.CreateProxy <ControllerProxy>()); //controllerService3 = new ControllerService(apiClient.CreateProxy<ControllerProxy>()); //controllerService4 = new ControllerService(apiClient.CreateProxy<ControllerProxy>()); broadcastProxy = apiClient.CreateProxy <BroadcastProxy>(); headTrackingService.ChangeStatus(true); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void Initialize(PoseCoreEventManager eventMgr) { poseCoreEventManager = eventMgr; if (initiated) { Debug.Log("MQTT already initiated, ignoring connect call."); return; } initiated = true; Debug.Log("MqttPoseProxy::Connect"); broadcastProxy = new BroadcastProxy(); broadcastProxy.mqttPoseProxy = this; if (isUsingBroadcast) { Debug.Log("MqttPoseProxy is using broadcast to connect to MQTT srv"); broadcastProxy.Start(); } else { Debug.Log("MqttPoseProxy is directly connecting to MQTT srv"); Connect(); } }
// Sets up connection and returns true if all links are established. private bool TrySettingUpConnection() { lastConnectionAttempt = DateTime.Now; // Make sure API server is alive var status = api.GetStatus(timeoutThresholdMs); if (status == null) { return(false); } // Reset current connections, if exist DisconnectAllEndpoints(); try { if (capabilities.HasFlag(Capabilities.HeadTracking)) { var endpointStatus = status.Endpoints.FirstOrDefault(x => x.Name == EndpointNames.HeadTracking); if (endpointStatus == null || endpointStatus.Code != (int)ControlResponseCode.OK) { return(false); } head = new HeadRemote(api.CreateProxy <HeadTrackingProxy>()); } if (capabilities.HasFlag(Capabilities.Controllers)) { var endpointStatus = status.Endpoints.FirstOrDefault(x => x.Name == EndpointNames.Controller); if (endpointStatus == null || endpointStatus.Code != (int)ControlResponseCode.OK) { return(false); } controller = new ControllerRemote(api.CreateProxy <ControllerProxy>()); } // Subscribe to haptic pulse broadcasts, if controller proxy is in use if (controller != null) { broadcasts = api.CreateProxy <BroadcastProxy>(); // Forward the events to long-lived event so API user doesn't // have to resubscribe on reconnect broadcasts.HapticPulseReceived += (s, e) => HapticPulse?.Invoke(this, e); } return(true); } catch (Exception x) { Logger.Error("Error during API connection: " + x); // Cleanup possibly connected endpoints DisconnectAllEndpoints(); } return(false); }