Skip to content

Commit

Permalink
Add per-device WebRTC setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Jan 3, 2021
1 parent 5b51132 commit f299c34
Show file tree
Hide file tree
Showing 21 changed files with 2,540 additions and 25 deletions.
9 changes: 6 additions & 3 deletions Desktop.Core/Services/CasterSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private void ApplyConnectionHandlers()
string requesterName,
bool notifyUser,
bool enforceAttendedAccess,
bool useWebRtc,
string organizationName) =>
{
try
Expand All @@ -219,7 +220,8 @@ private void ApplyConnectionHandlers()
{
NotifyUser = notifyUser,
ViewerID = viewerID,
RequesterName = requesterName
RequesterName = requesterName,
UseWebRtc = useWebRtc
});
}
catch (Exception ex)
Expand Down Expand Up @@ -260,13 +262,14 @@ private void ApplyConnectionHandlers()
}
});

Connection.On("RequestScreenCast", (string viewerID, string requesterName, bool notifyUser) =>
Connection.On("RequestScreenCast", (string viewerID, string requesterName, bool notifyUser, bool useWebRtc) =>
{
conductor.InvokeScreenCastRequested(new ScreenCastRequest()
{
NotifyUser = notifyUser,
ViewerID = viewerID,
RequesterName = requesterName
RequesterName = requesterName,
UseWebRtc = useWebRtc
});
});

Expand Down
4 changes: 2 additions & 2 deletions Desktop.Core/Services/ScreenCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ await viewer.SendScreenCapture(new CaptureFrame[]
}


if (EnvironmentHelper.IsWindows)
if (EnvironmentHelper.IsWindows && screenCastRequest.UseWebRtc)
{
await viewer.InitializeWebRtc();
}
Expand Down Expand Up @@ -149,7 +149,7 @@ await viewer.SendScreenCapture(new CaptureFrame[]
currentFrame?.Dispose();
currentFrame = viewer.Capturer.GetNextFrame();

var diffAreas = ImageUtils.GetDiffAreas(currentFrame, previousFrame, viewer.Capturer.CaptureFullscreen);
var diffAreas = ImageUtils.GetDiffAreas2(currentFrame, previousFrame, viewer.Capturer.CaptureFullscreen);

if (!diffAreas.Any())
{
Expand Down
16 changes: 8 additions & 8 deletions Desktop.Core/Utilities/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,10 @@ private static void AddChangeToList(List<Rectangle> changes, int left, int top,
{
// Bounding box is valid. Padding is necessary to prevent artifacts from
// moving windows.
left = Math.Max(left - 1, 0);
top = Math.Max(top - 1, 0);
right = Math.Min(right + 1, width);
bottom = Math.Min(bottom + 1, height);
left = Math.Max(left - 5, 0);
top = Math.Max(top - 5, 0);
right = Math.Min(right + 5, width);
bottom = Math.Min(bottom + 5, height);

changes.Add(new Rectangle(left, top, right - left, bottom - top));
}
Expand All @@ -511,10 +511,10 @@ private static void AddChangeToList(ConcurrentQueue<Rectangle> changes, int left
{
// Bounding box is valid. Padding is necessary to prevent artifacts from
// moving windows.
left = Math.Max(left - 1, 0);
top = Math.Max(top - 1, 0);
right = Math.Min(right + 1, width);
bottom = Math.Min(bottom + 1, height);
left = Math.Max(left - 5, 0);
top = Math.Max(top - 5, 0);
right = Math.Min(right + 5, width);
bottom = Math.Min(bottom + 5, height);

changes.Enqueue(new Rectangle(left, top, right - left, bottom - top));
}
Expand Down
1 change: 1 addition & 0 deletions Server/Hubs/AgentHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public Task DeviceHeartbeat(Device device)

DataService.AddOrUpdateDevice(device, out var updatedDevice);
Device = updatedDevice;
ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device);

var userIDs = BrowserHub.ConnectionIdToUserLookup.Values.Select(x => x.Id);

Expand Down
16 changes: 12 additions & 4 deletions Server/Hubs/ViewerHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,31 @@ public async Task SendScreenCastRequestToDevice(string screenCasterID, string re
OrganizationID = orgId
});


if (Mode == RemoteControlMode.Unattended)
{
var targetDevice = AgentHub.ServiceConnections[SessionInfo.ServiceID];

var useWebRtc = targetDevice.WebRtcSetting == WebRtcSetting.Default ?
AppConfig.UseWebRtc :
targetDevice.WebRtcSetting == WebRtcSetting.Enabled;


SessionInfo.Mode = RemoteControlMode.Unattended;
var deviceID = AgentHub.ServiceConnections[SessionInfo.ServiceID].ID;

if ((!string.IsNullOrWhiteSpace(otp) &&
RemoteControlFilterAttribute.OtpMatchesDevice(otp, deviceID))
RemoteControlFilterAttribute.OtpMatchesDevice(otp, targetDevice.ID))
||
(Context.User.Identity.IsAuthenticated &&
DataService.DoesUserHaveAccessToDevice(deviceID, Context.UserIdentifier)))
DataService.DoesUserHaveAccessToDevice(targetDevice.ID, Context.UserIdentifier)))
{
var orgName = DataService.GetOrganizationNameById(orgId);
await CasterHubContext.Clients.Client(screenCasterID).SendAsync("GetScreenCast",
Context.ConnectionId,
RequesterName,
AppConfig.RemoteControlNotifyUser,
AppConfig.EnforceAttendedAccess,
useWebRtc,
orgName);
}
else
Expand All @@ -228,7 +236,7 @@ await CasterHubContext.Clients.Client(screenCasterID).SendAsync("GetScreenCast",
{
SessionInfo.Mode = RemoteControlMode.Normal;
await Clients.Caller.SendAsync("RequestingScreenCast");
await CasterHubContext.Clients.Client(screenCasterID).SendAsync("RequestScreenCast", Context.ConnectionId, RequesterName, AppConfig.RemoteControlNotifyUser);
await CasterHubContext.Clients.Client(screenCasterID).SendAsync("RequestScreenCast", Context.ConnectionId, RequesterName, AppConfig.RemoteControlNotifyUser, AppConfig.UseWebRtc);
}
}

Expand Down
Loading

0 comments on commit f299c34

Please sign in to comment.