Dispose of DataChannel before exiting.

This commit is contained in:
Jared Goodwin 2020-08-07 09:23:32 -07:00
parent 44dc4e346c
commit bf89797558
8 changed files with 30 additions and 25 deletions

View File

@ -107,19 +107,28 @@ namespace Remotely.Desktop.Core.Models
}
}
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)
@ -212,7 +221,7 @@ namespace Remotely.Desktop.Core.Models
}
private Task SendToViewer(Action webRtcSend, Func<Task> websocketSend)
{
if (IsUsingWebRtc())
if (IsUsingWebRtc)
{
webRtcSend();
return Task.CompletedTask;

View File

@ -96,12 +96,12 @@ namespace Remotely.Desktop.Core.Services
{
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;

View File

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Remotely.Desktop.Core.Services
@ -56,7 +57,13 @@ namespace Remotely.Desktop.Core.Services
{
try
{
PeerSession?.Close();
Transceiver?.LocalVideoTrack?.Dispose();
VideoSource?.Dispose();
try
{
PeerSession?.RemoveDataChannel(CaptureChannel);
}
catch { }
PeerSession?.Dispose();
}
catch { }

View File

@ -64,10 +64,8 @@ namespace Remotely.Desktop.Win
{
StartUiThread(() => new MainWindow());
}
System.Windows.Forms.Application.Run();
Environment.Exit(0);
System.Windows.Forms.Application.Run();
}
catch (Exception ex)

View File

@ -164,12 +164,7 @@ namespace Remotely.Desktop.Win.Services
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;
}

View File

@ -80,8 +80,6 @@ export function Prompt(promptMessage) {
export function SetScreenSize(width, height) {
ScreenViewer.width = width;
ScreenViewer.height = height;
//VideoScreenViewer.width = width;
//VideoScreenViewer.height = height;
Screen2DContext.clearRect(0, 0, width, height);
}
export function ShowMessage(message) {

File diff suppressed because one or more lines are too long

View File

@ -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);
}