Exemplo n.º 1
0
        public async Task <IEnumerable <VTubeStudioHotKey> > GetHotKeys(string modelID = null)
        {
            List <VTubeStudioHotKey> results = new List <VTubeStudioHotKey>();

            VTubeStudioWebSocketRequestPacket packet = new VTubeStudioWebSocketRequestPacket("HotkeysInCurrentModelRequest");

            if (!string.IsNullOrEmpty(modelID))
            {
                packet.data            = new JObject();
                packet.data["modelID"] = modelID;
            }

            VTubeStudioWebSocketResponsePacket response = await this.websocket.SendAndReceive(packet);

            if (response != null && response.data != null && response.data.TryGetValue("availableHotkeys", out JToken hotKeys) && hotKeys is JArray)
            {
                foreach (VTubeStudioHotKey hotKey in ((JArray)hotKeys).ToTypedArray <VTubeStudioHotKey>())
                {
                    if (hotKey != null)
                    {
                        results.Add(hotKey);
                    }
                }
            }

            return(results);
        }
Exemplo n.º 2
0
        public async Task <VTubeStudioWebSocketResponsePacket> SendAndReceive(VTubeStudioWebSocketRequestPacket packet, int delaySeconds = 5)
        {
            Logger.Log(LogLevel.Debug, "VTube Studio Packet Sent - " + JSONSerializerHelper.SerializeToString(packet));

            this.responses.Remove(packet.requestID);

            await this.Send(JSONSerializerHelper.SerializeToString(packet));

            int cycles = delaySeconds * 10;

            for (int i = 0; i < cycles && !this.responses.ContainsKey(packet.requestID); i++)
            {
                await Task.Delay(100);
            }

            this.responses.TryGetValue(packet.requestID, out VTubeStudioWebSocketResponsePacket response);
            return(response);
        }