190 lines
6.5 KiB
C#
190 lines
6.5 KiB
C#
using LiveRecorder.Domain.Enums;
|
|
|
|
namespace LiveRecorder.Domain.Entities;
|
|
|
|
public class LiveRoom
|
|
{
|
|
private LiveRoom()
|
|
{
|
|
}
|
|
|
|
public LiveRoom(
|
|
LivePlatformType platform,
|
|
string sourceUrl,
|
|
string roomId,
|
|
string normalizedUrl,
|
|
DateTimeOffset createdAt)
|
|
{
|
|
Id = Guid.NewGuid();
|
|
Platform = platform;
|
|
SourceUrl = sourceUrl;
|
|
RoomId = roomId;
|
|
NormalizedUrl = normalizedUrl;
|
|
IsEnabled = true;
|
|
AvailabilityStatus = LiveRoomAvailabilityStatus.Unknown;
|
|
CreatedAt = createdAt;
|
|
UpdatedAt = createdAt;
|
|
}
|
|
|
|
public Guid Id { get; private set; }
|
|
|
|
public LivePlatformType Platform { get; private set; }
|
|
|
|
public string SourceUrl { get; private set; } = string.Empty;
|
|
|
|
public string RoomId { get; private set; } = string.Empty;
|
|
|
|
public string NormalizedUrl { get; private set; } = string.Empty;
|
|
|
|
public string? Title { get; private set; }
|
|
|
|
public string? AnchorName { get; private set; }
|
|
|
|
public string? AnchorId { get; private set; }
|
|
|
|
public string? AvatarUrl { get; private set; }
|
|
|
|
public string? CoverUrl { get; private set; }
|
|
|
|
public string? PreferredQualityOverride { get; private set; }
|
|
|
|
public RecordOutputFormat? OutputFormatOverride { get; private set; }
|
|
|
|
public RecordSaveMode? SaveModeOverride { get; private set; }
|
|
|
|
public RecordingTemplateType? RecordingTemplateOverride { get; private set; }
|
|
|
|
public int? SegmentDurationMinutesOverride { get; private set; }
|
|
|
|
public bool? EnableAutoReconnectOverride { get; private set; }
|
|
|
|
public int? ReconnectDelayMaxSecondsOverride { get; private set; }
|
|
|
|
public int? ReadWriteTimeoutMillisecondsOverride { get; private set; }
|
|
|
|
public bool? EnableDanmakuRecordingOverride { get; private set; }
|
|
|
|
public bool? DanmakuIncludeNonChatEventsOverride { get; private set; }
|
|
|
|
public int? DanmakuMinPollIntervalMillisecondsOverride { get; private set; }
|
|
|
|
public int? DanmakuRetryDelayMaxSecondsOverride { get; private set; }
|
|
|
|
public bool IsEnabled { get; private set; }
|
|
|
|
public bool HasSentLiveNotificationForCurrentSession { get; private set; }
|
|
|
|
public LiveRoomAvailabilityStatus AvailabilityStatus { get; private set; }
|
|
|
|
public string? LastAutoStartDecisionCode { get; private set; }
|
|
|
|
public string? LastAutoStartDecisionSummary { get; private set; }
|
|
|
|
public string? LastAutoStartDecisionDetail { get; private set; }
|
|
|
|
public DateTimeOffset? LastAutoStartDecisionAt { get; private set; }
|
|
|
|
public DateTimeOffset CreatedAt { get; private set; }
|
|
|
|
public DateTimeOffset UpdatedAt { get; private set; }
|
|
|
|
public DateTimeOffset? LastCheckedAt { get; private set; }
|
|
|
|
public ICollection<RecordTask> RecordTasks { get; private set; } = new List<RecordTask>();
|
|
|
|
public void UpdateSource(string sourceUrl, string normalizedUrl, DateTimeOffset updatedAt)
|
|
{
|
|
SourceUrl = sourceUrl;
|
|
NormalizedUrl = normalizedUrl;
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
public void UpdateRoomId(string roomId, DateTimeOffset updatedAt)
|
|
{
|
|
RoomId = roomId;
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
public void UpdateMetadata(string? title, string? anchorName, string? anchorId, string? avatarUrl, string? coverUrl, DateTimeOffset updatedAt)
|
|
{
|
|
Title = PreferIncomingValue(title, Title);
|
|
AnchorName = PreferIncomingValue(anchorName, AnchorName);
|
|
AnchorId = PreferIncomingValue(anchorId, AnchorId);
|
|
AvatarUrl = PreferIncomingValue(avatarUrl, AvatarUrl);
|
|
CoverUrl = PreferIncomingValue(coverUrl, CoverUrl);
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
public void UpdateAvailability(LiveRoomAvailabilityStatus availabilityStatus, DateTimeOffset checkedAt)
|
|
{
|
|
AvailabilityStatus = availabilityStatus;
|
|
if (availabilityStatus != LiveRoomAvailabilityStatus.Live)
|
|
{
|
|
HasSentLiveNotificationForCurrentSession = false;
|
|
}
|
|
|
|
LastCheckedAt = checkedAt;
|
|
UpdatedAt = checkedAt;
|
|
}
|
|
|
|
public void SetEnabled(bool isEnabled, DateTimeOffset updatedAt)
|
|
{
|
|
IsEnabled = isEnabled;
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
public void MarkLiveNotificationSent(DateTimeOffset updatedAt)
|
|
{
|
|
HasSentLiveNotificationForCurrentSession = true;
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
public void SetLastAutoStartDecision(
|
|
string? code,
|
|
string? summary,
|
|
string? detail,
|
|
DateTimeOffset decidedAt)
|
|
{
|
|
LastAutoStartDecisionCode = NormalizeNullable(code);
|
|
LastAutoStartDecisionSummary = NormalizeNullable(summary);
|
|
LastAutoStartDecisionDetail = NormalizeNullable(detail);
|
|
LastAutoStartDecisionAt = decidedAt;
|
|
}
|
|
|
|
public void UpdateRecordingSettingsOverrides(
|
|
string? preferredQualityOverride,
|
|
RecordOutputFormat? outputFormatOverride,
|
|
RecordSaveMode? saveModeOverride,
|
|
RecordingTemplateType? recordingTemplateOverride,
|
|
int? segmentDurationMinutesOverride,
|
|
bool? enableAutoReconnectOverride,
|
|
int? reconnectDelayMaxSecondsOverride,
|
|
int? readWriteTimeoutMillisecondsOverride,
|
|
bool? enableDanmakuRecordingOverride,
|
|
bool? danmakuIncludeNonChatEventsOverride,
|
|
int? danmakuMinPollIntervalMillisecondsOverride,
|
|
int? danmakuRetryDelayMaxSecondsOverride,
|
|
DateTimeOffset updatedAt)
|
|
{
|
|
PreferredQualityOverride = NormalizeNullable(preferredQualityOverride);
|
|
OutputFormatOverride = outputFormatOverride;
|
|
SaveModeOverride = saveModeOverride;
|
|
RecordingTemplateOverride = recordingTemplateOverride;
|
|
SegmentDurationMinutesOverride = segmentDurationMinutesOverride;
|
|
EnableAutoReconnectOverride = enableAutoReconnectOverride;
|
|
ReconnectDelayMaxSecondsOverride = reconnectDelayMaxSecondsOverride;
|
|
ReadWriteTimeoutMillisecondsOverride = readWriteTimeoutMillisecondsOverride;
|
|
EnableDanmakuRecordingOverride = enableDanmakuRecordingOverride;
|
|
DanmakuIncludeNonChatEventsOverride = danmakuIncludeNonChatEventsOverride;
|
|
DanmakuMinPollIntervalMillisecondsOverride = danmakuMinPollIntervalMillisecondsOverride;
|
|
DanmakuRetryDelayMaxSecondsOverride = danmakuRetryDelayMaxSecondsOverride;
|
|
UpdatedAt = updatedAt;
|
|
}
|
|
|
|
private static string? PreferIncomingValue(string? incomingValue, string? existingValue) =>
|
|
string.IsNullOrWhiteSpace(incomingValue) ? existingValue : incomingValue;
|
|
|
|
private static string? NormalizeNullable(string? value) =>
|
|
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
|
}
|