示例#1
0
 private void RegisterHatClientEvents(HatClient hatClient, bool register)
 {
     if (register)
     {
         hatClient.Log += OnComponentLog;
         hatClient.HatConnectionChanged      += OnHatConnectionChanged;
         hatClient.HatConnectionStatusUpdate += OnHatConnectionStatusUpdate;
     }
     else
     {
         hatClient.Log -= OnComponentLog;
         hatClient.HatConnectionChanged      -= OnHatConnectionChanged;
         hatClient.HatConnectionStatusUpdate -= OnHatConnectionStatusUpdate;
     }
 }
示例#2
0
        /// <summary>
        /// Create a new HatClient for the discovered server
        /// </summary>
        async Task CreateNewHatClientAsync(StreamInfo streamInfo)
        {
            var doc      = XDocument.Parse(streamInfo.as_xml());
            var hostName = doc.Element("info")?.Element("hostname").Value;

            if (!DiscoveredLslStreams.ContainsKey(hostName))
            {
                Log?.Invoke(this, new LogEventArgs(this, "CreateNewHatClient", $"Discovered new brainHat server {hostName}, but no matching LSL stream - ignoring.", LogLevel.DEBUG));
                return;
            }

            Log?.Invoke(this, new LogEventArgs(this, "CreateNewHatClient", $"Discovered new brainHat server {hostName}.\n{streamInfo.as_xml()}", LogLevel.INFO));
            var hatClient = new HatClient(hostName, streamInfo, DiscoveredLslStreams[hostName]);

            DiscoveredServers.TryAdd(hostName, hatClient);

            RegisterHatClientEvents(hatClient, true);
            await hatClient.StartHatClientAsync();
        }