Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model object enhancements #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
71 changes: 67 additions & 4 deletions obs-websocket-dotnet/Types/MediaInputStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace OBSWebsocketDotNet.Types
Expand All @@ -12,19 +13,35 @@ public class MediaInputStatus
/// State of the media input
/// </summary>
[JsonProperty(PropertyName = "mediaState")]
public string State { get; set; }
public string StateString { get; set; }

/// <summary>
/// State of the media input
/// </summary>
[JsonIgnore]
public MediaState? State
{
get
{
if (!Enum.TryParse(StateString, out MediaState state))
{
return null;
}
return state;
}
}

/// <summary>
/// Total duration of the playing media in milliseconds. `null` if not playing
/// </summary>
[JsonProperty(PropertyName = "mediaDuration")]
public int? Duration { get; set; }
public long? Duration { get; set; }

/// <summary>
/// Position of the cursor in milliseconds. `null` if not playing
/// </summary>
[JsonProperty(PropertyName = "mediaCursor")]
public int Cursor { get; set; }
public long? Cursor { get; set; }

/// <summary>
/// Instantiate from JObject
Expand All @@ -40,4 +57,50 @@ public MediaInputStatus(JObject body)
/// </summary>
public MediaInputStatus() { }
}

/// <summary>
/// Enum representing the state of a media input
/// </summary>
public enum MediaState
{
/// <summary>
/// No media is loaded
/// </summary>
OBS_MEDIA_STATE_NONE,

/// <summary>
/// Media is playing
/// </summary>
OBS_MEDIA_STATE_PLAYING,

/// <summary>
/// Media is opening
/// </summary>
OBS_MEDIA_STATE_OPENING,

/// <summary>
/// Media is buffering
/// </summary>
OBS_MEDIA_STATE_BUFFERING,

/// <summary>
/// Media is playing but is paused
/// </summary>
OBS_MEDIA_STATE_PAUSED,

/// <summary>
/// Media is stopped
/// </summary>
OBS_MEDIA_STATE_STOPPED,

/// <summary>
/// Media is ended
/// </summary>
OBS_MEDIA_STATE_ENDED,

/// <summary>
/// Media has errored
/// </summary>
OBS_MEDIA_STATE_ERROR
}
}
12 changes: 6 additions & 6 deletions obs-websocket-dotnet/Types/OBSVideoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ public class ObsVideoSettings
/// Numerator of the fractional FPS value
/// </summary>
[JsonProperty(PropertyName = "fpsNumerator")]
public double FpsNumerator { internal set; get; }
public double FpsNumerator { set; get; }

/// <summary>
/// Denominator of the fractional FPS value
/// </summary>
[JsonProperty(PropertyName = "fpsDenominator")]
public double FpsDenominator { internal set; get; }
public double FpsDenominator { set; get; }

/// <summary>
/// Base (canvas) width
/// </summary>
[JsonProperty(PropertyName = "baseWidth")]
public int BaseWidth { internal set; get; }
public int BaseWidth { set; get; }

/// <summary>
/// Base (canvas) height
/// </summary>
[JsonProperty(PropertyName = "baseHeight")]
public int BaseHeight { internal set; get; }
public int BaseHeight { set; get; }

/// <summary>
/// Width of the output resolution in pixels
/// </summary>
[JsonProperty(PropertyName = "outputWidth")]
public int OutputWidth { internal set; get; }
public int OutputWidth { set; get; }

/// <summary>
/// Height of the output resolution in pixels
/// </summary>
[JsonProperty(PropertyName = "outputHeight")]
public int OutputHeight { internal set; get; }
public int OutputHeight { set; get; }
}
}
30 changes: 5 additions & 25 deletions obs-websocket-dotnet/Types/OutputStateChanged.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Newtonsoft.Json.Linq;
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;

namespace OBSWebsocketDotNet.Types
{
Expand Down Expand Up @@ -35,29 +33,11 @@ public OutputState State {
return state.Value;
}

switch (StateStr)
if (!Enum.TryParse(StateStr, ignoreCase: true, out OutputState stateTmp))
{
case "OBS_WEBSOCKET_OUTPUT_STARTING":
state = OutputState.OBS_WEBSOCKET_OUTPUT_STARTING;
break;
case "OBS_WEBSOCKET_OUTPUT_STARTED":
state = OutputState.OBS_WEBSOCKET_OUTPUT_STARTED;
break;
case "OBS_WEBSOCKET_OUTPUT_STOPPING":
state = OutputState.OBS_WEBSOCKET_OUTPUT_STOPPING;
break;
case "OBS_WEBSOCKET_OUTPUT_STOPPED":
state = OutputState.OBS_WEBSOCKET_OUTPUT_STOPPED;
break;
case "OBS_WEBSOCKET_OUTPUT_PAUSED":
state = OutputState.OBS_WEBSOCKET_OUTPUT_PAUSED;
break;
case "OBS_WEBSOCKET_OUTPUT_RESUMED":
state = OutputState.OBS_WEBSOCKET_OUTPUT_RESUMED;
break;
default:
throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException($"Couldn't parse '{StateStr}' as {nameof(OutputState)}");
}
state = stateTmp;

return state.Value;
}
Expand Down
22 changes: 21 additions & 1 deletion obs-websocket-dotnet/Types/StreamingServiceSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace OBSWebsocketDotNet.Types
{
Expand Down Expand Up @@ -36,5 +38,23 @@ public class StreamingServiceSettings
/// </summary>
[JsonProperty(PropertyName = "password")]
public string Password { set; get; }

/// <summary>
/// The service being used to stream
/// </summary>
[JsonProperty(PropertyName = "service")]
public string Service { get; set; }

/// <summary>
/// The protocol to use for the stream
/// </summary>
[JsonProperty(PropertyName = "protocol")]
public string Protocol { get; set; }

/// <summary>
/// Other values not covered by the class
/// </summary>
[JsonExtensionData]
public Dictionary<string, JToken> OtherValues { get; set; }
}
}