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

#136: Writing error logs to an ILogger instead of Console, adding an event for Unsupported Events, and other fixes #137

Closed
wants to merge 7 commits into from
Closed
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
10 changes: 8 additions & 2 deletions obs-websocket-dotnet/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using OBSWebsocketDotNet.Types.Events;
using Microsoft.Extensions.Logging;

namespace OBSWebsocketDotNet
{
Expand Down Expand Up @@ -290,6 +291,11 @@ public partial class OBSWebsocket
/// </summary>
public event EventHandler<SceneNameChangedEventArgs> SceneNameChanged;

/// <summary>
/// An unsupported event has been received.
/// </summary>
public event EventHandler<UnsupportedEventArgs> UnsupportedEvent;

#endregion

#region EventProcessing
Expand Down Expand Up @@ -521,8 +527,8 @@ protected void ProcessEventType(string eventType, JObject body)

default:
var message = $"Unsupported Event: {eventType}\n{body}";
Console.WriteLine(message);
Debug.WriteLine(message);
Logger?.LogInformation(message);
UnsupportedEvent?.Invoke(this, new UnsupportedEventArgs(eventType, body));
break;
}
}
Expand Down
8 changes: 8 additions & 0 deletions obs-websocket-dotnet/OBSWebsocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using System.Net.WebSockets;
using Websocket.Client;
using OBSWebsocketDotNet.Communication;
using Websocket.Client.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace OBSWebsocketDotNet
{
Expand Down Expand Up @@ -59,6 +62,11 @@ public bool IsConnected
}
}

/// <summary>
/// Gets or sets the logger for this instance
/// </summary>
public ILogger<OBSWebsocket> Logger { get; set; } = NullLogger<OBSWebsocket>.Instance;

/// <summary>
/// Constructor
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions obs-websocket-dotnet/OBSWebsocket_Requests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OBSWebsocketDotNet.Types;
using System;
Expand Down Expand Up @@ -339,7 +340,7 @@ public bool RemoveSourceFilter(string sourceName, string filterName)
catch (Exception e)
{
//TODO exception handling
Console.WriteLine(e.Message);
Logger?.LogError(e, "Error removing filter");
}
return false;
}
Expand Down
29 changes: 29 additions & 0 deletions obs-websocket-dotnet/Types/Events/UnsupportedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Newtonsoft.Json.Linq;

namespace OBSWebsocketDotNet.Types.Events
{
/// <summary>
/// Event args for unsupported events
/// </summary>
public class UnsupportedEventArgs : EventArgs
{
/// <summary>
/// The type of the event
/// </summary>
public string EventType { get; }
/// <summary>
/// The body of the event
/// </summary>
public JObject Body { get; }

/// <summary>
/// Event args for unsupported events
/// </summary>
public UnsupportedEventArgs(string eventType, JObject body)
{
EventType = eventType;
Body = body;
}
}
}
70 changes: 66 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,34 @@ 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>
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 +56,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; }
}
}
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; }
}
}
3 changes: 2 additions & 1 deletion obs-websocket-dotnet/obs-websocket-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ What's new in v5.0.0.3
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>E:\Projects\GitHub\obs-websocket-dotnet-standard\obs-websocket-dotnet\obs-websocket-dotnet.xml</DocumentationFile>
<DocumentationFile>obs-websocket-dotnet.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Websocket.Client" Version="4.4.43" />
</ItemGroup>
Expand Down
Loading