Skip to content

Commit

Permalink
Add Windows Session selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 13, 2020
1 parent 3ac2292 commit fbd2ece
Show file tree
Hide file tree
Showing 40 changed files with 408 additions and 144 deletions.
10 changes: 5 additions & 5 deletions Agent/Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.4" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.4" />
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="7.0.0" />
<PackageReference Include="Microsoft.PowerShell.Commands.Management" Version="7.0.0" />
<PackageReference Include="Microsoft.PowerShell.Commands.Utility" Version="7.0.0" />
Expand Down
5 changes: 4 additions & 1 deletion Agent/Services/DeviceSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ private void RegisterMessageHandlers()
var fileIDs = JsonSerializer.Deserialize<string[]>(Encoding.UTF8.GetString(response));
await HubConnection.SendAsync("DownloadFile", fileIDs[0], senderConnectionID);
});

HubConnection.On("ChangeWindowsSession", async (string serviceID, string requesterID, int sessionID) =>
{
await AppLauncher.LaunchRemoteControl(sessionID, requesterID, serviceID, HubConnection);
});
HubConnection.On("ExecuteCommand", (async (string mode, string command, string commandID, string senderConnectionID) =>
{
if (!IsServerVerified)
Expand Down
6 changes: 3 additions & 3 deletions Desktop.Linux/Desktop.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.9" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.9" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.9" />
<PackageReference Include="Avalonia" Version="0.9.10" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.10" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ScreenCast.Core\ScreenCast.Core.csproj" />
Expand Down
13 changes: 13 additions & 0 deletions ScreenCast.Core/Communication/CasterSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public async Task SendViewerRemoved(string viewerID)
{
await Connection.SendAsync("SendViewerRemoved", viewerID);
}
public async Task SendWindowsSessions(List<WindowsSession> windowsSessions, string viewerID)
{
await Connection.SendAsync("SendWindowsSessions", windowsSessions, viewerID);
}

private void ApplyConnectionHandlers()
{
var conductor = ServiceContainer.Instance.GetRequiredService<Conductor>();
Expand Down Expand Up @@ -250,6 +255,14 @@ private void ApplyConnectionHandlers()
}
});

Connection.On("GetWindowsSessions", async (string viewerID) =>
{
if (conductor.Viewers.TryGetValue(viewerID, out var viewer))
{
await viewer.SendWindowsSessions();
}
});

Connection.On("RequestScreenCast", (string viewerID, string requesterName) =>
{
conductor.InvokeScreenCastRequested(new ScreenCastRequest() { ViewerID = viewerID, RequesterName = requesterName });
Expand Down
22 changes: 12 additions & 10 deletions ScreenCast.Core/Communication/WebRtcSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public WebRtcSession(IRtcMessageHandler rtcMessageHandler)
public bool IsDataChannelOpen => CaptureChannel?.State == DataChannel.ChannelState.Open;
public bool IsPeerConnected => PeerConnection?.IsConnected == true;
private DataChannel CaptureChannel { get; set; }
private PeerConnection PeerConnection { get; set; }
private IceServerModel[] IceServers { get; set; }
private PeerConnection PeerConnection { get; set; }
private IRtcMessageHandler RtcMessageHandler { get; }
public void AddIceCandidate(string sdpMid, int sdpMlineIndex, string candidate)
{
Expand Down Expand Up @@ -72,6 +72,11 @@ public async Task Init(IceServerModel[] iceServers)
CaptureChannel.StateChanged += CaptureChannel_StateChanged;
PeerConnection.CreateOffer();
}
public void SendAudioSample(byte[] audioSample)
{
SendDto(new AudioSampleDto(audioSample));
}

public void SendCaptureFrame(int left, int top, int width, int height, byte[] imageBytes, long imageQuality)
{
for (var i = 0; i < imageBytes.Length; i += 50_000)
Expand Down Expand Up @@ -103,16 +108,15 @@ public void SendClipboardText(string clipboardText)
SendDto(new ClipboardTextDto(clipboardText));
}

public void SendMachineName(string machineName)
public void SendCursorChange(CursorInfo cursorInfo)
{
SendDto(new MachineNameDto(machineName));
SendDto(new CursorChangeDto(cursorInfo.ImageBytes, cursorInfo.HotSpot.X, cursorInfo.HotSpot.Y, cursorInfo.CssOverride));
}

public void SendAudioSample(byte[] audioSample)
public void SendMachineName(string machineName)
{
SendDto(new AudioSampleDto(audioSample));
SendDto(new MachineNameDto(machineName));
}

public void SendScreenData(string selectedScreen, string[] displayNames)
{
SendDto(new ScreenDataDto(selectedScreen, displayNames));
Expand All @@ -122,10 +126,9 @@ public void SendScreenSize(int width, int height)
{
SendDto(new ScreenSizeDto(width, height));
}

public void SendCursorChange(CursorInfo cursorInfo)
public void SendWindowsSessions(List<WindowsSession> windowsSessions)
{
SendDto(new CursorChangeDto(cursorInfo.ImageBytes, cursorInfo.HotSpot.X, cursorInfo.HotSpot.Y, cursorInfo.CssOverride));
SendDto(new WindowsSessionsDto(windowsSessions));
}

public void SetRemoteDescription(string type, string sdp)
Expand Down Expand Up @@ -176,7 +179,6 @@ private void PeerConnection_LocalSdpReadytoSend(string type, string sdp)
Logger.Debug($"Local SDP ready.");
LocalSdpReady?.Invoke(this, sdp);
}

private void SendDto<T>(T dto)
{
CaptureChannel.SendMessage(MessagePackSerializer.Serialize(dto));
Expand Down
27 changes: 19 additions & 8 deletions ScreenCast.Core/Models/Viewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using Remotely.Shared.Helpers;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using Remotely.Shared.Win32;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Threading.Tasks;

Expand Down Expand Up @@ -137,35 +139,44 @@ await SendToViewer(() => RtcSession.SendCursorChange(cursorInfo),
() => CasterSocket.SendCursorChange(cursorInfo, ViewerConnectionID));
}

public async Task SendMachineName(string machineName, string viewerID)
public async Task SendMachineName(string machineName)
{
await SendToViewer(() => RtcSession.SendMachineName(machineName),
() => CasterSocket.SendMachineName(machineName, viewerID));
() => CasterSocket.SendMachineName(machineName, ViewerConnectionID));
}

public async Task SendScreenCapture(byte[] encodedImageBytes, string viewerID, int left, int top, int width, int height)
public async Task SendScreenCapture(byte[] encodedImageBytes, int left, int top, int width, int height)
{
await SendToViewer(() =>
{
RtcSession.SendCaptureFrame(left, top, width, height, encodedImageBytes, ImageQuality);
WebSocketBuffer = 0;
}, async () =>
{
await CasterSocket.SendScreenCapture(encodedImageBytes, viewerID, left, top, width, height, ImageQuality);
await CasterSocket.SendScreenCapture(encodedImageBytes, ViewerConnectionID, left, top, width, height, ImageQuality);
WebSocketBuffer += encodedImageBytes.Length;
});
}

public async Task SendScreenData(string selectedScreen, string[] displayNames, string viewerID)
public async Task SendScreenData(string selectedScreen, string[] displayNames)
{
await SendToViewer(() => RtcSession.SendScreenData(selectedScreen, displayNames),
() => CasterSocket.SendScreenData(selectedScreen, displayNames, viewerID));
() => CasterSocket.SendScreenData(selectedScreen, displayNames, ViewerConnectionID));
}

public async Task SendScreenSize(int width, int height, string viewerID)
public async Task SendScreenSize(int width, int height)
{
await SendToViewer(() => RtcSession.SendScreenSize(width, height),
() => CasterSocket.SendScreenSize(width, height, viewerID));
() => CasterSocket.SendScreenSize(width, height, ViewerConnectionID));
}

public async Task SendWindowsSessions()
{
if (EnvironmentHelper.IsWindows)
{
await SendToViewer(() => RtcSession.SendWindowsSessions(Win32Interop.GetActiveSessions()),
() => CasterSocket.SendWindowsSessions(Win32Interop.GetActiveSessions(), ViewerConnectionID));
}
}

public async Task ThrottleIfNeeded()
Expand Down
10 changes: 5 additions & 5 deletions ScreenCast.Core/ScreenCast.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.4" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="3.1.4" />
<PackageReference Include="Microsoft.MixedReality.WebRTC" Version="1.0.3" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.7.0" />
Expand Down
Loading

0 comments on commit fbd2ece

Please sign in to comment.