Beispiel #1
0
        public async Task SendScreenData(string selectedScreen, string[] displayNames)
        {
            var dto = new ScreenDataDto(selectedScreen, displayNames);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #2
0
        public async Task SendScreenSize(int width, int height)
        {
            var dto = new ScreenSizeDto(width, height);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #3
0
        public async Task SendClipboardText(string clipboardText)
        {
            var dto = new ClipboardTextDto(clipboardText);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #4
0
        public async Task SendMachineName(string machineName)
        {
            var dto = new MachineNameDto(machineName);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #5
0
        public async Task SendAudioSample(byte[] audioSample)
        {
            var dto = new AudioSampleDto(audioSample);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #6
0
        public async Task SendCursorChange(CursorInfo cursorInfo)
        {
            var dto = new CursorChangeDto(cursorInfo.ImageBytes, cursorInfo.HotSpot.X, cursorInfo.HotSpot.Y, cursorInfo.CssOverride);

            await SendToViewer(() => RtcSession.SendDto(dto),
                               () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
        }
Beispiel #7
0
        public async Task SendScreenCapture(byte[] encodedImageBytes, int left, int top, int width, int height)
        {
            PendingSentFrames.Enqueue(DateTimeOffset.Now);

            for (var i = 0; i < encodedImageBytes.Length; i += 50_000)
            {
                var dto = new CaptureFrameDto()
                {
                    Left         = left,
                    Top          = top,
                    Width        = width,
                    Height       = height,
                    EndOfFrame   = false,
                    ImageBytes   = encodedImageBytes.Skip(i).Take(50_000).ToArray(),
                    ImageQuality = imageQuality
                };

                await SendToViewer(() => RtcSession.SendDto(dto),
                                   () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
            }

            var endOfFrameDto = new CaptureFrameDto()
            {
                Left         = left,
                Top          = top,
                Width        = width,
                Height       = height,
                EndOfFrame   = true,
                ImageQuality = imageQuality
            };

            await SendToViewer(() => RtcSession.SendDto(endOfFrameDto),
                               () => CasterSocket.SendDtoToViewer(endOfFrameDto, ViewerConnectionID));
        }
Beispiel #8
0
        public async Task SendFile(FileUpload fileUpload, Action <double> progressUpdateCallback)
        {
            try
            {
                var messageId = Guid.NewGuid().ToString();
                var fileDto   = new FileDto()
                {
                    EndOfFile   = false,
                    FileName    = fileUpload.DisplayName,
                    MessageId   = messageId,
                    StartOfFile = true
                };

                await SendToViewer(() => RtcSession.SendDto(fileDto),
                                   () => CasterSocket.SendDtoToViewer(fileDto, ViewerConnectionID));

                using var fs = File.OpenRead(fileUpload.FilePath);
                using var br = new BinaryReader(fs);
                while (fs.Position < fs.Length)
                {
                    fileDto = new FileDto()
                    {
                        Buffer    = br.ReadBytes(50_000),
                        FileName  = fileUpload.DisplayName,
                        MessageId = messageId
                    };

                    await SendToViewer(async() =>
                    {
                        await RtcSession.SendDto(fileDto);
                        //await TaskHelper.DelayUntilAsync(() => RtcSession.CurrentBuffer > 0, TimeSpan.FromSeconds(1), 100);
                        await TaskHelper.DelayUntilAsync(() => RtcSession.CurrentBuffer == 0, TimeSpan.MaxValue, 100);
                    },
                                       async() =>
                    {
                        await CasterSocket.SendDtoToViewer(fileDto, ViewerConnectionID);
                    });

                    progressUpdateCallback((double)fs.Position / fs.Length);
                }

                fileDto = new FileDto()
                {
                    EndOfFile   = true,
                    FileName    = fileUpload.DisplayName,
                    MessageId   = messageId,
                    StartOfFile = false
                };

                await SendToViewer(() => RtcSession.SendDto(fileDto),
                                   () => CasterSocket.SendDtoToViewer(fileDto, ViewerConnectionID));

                progressUpdateCallback(1);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }
Beispiel #9
0
        public async Task SendScreenCapture(IEnumerable <CaptureFrame> screenFrame)
        {
            PendingSentFrames.Enqueue(DateTimeOffset.Now);

            foreach (var frame in screenFrame)
            {
                var left   = frame.Left;
                var top    = frame.Top;
                var width  = frame.Width;
                var height = frame.Height;

                for (var i = 0; i < frame.EncodedImageBytes.Length; i += 50_000)
                {
                    var dto = new CaptureFrameDto()
                    {
                        Left         = left,
                        Top          = top,
                        Width        = width,
                        Height       = height,
                        EndOfFrame   = false,
                        ImageBytes   = frame.EncodedImageBytes.Skip(i).Take(50_000).ToArray(),
                        ImageQuality = _imageQuality,
                        EndOfCapture = false
                    };

                    await SendToViewer(() => RtcSession.SendDto(dto),
                                       () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
                }

                var endOfFrameDto = new CaptureFrameDto()
                {
                    Left         = left,
                    Top          = top,
                    Width        = width,
                    Height       = height,
                    EndOfFrame   = true,
                    ImageQuality = _imageQuality,
                    EndOfCapture = false
                };

                await SendToViewer(() => RtcSession.SendDto(endOfFrameDto),
                                   () => CasterSocket.SendDtoToViewer(endOfFrameDto, ViewerConnectionID));
            }

            var endofCaptureDto = new CaptureFrameDto()
            {
                Left         = 0,
                Top          = 0,
                Width        = 0,
                Height       = 0,
                EndOfFrame   = true,
                ImageQuality = _imageQuality,
                EndOfCapture = true
            };

            await SendToViewer(() => RtcSession.SendDto(endofCaptureDto),
                               () => CasterSocket.SendDtoToViewer(endofCaptureDto, ViewerConnectionID));
        }
Beispiel #10
0
 public async Task SendWindowsSessions()
 {
     if (EnvironmentHelper.IsWindows)
     {
         var dto = new WindowsSessionsDto(Win32Interop.GetActiveSessions());
         await SendToViewer(() => RtcSession.SendDto(dto),
                            () => CasterSocket.SendDtoToViewer(dto, ViewerConnectionID));
     }
 }