public int Shutdown()
        {
            // Shutdown the JSON server to stop listening for new requests.
            cancellationTokenSource?.Cancel();

            // Dispose and cleanup.
            try
            {
                jsonServer?.Dispose();
                jsonServer = null;
            }
            catch { return(1); }

            try
            {
                if (jsonServerTask != null && !jsonServerTask.IsCompleted)
                {
                    jsonServerTask?.Wait(1000); // Sometimes the Task has not finished closing by the time we reach this point. Give it a second to wrap up.
                }
                jsonServerTask?.Dispose();
                jsonServerTask = null;
            }
            catch { return(1); }

            try
            {
                cancellationTokenSource?.Dispose();
                cancellationTokenSource = null;
            }
            catch { return(1); }

            // Return success if we reached this point without issue.
            return(0);
        }
        public int Startup(IPluginHostDelegates hostDelegates)
        {
            SRTPluginUIJSON.hostDelegates = hostDelegates;

            // Start the JSON server for listening for new reqeusts.
            cancellationTokenSource = new CancellationTokenSource();
            jsonServer     = new JSONServer();
            jsonServerTask = jsonServer?.Start(cancellationTokenSource.Token);

            // Return success.
            return(0);
        }