Skip to content

Commit

Permalink
Dispose of DataChannel before exiting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Aug 7, 2020
1 parent 0027d9e commit 4686fc6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
23 changes: 16 additions & 7 deletions Desktop.Core/Models/Viewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,28 @@ public async Task InitializeWebRtc()
}
}

public bool IsUsingWebRtcVideo()
public bool IsUsingWebRtcVideo
{
return RtcSession?.IsVideoTrackConnected == true;
get
{
return RtcSession?.IsPeerConnected == true && RtcSession?.IsVideoTrackConnected == true;
}
}

public bool IsStalled()
public bool IsStalled
{
return PendingSentFrames.TryPeek(out var result) && DateTimeOffset.Now - result > TimeSpan.FromSeconds(15);
get
{
return PendingSentFrames.TryPeek(out var result) && DateTimeOffset.Now - result > TimeSpan.FromSeconds(15);
}
}

public bool IsUsingWebRtc()
public bool IsUsingWebRtc
{
return RtcSession?.IsPeerConnected == true && RtcSession?.IsDataChannelOpen == true;
get
{
return RtcSession?.IsPeerConnected == true && RtcSession?.IsDataChannelOpen == true;
}
}

public async Task SendAudioSample(byte[] audioSample)
Expand Down Expand Up @@ -212,7 +221,7 @@ private async void ClipboardService_ClipboardTextChanged(object sender, string c
}
private Task SendToViewer(Action webRtcSend, Func<Task> websocketSend)
{
if (IsUsingWebRtc())
if (IsUsingWebRtc)
{
webRtcSend();
return Task.CompletedTask;
Expand Down
6 changes: 3 additions & 3 deletions Desktop.Core/Services/ScreenCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public async Task BeginScreenCasting(ScreenCastRequest screenCastRequest)
{
try
{
if (viewer.IsUsingWebRtcVideo())
if (viewer.IsUsingWebRtcVideo)
{
Thread.Sleep(10);
Thread.Sleep(100);
continue;
}
if (viewer.IsStalled())
if (viewer.IsStalled)
{
// Viewer isn't responding. Abort sending.
break;
Expand Down
9 changes: 8 additions & 1 deletion Desktop.Core/Services/WebRtcSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Remotely.Desktop.Core.Services
Expand Down Expand Up @@ -56,7 +57,13 @@ public void Dispose()
{
try
{
PeerSession?.Close();
Transceiver?.LocalVideoTrack?.Dispose();
VideoSource?.Dispose();
try
{
PeerSession?.RemoveDataChannel(CaptureChannel);
}
catch { }
PeerSession?.Dispose();
}
catch { }
Expand Down
4 changes: 1 addition & 3 deletions Desktop.Win/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ public static void Main(string[] args)
{
StartUiThread(() => new MainWindow());
}

System.Windows.Forms.Application.Run();

Environment.Exit(0);
System.Windows.Forms.Application.Run();

}
catch (Exception ex)
Expand Down
7 changes: 1 addition & 6 deletions Desktop.Win/Services/ScreenCapturerWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ private Bitmap GetBitBltFrame()
catch (Exception ex)
{
Logger.Write(ex);
Logger.Write("Capturer error. Trying to switch desktops in BitBltCapture.");
if (Win32Interop.SwitchToInputDesktop())
{
Win32Interop.GetCurrentDesktop(out var desktopName);
Logger.Write($"Switch to desktop {desktopName} after capture error in BitBltCapture.");
}
Logger.Write("Capturer error in BitBltCapture.");
NeedsInit = true;
}

Expand Down
2 changes: 0 additions & 2 deletions Server/wwwroot/scripts/RemoteControl/UI.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/RemoteControl/UI.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Server/wwwroot/scripts/RemoteControl/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ export function Prompt(promptMessage: string): Promise<string> {
export function SetScreenSize(width: number, height: number) {
ScreenViewer.width = width;
ScreenViewer.height = height;
//VideoScreenViewer.width = width;
//VideoScreenViewer.height = height;
Screen2DContext.clearRect(0, 0, width, height);
}

Expand Down

0 comments on commit 4686fc6

Please sign in to comment.