Exemple #1
0
        public DreamClient()
        {
            var dd = DreamData.GetStore();

            dev          = GetDeviceData();
            dreamScene   = new DreamScene();
            devMode      = dev.Mode;
            ambientMode  = dev.AmbientModeType;
            ambientShow  = dev.AmbientShowType;
            ambientColor = dev.AmbientColor;
            brightness   = dev.Brightness;
            // Set these to "unset" states
            prevMode           = -1;
            prevAmbientMode    = -1;
            prevAmbientShow    = -1;
            streamStarted      = false;
            showBuilderStarted = false;
            string sourceIp = dd.GetItem("dsIp");

            group          = (byte)dev.GroupNumber;
            targetEndpoint = new IPEndPoint(IPAddress.Parse(sourceIp), 8888);
            dd.Dispose();
            disposed = false;
            bridges  = new List <HueBridge>();
        }
Exemple #2
0
        // This initializes all of the data in our class and starts function loops
        private void Initialize()
        {
            LogUtil.Write("Initializing dream client...");
            // Create cancellation token sources
            _sendTokenSource    = new CancellationTokenSource();
            _captureTokenSource = new CancellationTokenSource();
            _camTokenSource     = new CancellationTokenSource();

            // Init lifx client
            _lifxClient = LifxClient.CreateAsync().Result;

            // Init nano HttpClient
            _nanoClient = new HttpClient();

            // Init nano socket
            _nanoSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _nanoSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            _nanoSocket.EnableBroadcast = false;

            // Cache data store
            // Check default settings
            DataUtil.CheckDefaults(_lifxClient);
            var dd = DataUtil.GetDb();

            // Get audio input if exists
            _aStream = GetStream();
            // Get our device data
            _dev = DataUtil.GetDeviceData();
            // Create scene builder
            _dreamScene = new DreamScene();
            // Get a list of devices
            _devices = new List <BaseDevice>();
            // Read other variables
            _devMode      = _dev.Mode;
            _ambientMode  = _dev.AmbientModeType;
            _ambientShow  = _dev.AmbientShowType;
            _ambientColor = ColorFromString(_dev.AmbientColor);
            _brightness   = _dev.Brightness;
            _autoDisabled = false;
            try {
                _autoDisabled = DataUtil.GetItem("AutoDisabled");
            } catch {
            }

            CaptureMode = DataUtil.GetItem("CaptureMode");

            // Set default values
            _prevMode           = -1;
            _prevAmbientMode    = -1;
            _prevAmbientShow    = -1;
            _streamStarted      = false;
            _showBuilderStarted = false;
            _group          = (byte)_dev.GroupNumber;
            _targetEndpoint = new IPEndPoint(IPAddress.Parse(DataUtil.GetItem("DsIp")), 8888);
            _sDevices       = new List <IStreamingDevice>();
            _wlStrips       = new List <WLedStrip>();
            // Start our timer to refresh devices
            StartRefreshTimer();
            // Start our service to capture (if capture mode is set)
            StartCaptureServices(_captureTokenSource.Token);
            StartVideoCaptureTask();
            // Now, start listening for UDP commands
            StartListening();
            // Finally start our normal device behavior
            if (!_autoDisabled)
            {
                UpdateMode(_dev.Mode);
            }
        }