Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need all this in the test client?
Overall groups should be avoided per the Websocket documentation:
"Using groups at all in OBS is discouraged, as they are very broken under the hood."

https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol.md#getgroupsceneitemlist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't. If I recall correctly, the previous code received and used that info for free from the old API. I was operating under the premise that I would mimic that behavior.

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"]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other functions are in the format of (type)resonse["keyName"] is there a reason we're changing it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deserialization does not like the direct cast here, causing the request to hang. Now that you have me thinking, maybe changing List to something like a JArray could work as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was testing with my code, it was failing on line 1747 saying it couldn't convert from Array to String but I changed it to this and got it to work:

return JsonConvert.DeserializeObject<List<SceneItemDetails>>(response["sceneItems"].ToString());

You'll notice I also changed the overall function to return as SceneItemDetails like it was before but apparently for whatever reason the (string) isn't allowed whereas .ToString() is fine.

return JsonConvert.DeserializeObject<List<JObject>>(response["sceneItems"].ToString());
}

/// <summary>
Expand Down