コード例 #1
0
        /// <summary>
        /// Updates the clients connected, and the state of the clients, ex. profiles.
        /// </summary>
        public void UpdateClientState()
        {
            try
            {
                //Since ports are quite random, we only use the ip when connecting to the plugin.
                //There is only possible (without faking it) to have one client per ip.
                //Therefor this is a unique identifier that will hold between restarts.
                var clients = _server.ClientData
                              .Select(clientData => clientData.ClientIdentifier)
                              .Select(identifier => identifier.ClientIpAddress)
                              //Distinct since GoXLR right now does not close the old connection on reconnect:
                              .Distinct()
                              .ToArray();

                var clientChoices = new List <string> {
                    "default"
                };
                clientChoices.AddRange(clients);

                //Update states:
                _client.StateUpdate(PluginId + ".single.clients.state.connected", clients.FirstOrDefault() ?? "none");
                _client.StateUpdate(PluginId + ".multiple.clients.states.count", clients.Length.ToString());

                //Update choices:
                _client.ChoiceUpdate(PluginId + ".multiple.routingtable.action.change.data.clients", clientChoices.ToArray());

                _client.ChoiceUpdate(PluginId + ".multiple.profiles.action.change.data.clients", clientChoices.ToArray());
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
コード例 #2
0
        //Send messages for testing.
        private void SendMessages()
        {
            //Update choices (dropdown in UI when creating an action):
            _client.ChoiceUpdate("category1.action1.data2", new[] { "choice 1 (updated)", "choice 2 (updated)", "choice 3 (updated)" });

            //Removes a dynamic state (no change if state does not exist):
            _client.RemoveState("dynamicState1");

            //Adds a state we can work with:
            _client.CreateState("dynamicState1", "Test dynamic state 1", "Test 123");

            //Updates the created dynamic state, if you do not create it:
            _client.StateUpdate("dynamicState1", "d1");

            //You can display this value, but it will not appear in any list:
            _client.StateUpdate("dynamicState2", "d2");

            //Updates the static state (entry.tp):
            _client.StateUpdate("category1.staticstate1", "s1");

            //Custom states (Global Objects/left panel in Touch Portal UI), user adds this (states.tp in %AppData%/TouchPortal).
            //The user should add this manually in the UI:
            _client.StateUpdate("global.customState1", "c2");

            //Updates settings in Touch Portal settings:
            _client.SettingUpdate("Test3", DateTime.UtcNow.ToString("yyyyMMddHHmmss"));

            //Updates the min and max value of the number field.
            _client.UpdateActionData("category1.action1.data4", 10, 15, ActionDataType.Number);

            //Sends a notification to the Touch Portal UI this needs options the user can react on:
            _client.ShowNotification($"TouchPortal.SamplePlugin|update", "SamplePlugin: new version", "Please update to version 1.0!", new[] {
                new NotificationOptions {
                    Id = "update", Title = "Update this plugin"
                },
                new NotificationOptions {
                    Id = "readMore", Title = "Read more..."
                }
            });

            //Updates a connector/slider value.
            _client.ConnectorUpdate("dotnetsample001", 10);

            //Updates the connector with data, however this seems buggy, and we would need to find a more automated way of doing this.
            var message = JsonSerializer.Serialize(new
            {
                type        = "connectorUpdate",
                connectorId = $"pc_{PluginId}_dotnetsample002|connectordata001=test", //If you change the value in Touch Portal UI, this also need to be changed (and the page on the touch device might need to be refreshed).
                value       = 20
            });

            _client.SendMessage(message);

            //_client.Close()
        }
コード例 #3
0
        public void MonitoringCallback(IReadOnlyList <MeterValues> meters)
        {
            var image = _barMeterGraphics.DrawPng(meters);

            if (image?.Length > 0)
            {
                _client.StateUpdate("oddbear.audio.monitor.icon", Convert.ToBase64String(image));
            }
        }
コード例 #4
0
        private void SimConnectEvent_OnConnect()
        {
            _simConnectCancellationTokenSource = new CancellationTokenSource();

            _client.StateUpdate("MSFSTouchPortalPlugin.Plugin.State.Connected", _simConnectService.IsConnected().ToString().ToLower());

            // Register Actions
            foreach (var a in actionsDictionary)
            {
                _simConnectService.MapClientEventToSimEvent(a.Value, a.Value.ToString());
                _simConnectService.AddNotification(a.Value.GetType().GetCustomAttribute <SimNotificationGroupAttribute>().Group, a.Value);
            }

            // Register SimVars
            foreach (var s in statesDictionary)
            {
                _simConnectService.RegisterToSimConnect(s.Value);
            }

            Task.WhenAll(RunPluginServices(_simConnectCancellationTokenSource.Token));
        }