mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Extracted idle timer into separate class. Rename namespace.
This commit is contained in:
parent
a694765e9c
commit
a767d2486f
@ -7,7 +7,7 @@ using Remotely.Desktop.Unix.Services;
|
||||
using Remotely.ScreenCast.Core;
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Linux.Capture;
|
||||
using Remotely.ScreenCast.Linux.Input;
|
||||
using Remotely.Shared.Models;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using Remotely.Desktop.Win.Services;
|
||||
using Remotely.Desktop.Win.ViewModels;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
|
||||
@ -4,7 +4,7 @@ using Remotely.Shared.Models;
|
||||
using Remotely.ScreenCast.Core;
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Win;
|
||||
using Remotely.ScreenCast.Win.Capture;
|
||||
using Remotely.ScreenCast.Win.Input;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using Remotely.ScreenCast.Core.Sockets;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
@ -5,7 +5,7 @@ using Remotely.ScreenCast.Core.Enums;
|
||||
using Remotely.ScreenCast.Core.Input;
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using Remotely.ScreenCast.Core.Sockets;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@ -35,12 +35,12 @@ namespace Remotely.ScreenCast.Core
|
||||
public HubConnection Connection { get; private set; }
|
||||
public string CurrentDesktopName { get; set; }
|
||||
public string Host { get; private set; }
|
||||
public IdleTimer IdleTimer { get; set; }
|
||||
public bool IsSwitchingDesktops { get; set; }
|
||||
public AppMode Mode { get; private set; }
|
||||
public string RequesterID { get; private set; }
|
||||
public string ServiceID { get; private set; }
|
||||
public ConcurrentDictionary<string, Viewer> Viewers { get; } = new ConcurrentDictionary<string, Viewer>();
|
||||
public bool IsSwitchingDesktops { get; set; }
|
||||
|
||||
public Task Connect()
|
||||
{
|
||||
Connection = new HubConnectionBuilder()
|
||||
@ -86,37 +86,20 @@ namespace Remotely.ScreenCast.Core
|
||||
CasterSocket = new CasterSocket(Connection, this, keyboardMouse);
|
||||
}
|
||||
|
||||
public void StartWaitForViewerTimer()
|
||||
{
|
||||
var timer = new System.Timers.Timer(10000);
|
||||
timer.AutoReset = false;
|
||||
timer.Elapsed += (sender, arg) =>
|
||||
{
|
||||
// Shut down if no viewers have connected within 10 seconds.
|
||||
if (Viewers.Count == 0)
|
||||
{
|
||||
Logger.Write("No viewers connected after 10 seconds. Shutting down.");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
internal void InvokeAudioToggled(bool toggleOn)
|
||||
{
|
||||
AudioToggled?.Invoke(null, toggleOn);
|
||||
}
|
||||
|
||||
internal void InvokeScreenCastInitiated(ScreenCastRequest viewerIdAndRequesterName)
|
||||
{
|
||||
ScreenCastInitiated?.Invoke(null, viewerIdAndRequesterName);
|
||||
}
|
||||
|
||||
internal void InvokeClipboardTransfer(string transferText)
|
||||
{
|
||||
ClipboardTransferred?.Invoke(null, transferText);
|
||||
}
|
||||
|
||||
internal void InvokeScreenCastInitiated(ScreenCastRequest viewerIdAndRequesterName)
|
||||
{
|
||||
ScreenCastInitiated?.Invoke(null, viewerIdAndRequesterName);
|
||||
}
|
||||
internal void InvokeScreenCastRequested(ScreenCastRequest viewerIdAndRequesterName)
|
||||
{
|
||||
ScreenCastRequested?.Invoke(null, viewerIdAndRequesterName);
|
||||
|
||||
42
ScreenCast.Core/Services/IdleTimer.cs
Normal file
42
ScreenCast.Core/Services/IdleTimer.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Timers;
|
||||
|
||||
namespace Remotely.ScreenCast.Core.Services
|
||||
{
|
||||
public class IdleTimer
|
||||
{
|
||||
public IdleTimer(ConcurrentDictionary<string, Viewer> viewerList)
|
||||
{
|
||||
ViewerList = viewerList;
|
||||
Timer.Elapsed += Timer_Elapsed;
|
||||
}
|
||||
|
||||
public ConcurrentDictionary<string, Viewer> ViewerList { get; }
|
||||
|
||||
public DateTime ViewersLastSeen { get; private set; } = DateTime.Now;
|
||||
|
||||
private Timer Timer { get; } = new Timer(100);
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Timer.Start();
|
||||
}
|
||||
|
||||
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (ViewerList.Count > 0)
|
||||
{
|
||||
ViewersLastSeen = DateTime.Now;
|
||||
}
|
||||
else if (DateTime.Now - ViewersLastSeen > TimeSpan.FromSeconds(10))
|
||||
{
|
||||
Logger.Write("No viewers connected after 10 seconds. Shutting down.");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Remotely.ScreenCast.Core.Utilities
|
||||
namespace Remotely.ScreenCast.Core.Services
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
@ -11,7 +11,7 @@ using Remotely.ScreenCast.Core.Capture;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Core.Input;
|
||||
using Remotely.Shared.Win32;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Linux.X11Interop;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using Remotely.ScreenCast.Core.Input;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Linux.X11Interop;
|
||||
using Remotely.ScreenCast.Core;
|
||||
using System;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using Remotely.Shared.Models;
|
||||
using Remotely.ScreenCast.Core;
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Linux.Capture;
|
||||
using Remotely.ScreenCast.Linux.Input;
|
||||
using Remotely.ScreenCast.Linux.X11Interop;
|
||||
@ -30,7 +30,8 @@ namespace Remotely.ScreenCast.Linux
|
||||
Conductor.ClipboardTransferred += Conductor_ClipboardTransferred;
|
||||
Conductor.CasterSocket.SendDeviceInfo(Conductor.ServiceID, Environment.MachineName).Wait();
|
||||
Conductor.CasterSocket.NotifyRequesterUnattendedReady(Conductor.RequesterID).Wait();
|
||||
Conductor.StartWaitForViewerTimer();
|
||||
Conductor.IdleTimer = new IdleTimer(Conductor.Viewers);
|
||||
Conductor.IdleTimer.Start();
|
||||
while (true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
|
||||
@ -11,7 +11,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using System.Threading;
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using SharpDX;
|
||||
using SharpDX.Direct3D11;
|
||||
using SharpDX.DXGI;
|
||||
|
||||
@ -6,7 +6,7 @@ using Remotely.ScreenCast.Core.Capture;
|
||||
using Remotely.ScreenCast.Core.Enums;
|
||||
using Remotely.ScreenCast.Core.Models;
|
||||
using Remotely.ScreenCast.Core.Sockets;
|
||||
using Remotely.ScreenCast.Core.Utilities;
|
||||
using Remotely.ScreenCast.Core.Services;
|
||||
using Remotely.ScreenCast.Win.Capture;
|
||||
using Remotely.ScreenCast.Win.Input;
|
||||
using System;
|
||||
@ -85,7 +85,8 @@ namespace Remotely.ScreenCast.Win
|
||||
Conductor.CasterSocket.SendDeviceInfo(Conductor.ServiceID, Environment.MachineName).Wait();
|
||||
CheckInitialDesktop();
|
||||
CheckForRelaunch();
|
||||
Conductor.StartWaitForViewerTimer();
|
||||
Conductor.IdleTimer = new IdleTimer(Conductor.Viewers);
|
||||
Conductor.IdleTimer.Start();
|
||||
HandleConnection(Conductor).Wait();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user