Skip to content

Commit

Permalink
Fix GetGroupSceneItemList
Browse files Browse the repository at this point in the history
* Fix string conversion in GetGroupSceneItemList.
* Refactor get scene list method in test client and support top level groups.
  • Loading branch information
jsTron committed Oct 13, 2022
1 parent 8f11569 commit 44c722b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
39 changes: 34 additions & 5 deletions TestClient/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License along
using OBSWebsocketDotNet;
using OBSWebsocketDotNet.Types;
using OBSWebsocketDotNet.Types.Events;
using Newtonsoft.Json;

namespace TestClient
{
Expand Down Expand Up @@ -329,17 +330,45 @@ private void btnConnect_Click(object sender, EventArgs e)

private void btnListScenes_Click(object sender, EventArgs e)
{
var scenes = obs.ListScenes();
var scenes = obs.GetSceneList().Scenes;

tvScenes.Nodes.Clear();
foreach (var scene in scenes)
{
var node = new TreeNode(scene.Name);
var sources = new List<SceneItemDetails>();
sources.AddRange(obs.GetSceneItemList(scene.Name));
foreach (var item in sources)
var itemList = obs.GetSceneItemList(scene.Name);
var groupList = obs.GetGroupList();
groupList.RemoveAll(x => !itemList.Any(y => y.SourceName.Equals(x)));

if (groupList.Count > 0)
{
foreach (var name in groupList)
{
var group = new ObsScene { Name = name, Items = new List<SceneItemDetails>() };
var parentNode = node.Nodes.Add(group.Name);

foreach (var item in obs.GetGroupSceneItemList(group.Name))
{
group.Items.Add(JsonConvert.DeserializeObject<SceneItemDetails>(item.ToString()));
}

if (group.Items.Count() > 0)
{
foreach (var groupSceneItem in group.Items)
{
parentNode.Nodes.Add(groupSceneItem.SourceName);
}
}
}
}

var items = obs.GetSceneItemList(scene.Name).Where(x => !(bool)groupList?.Any(y => y.Equals(x.SourceName)));
if (items != null && items.Count() > 0)
{
node.Nodes.Add(item.SourceName);
foreach (var item in items)
{
node.Nodes.Add(item.SourceName);
}
}

tvScenes.Nodes.Add(node);
Expand Down
2 changes: 1 addition & 1 deletion obs-websocket-dotnet/OBSWebsocket_Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ public List<JObject> GetGroupSceneItemList(string sceneName)
};

var response = SendRequest(nameof(GetGroupSceneItemList), request);
return JsonConvert.DeserializeObject<List<JObject>>((string)response["sceneItems"]);
return JsonConvert.DeserializeObject<List<JObject>>(response["sceneItems"].ToString());
}

/// <summary>
Expand Down

0 comments on commit 44c722b

Please sign in to comment.