Ejemplo n.º 1
0
 public Viewer(CasterSocket casterSocket,
               IScreenCapturer screenCapturer,
               IClipboardService clipboardService,
               IWebRtcSessionFactory webRtcSessionFactory,
               IAudioCapturer audioCapturer)
 {
     Capturer             = screenCapturer;
     CasterSocket         = casterSocket;
     WebRtcSessionFactory = webRtcSessionFactory;
     EncoderParams        = new EncoderParameters();
     ImageQuality         = defaultImageQuality;
     ClipboardService     = clipboardService;
     ClipboardService.ClipboardTextChanged += ClipboardService_ClipboardTextChanged;
     AudioCapturer = audioCapturer;
     AudioCapturer.AudioSampleReady += AudioCapturer_AudioSampleReady;
 }
Ejemplo n.º 2
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);
                }, async() =>
                {
                    await 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);
            }, async() =>
            {
                await CasterSocket.SendDtoToViewer(endOfFrameDto, ViewerConnectionID);
            });
        }
Ejemplo n.º 3
0
        public async Task SendScreenCapture(CaptureFrame screenFrame)
        {
            PendingSentFrames.Enqueue(DateTimeOffset.Now);

            var left   = screenFrame.Left;
            var top    = screenFrame.Top;
            var width  = screenFrame.Width;
            var height = screenFrame.Height;

            for (var i = 0; i < screenFrame.EncodedImageBytes.Length; i += 50_000)
            {
                var dto = new CaptureFrameDto()
                {
                    Left         = left,
                    Top          = top,
                    Width        = width,
                    Height       = height,
                    EndOfFrame   = false,
                    ImageBytes   = screenFrame.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));
        }
Ejemplo n.º 4
0
        public async Task InitializeWebRtc()
        {
            try
            {
                var iceServers = await CasterSocket.GetIceServers();

                RtcSession = WebRtcSessionFactory.GetNewSession(this);
                RtcSession.LocalSdpReady += async(sender, sdp) =>
                {
                    await CasterSocket.SendRtcOfferToBrowser(sdp.Content, ViewerConnectionID, iceServers);
                };
                RtcSession.IceCandidateReady += async(sender, candidate) =>
                {
                    await CasterSocket.SendIceCandidateToBrowser(candidate.Content, candidate.SdpMlineIndex, candidate.SdpMid, ViewerConnectionID);
                };

                await RtcSession.Init(iceServers);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }
Ejemplo n.º 5
0
 public async Task SendViewerConnected()
 {
     await CasterSocket.SendViewerConnected(ViewerConnectionID);
 }
Ejemplo n.º 6
0
 public async Task SendCtrlAltDel()
 {
     await CasterSocket.SendCtrlAltDelToAgent();
 }
Ejemplo n.º 7
0
        public async Task ParseMessage(byte[] message)
        {
            try
            {
                var baseDto = MessagePackSerializer.Deserialize <BinaryDtoBase>(message);

                switch (baseDto.DtoType)
                {
                case BinaryDtoType.MouseMove:
                case BinaryDtoType.MouseDown:
                case BinaryDtoType.MouseUp:
                case BinaryDtoType.Tap:
                case BinaryDtoType.MouseWheel:
                case BinaryDtoType.KeyDown:
                case BinaryDtoType.KeyUp:
                case BinaryDtoType.CtrlAltDel:
                case BinaryDtoType.ToggleBlockInput:
                case BinaryDtoType.ClipboardTransfer:
                case BinaryDtoType.KeyPress:
                case BinaryDtoType.SetKeyStatesUp:
                {
                    if (!Viewer.HasControl)
                    {
                        return;
                    }
                }
                break;

                default:
                    break;
                }

                switch (baseDto.DtoType)
                {
                case BinaryDtoType.SelectScreen:
                    SelectScreen(message);
                    break;

                case BinaryDtoType.MouseMove:
                    MouseMove(message);
                    break;

                case BinaryDtoType.MouseDown:
                    MouseDown(message);
                    break;

                case BinaryDtoType.MouseUp:
                    MouseUp(message);
                    break;

                case BinaryDtoType.Tap:
                    Tap(message);
                    break;

                case BinaryDtoType.MouseWheel:
                    MouseWheel(message);
                    break;

                case BinaryDtoType.KeyDown:
                    KeyDown(message);
                    break;

                case BinaryDtoType.KeyUp:
                    KeyUp(message);
                    break;

                case BinaryDtoType.CtrlAltDel:
                    await CasterSocket.SendCtrlAltDel();

                    break;

                case BinaryDtoType.AutoQualityAdjust:
                    SetAutoQualityAdjust(message);
                    break;

                case BinaryDtoType.ToggleAudio:
                    ToggleAudio(message);
                    break;

                case BinaryDtoType.ToggleBlockInput:
                    ToggleBlockInput(message);
                    break;

                case BinaryDtoType.ToggleWebRtcVideo:
                    ToggleWebRtcVideo(message);
                    break;

                case BinaryDtoType.ClipboardTransfer:
                    ClipboardTransfer(message);
                    break;

                case BinaryDtoType.KeyPress:
                    await KeyPress(message);

                    break;

                case BinaryDtoType.QualityChange:
                    QualityChange(message);
                    break;

                case BinaryDtoType.File:
                    await DownloadFile(message);

                    break;

                case BinaryDtoType.WindowsSessions:
                    await GetWindowsSessions();

                    break;

                case BinaryDtoType.SetKeyStatesUp:
                    SetKeyStatesUp();
                    break;

                case BinaryDtoType.FrameReceived:
                    HandleFrameReceived();
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
        }