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
6 changes: 3 additions & 3 deletions TestClient/AdvancedWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;
using OBSWebsocketDotNet;
using OBSWebsocketDotNet.Types;
using System;
Expand Down Expand Up @@ -323,7 +323,7 @@ private void btnSourceInfo_Click(object sender, EventArgs e)
bool isLocked = obs.GetSceneItemLocked(scene, itemId);
LogMessage($"Source Locked: {isLocked}");

JObject data = obs.GetSceneItemTransformRaw(scene, itemId);
JsonObject data = obs.GetSceneItemTransformRaw(scene, itemId);
LogMessage($"Raw Data: {data}");

var transform = obs.GetSceneItemTransform(scene, itemId);
Expand Down Expand Up @@ -439,7 +439,7 @@ private void btnTransition_Click(object sender, EventArgs e)
obs.SetCurrentSceneTransition(transition.Name);
var activeTransition = obs.GetCurrentSceneTransition();
var info = activeTransition.Settings;
info ??= new JObject();
info ??= new JsonObject();
LogMessage($"Transition: {transition.Name} has {info.Count} settings");
}
obs.SetCurrentSceneTransition(enteringTransition.Name);
Expand Down
18 changes: 9 additions & 9 deletions obs-websocket-dotnet-tests/UnitTest_Types.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;
using OBSWebsocketDotNet.Communication;
using OBSWebsocketDotNet.Types;

Expand All @@ -19,7 +19,7 @@ public void OBSScene_BuildFromJSON()
int sceneItemId = 22;


JObject itemData = new JObject
JsonObject itemData = new JsonObject
{
{ "sourceName", itemName },
{ "sourceType", (int)sourceType },
Expand All @@ -39,7 +39,7 @@ public void OBSScene_BuildFromJSON()
itemData
};

var data = new JObject
var data = new JsonObject
{
{ "sceneName", sceneName },
{ "sources", items },
Expand All @@ -64,7 +64,7 @@ public void OBSAuthInfo_BuildFromJSON()
string challenge = "pBWv82hj";
string salt = "B9fL8CF7";

var data = new JObject
var data = new JsonObject
{
{ "authRequired", true },
{ "challenge", challenge },
Expand All @@ -90,7 +90,7 @@ public void OBSVersion_BuildFromJSON()
var requests = new JArray(availableRequests.Split(','));
var images = new JArray(supportedImageFormats.Split(','));

var data = new JObject
var data = new JsonObject
{
{ "obsWebSocketVersion", pluginVersion },
{ "obsVersion", obsVersion },
Expand Down Expand Up @@ -120,7 +120,7 @@ public void OBSStreamStatus_BuildFromJSON()
int outputSkippedFrames = 120;
int outputTotalFrames = 2000;

var data = new JObject
var data = new JsonObject
{
{ "outputActive", true },
{ "outputReconnecting", true },
Expand All @@ -147,7 +147,7 @@ public void OBSStreamStatus_BuildFromJSON()
[TestMethod]
public void OBSOutputStatus_BuildFromJSON()
{
var data = new JObject
var data = new JsonObject
{
{ "outputActive", true }
};
Expand All @@ -168,7 +168,7 @@ public void OBSCurrentTransitionInfo_BuildFromJSON()
bool transitionFixed = true;
bool transitionConfigurable = true;

var data = new JObject
var data = new JsonObject
{
{ "transitionName", transitionName },
{ "transitionDuration", duration },
Expand All @@ -192,7 +192,7 @@ public void OBSVolumeInfo_BuildFromJSON()
float volumeMul = 0.50f;
float volumeDB = 45.4f;

var data = new JObject
var data = new JsonObject
{
{ "inputVolumeMul", volumeMul },
{ "inputVolumeDb", volumeDB }
Expand Down
52 changes: 52 additions & 0 deletions obs-websocket-dotnet/AppJsonSerializerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json.Serialization;
using System.Text.Json.Nodes;
using OBSWebsocketDotNet.Types;
using OBSWebsocketDotNet.Communication;

namespace OBSWebsocketDotNet
{ [JsonSerializable(typeof(ObsVideoSettings))]
[JsonSerializable(typeof(ObsStats))]
[JsonSerializable(typeof(GetSceneListInfo))]
[JsonSerializable(typeof(List<FilterSettings>))]
[JsonSerializable(typeof(FilterSettings))]
[JsonSerializable(typeof(List<string>))]
[JsonSerializable(typeof(GetProfileListInfo))]
[JsonSerializable(typeof(RecordingStatus))] [JsonSerializable(typeof(GetTransitionListInfo))]
[JsonSerializable(typeof(StreamingService))]
[JsonSerializable(typeof(StreamingServiceSettings))]
[JsonSerializable(typeof(SceneItemTransformInfo))]
[JsonSerializable(typeof(ServerMessage))]
[JsonSerializable(typeof(JsonObject))]
[JsonSerializable(typeof(List<JsonObject>))]
// Types used in PopulateObject calls
[JsonSerializable(typeof(List<FilterReorderItem>))]
[JsonSerializable(typeof(FilterReorderItem))]
[JsonSerializable(typeof(VolumeInfo))]
[JsonSerializable(typeof(VirtualCamStatus))]
[JsonSerializable(typeof(TransitionSettings))]
[JsonSerializable(typeof(SourceTracks))]
[JsonSerializable(typeof(SourceActiveInfo))]
[JsonSerializable(typeof(SceneItemDetails))]
[JsonSerializable(typeof(RecordStateChanged))] [JsonSerializable(typeof(OutputStatus))]
[JsonSerializable(typeof(OutputStateChanged))]
[JsonSerializable(typeof(ObsVersion))]
[JsonSerializable(typeof(ObsScene))]
[JsonSerializable(typeof(Monitor))]
[JsonSerializable(typeof(MediaInputStatus))]
[JsonSerializable(typeof(InputVolume))]
[JsonSerializable(typeof(InputSettings))]
[JsonSerializable(typeof(InputFFMpegSettings))] [JsonSerializable(typeof(InputBrowserSourceSettings))]
[JsonSerializable(typeof(InputBasicInfo))]
[JsonSerializable(typeof(Input))]
[JsonSerializable(typeof(OBSAuthInfo))]
[JsonSerializable(typeof(TransitionOverrideInfo))]
[JsonSourceGenerationOptions(WriteIndented = true)]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}
}
8 changes: 4 additions & 4 deletions obs-websocket-dotnet/Communication/MessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json.Linq;
using System.Text.Json.Nodes;
using System;
using System.Collections.Generic;
using System.Text;
Expand All @@ -7,15 +7,15 @@ namespace OBSWebsocketDotNet.Communication
{
internal static class MessageFactory
{
internal static JObject BuildMessage(MessageTypes opCode, string messageType, JObject additionalFields, out string messageId)
internal static JsonObject BuildMessage(MessageTypes opCode, string messageType, JsonObject additionalFields, out string messageId)
{
messageId = Guid.NewGuid().ToString();
JObject payload = new JObject()
JsonObject payload = new JsonObject()
{
{ "op", (int)opCode }
};

JObject data = new JObject();
JsonObject data = new JsonObject();

switch (opCode)
{
Expand Down
13 changes: 7 additions & 6 deletions obs-websocket-dotnet/Communication/OBSAuthInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;using System.Text.Json.Serialization;
using System.Text.Json.Nodes;

namespace OBSWebsocketDotNet.Communication
{
Expand All @@ -11,22 +11,23 @@ public class OBSAuthInfo
/// <summary>
/// Authentication challenge
/// </summary>
[JsonProperty(PropertyName = "challenge")]
[JsonPropertyName("challenge")]
public readonly string Challenge;

/// <summary>
/// Password salt
/// </summary>
[JsonProperty(PropertyName = "salt")]
[JsonPropertyName("salt")]
public readonly string PasswordSalt;

/// <summary>
/// Builds the object from JSON response body
/// </summary>
/// <param name="data">JSON response body as a <see cref="JObject"/></param>
public OBSAuthInfo(JObject data)
public OBSAuthInfo(JsonObject data)
{
JsonConvert.PopulateObject(data.ToString(), this);
Challenge = data["challenge"]?.ToString();
PasswordSalt = data["salt"]?.ToString();
}

/// <summary>
Expand Down
11 changes: 6 additions & 5 deletions obs-websocket-dotnet/Communication/ServerMessage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Nodes;

namespace OBSWebsocketDotNet.Communication
{
Expand All @@ -11,13 +12,13 @@ internal class ServerMessage
/// <summary>
/// Server Message's operation code
/// </summary>
[JsonProperty(PropertyName = "op")]
[JsonPropertyName("op")]
public MessageTypes OperationCode { set; get; }

/// <summary>
/// Server Data
/// </summary>
[JsonProperty(PropertyName = "d")]
public JObject Data { get; set; }
[JsonPropertyName("d")]
public JsonObject Data { get; set; }
}
}
52 changes: 20 additions & 32 deletions obs-websocket-dotnet/Events.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;using System.Text.Json.Serialization;
using System.Text.Json.Nodes;
using OBSWebsocketDotNet.Communication;
using OBSWebsocketDotNet.Types;
using System;
Expand Down Expand Up @@ -305,22 +305,18 @@ public partial class OBSWebsocket
/// </summary>
/// <param name="eventType">Value of "event-type" in the JSON body</param>
/// <param name="body">full JSON message body</param>
protected void ProcessEventType(string eventType, JObject body)
protected void ProcessEventType(string eventType, JsonObject body)
{
body = (JObject)body["eventData"];
body = body["eventData"]?.AsObject();

switch (eventType)
{
case nameof(CurrentProgramSceneChanged):
CurrentProgramSceneChanged?.Invoke(this, new ProgramSceneChangedEventArgs((string)body["sceneName"]));
break;

case nameof(SceneListChanged):
SceneListChanged?.Invoke(this, new SceneListChangedEventArgs(JsonConvert.DeserializeObject<List<JObject>>((string)body["scenes"])));
break;

case nameof(SceneItemListReindexed):
SceneItemListReindexed?.Invoke(this, new SceneItemListReindexedEventArgs((string)body["sceneName"], JsonConvert.DeserializeObject<List<JObject>>((string)body["sceneItems"])));
break; case nameof(SceneListChanged):
SceneListChanged?.Invoke(this, new SceneListChangedEventArgs(JsonSerializer.Deserialize<List<JsonObject>>((string)body["scenes"], AppJsonSerializerContext.Default.ListJsonObject)));
break; case nameof(SceneItemListReindexed):
SceneItemListReindexed?.Invoke(this, new SceneItemListReindexedEventArgs((string)body["sceneName"], JsonSerializer.Deserialize<List<JsonObject>>((string)body["sceneItems"], AppJsonSerializerContext.Default.ListJsonObject)));
break;

case nameof(SceneItemCreated):
Expand All @@ -341,10 +337,8 @@ protected void ProcessEventType(string eventType, JObject body)

case nameof(CurrentSceneCollectionChanged):
CurrentSceneCollectionChanged?.Invoke(this, new CurrentSceneCollectionChangedEventArgs((string)body["sceneCollectionName"]));
break;

case nameof(SceneCollectionListChanged):
SceneCollectionListChanged?.Invoke(this, new SceneCollectionListChangedEventArgs(JsonConvert.DeserializeObject<List<string>>((string)body["sceneCollections"])));
break; case nameof(SceneCollectionListChanged):
SceneCollectionListChanged?.Invoke(this, new SceneCollectionListChangedEventArgs(JsonSerializer.Deserialize<List<string>>((string)body["sceneCollections"], AppJsonSerializerContext.Default.ListString)));
break;

case nameof(CurrentSceneTransitionChanged):
Expand All @@ -369,10 +363,8 @@ protected void ProcessEventType(string eventType, JObject body)

case nameof(CurrentProfileChanged):
CurrentProfileChanged?.Invoke(this, new CurrentProfileChangedEventArgs((string)body["profileName"]));
break;

case nameof(ProfileListChanged):
ProfileListChanged?.Invoke(this, new ProfileListChangedEventArgs(JsonConvert.DeserializeObject<List<string>>((string)body["profiles"])));
break; case nameof(ProfileListChanged):
ProfileListChanged?.Invoke(this, new ProfileListChangedEventArgs(JsonSerializer.Deserialize<List<string>>((string)body["profiles"], AppJsonSerializerContext.Default.ListString)));
break;

case nameof(StreamStateChanged):
Expand Down Expand Up @@ -404,7 +396,7 @@ protected void ProcessEventType(string eventType, JObject body)
break;

case nameof(SceneItemTransformChanged):
SceneItemTransformChanged?.Invoke(this, new SceneItemTransformEventArgs((string)body["sceneName"], (string)body["sceneItemId"], new SceneItemTransformInfo((JObject)body["sceneItemTransform"])));
SceneItemTransformChanged?.Invoke(this, new SceneItemTransformEventArgs((string)body["sceneName"], (string)body["sceneItemId"], new SceneItemTransformInfo(body["sceneItemTransform"]?.AsObject())));
break;

case nameof(InputAudioSyncOffsetChanged):
Expand All @@ -420,18 +412,16 @@ protected void ProcessEventType(string eventType, JObject body)
break;

case nameof(SourceFilterCreated):
SourceFilterCreated?.Invoke(this, new SourceFilterCreatedEventArgs((string)body["sourceName"], (string)body["filterName"], (string)body["filterKind"], (int)body["filterIndex"], (JObject)body["filterSettings"], (JObject)body["defaultFilterSettings"]));
SourceFilterCreated?.Invoke(this, new SourceFilterCreatedEventArgs((string)body["sourceName"], (string)body["filterName"], (string)body["filterKind"], (int)body["filterIndex"], body["filterSettings"]?.AsObject(), body["defaultFilterSettings"]?.AsObject()));
break;

case nameof(SourceFilterRemoved):
SourceFilterRemoved?.Invoke(this, new SourceFilterRemovedEventArgs((string)body["sourceName"], (string)body["filterName"]));
break;

case nameof(SourceFilterListReindexed):
break; case nameof(SourceFilterListReindexed):
if (SourceFilterListReindexed != null)
{
List<FilterReorderItem> filters = new List<FilterReorderItem>();
JsonConvert.PopulateObject(body["filters"].ToString(), filters);
filters = JsonSerializer.Deserialize<List<FilterReorderItem>>((string)body["filters"], AppJsonSerializerContext.Default.ListFilterReorderItem);

SourceFilterListReindexed?.Invoke(this, new SourceFilterListReindexedEventArgs((string)body["sourceName"], filters));
}
Expand Down Expand Up @@ -474,7 +464,7 @@ protected void ProcessEventType(string eventType, JObject body)
break;

case nameof(InputCreated):
InputCreated?.Invoke(this, new InputCreatedEventArgs((string)body["inputName"], (string)body["inputKind"], (string)body["unversionedInputKind"], (JObject)body["inputSettings"], (JObject)body["defaultInputSettings"]));
InputCreated?.Invoke(this, new InputCreatedEventArgs((string)body["inputName"], (string)body["inputKind"], (string)body["unversionedInputKind"], body["inputSettings"]?.AsObject(), body["defaultInputSettings"]?.AsObject()));
break;

case nameof(InputRemoved):
Expand All @@ -498,15 +488,13 @@ protected void ProcessEventType(string eventType, JObject body)
break;

case nameof(InputAudioTracksChanged):
InputAudioTracksChanged?.Invoke(this, new InputAudioTracksChangedEventArgs((string)body["inputName"], (JObject)body["inputAudioTracks"]));
InputAudioTracksChanged?.Invoke(this, new InputAudioTracksChangedEventArgs((string)body["inputName"], body["inputAudioTracks"]?.AsObject()));
break;

case nameof(InputAudioMonitorTypeChanged):
InputAudioMonitorTypeChanged?.Invoke(this, new InputAudioMonitorTypeChangedEventArgs((string)body["inputName"], (string)body["monitorType"]));
break;

case nameof(InputVolumeMeters):
InputVolumeMeters?.Invoke(this, new InputVolumeMetersEventArgs(JsonConvert.DeserializeObject<List<JObject>>((string)body["inputs"])));
break; case nameof(InputVolumeMeters):
InputVolumeMeters?.Invoke(this, new InputVolumeMetersEventArgs(JsonSerializer.Deserialize<List<JsonObject>>((string)body["inputs"], AppJsonSerializerContext.Default.ListJsonObject)));
break;

case nameof(ReplayBufferSaved):
Expand Down
Loading