Exemplo n.º 1
0
        private ScreenCaptureInfo GetScreen(byte[] receiveBytes)
        {
            int tempOffset = 0;
            var lenBytes   = new byte[4];

            Array.Copy(receiveBytes, tempOffset, lenBytes, 0, 4);
            int alllength = BitConverter.ToInt32(lenBytes, 0);

            tempOffset += 4;
            Array.Copy(receiveBytes, tempOffset, lenBytes, 0, 4);
            int userLength = BitConverter.ToInt32(lenBytes, 0);
            var userBytes  = new byte[userLength];

            tempOffset += 4;
            Array.Copy(receiveBytes, tempOffset, userBytes, 0, userLength);
            string            userString = Encoding.UTF8.GetString(userBytes);
            ScreenCaptureInfo info       = JsonHelper.DeserializeObj <ScreenCaptureInfo>(userString);

            tempOffset += userLength;
            Array.Copy(receiveBytes, tempOffset, lenBytes, 0, 4);
            int imgLength = BitConverter.ToInt32(lenBytes, 0);
            var imgBytes  = new byte[imgLength];

            tempOffset += 4;
            Array.Copy(receiveBytes, tempOffset, imgBytes, 0, imgLength);
            info.Image = FileHelper.ByteArrayToImage(imgBytes);
            return(info);
        }
Exemplo n.º 2
0
 public StudentScreen(ScreenCaptureInfo info)
 {
     InitializeComponent();
     this.picScreen.Image = info.Image;
     this.labName.Text    = info.DisplayName;
     this.UserName        = info.UserName;
 }
Exemplo n.º 3
0
        private void AddStudentScreenToPanel(ScreenCaptureInfo sinfo)
        {
            //var saveAudioFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "screen");
            //if (!Directory.Exists(saveAudioFilePath))
            //{
            //    Directory.CreateDirectory(saveAudioFilePath);
            //}
            //sinfo.Image.Save(Path.Combine(saveAudioFilePath, DateTime.Now.Ticks + ".png"));
            bool isExist = false;

            foreach (StudentScreen item in flowLayoutPanel1.Controls)
            {
                if (item.UserName == sinfo.UserName)
                {
                    isExist = true;
                    item.UpdateScreen(sinfo.Image);
                    break;
                }
            }

            if (!isExist)
            {
                StudentScreen newItem = new StudentScreen(sinfo);
                flowLayoutPanel1.Controls.Add(newItem);
                newItem.Width  = 300;
                newItem.Height = 220;
            }
        }
Exemplo n.º 4
0
        private void GetScreenCapture()
        {
            //  sc = new ScreenCapture();
            //// capture entire screen, and save it to a file
            ////  Image img = sc.CaptureScreen();
            //// display image in a Picture control named imageDisplay
            ////  this.pictureBox1.Image = img;
            //// capture this window, and save it
            //string pathPerc = @"Send.png";
            //string source = @"Capture.png";
            //sc.CaptureScreenToFile(source, ImageFormat.Png);
            //getThumImage(source, 40, 5, pathPerc);
            //string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pathPerc);
            //GlobalVariable.client.SendDesktopPic(fullPath);
            // GlobalVariable.client.CreateUDPStudentHole();
            isRunScreen = true;
            while (isRunScreen)
            {
                lock (obLock)
                {
                    try
                    {
                        Image img     = sc.CaptureScreen();
                        var   thumImg = getThumImage(img, 40, 5);

                        ScreenCaptureInfo info = new ScreenCaptureInfo();
                        info.DisplayName = GlobalVariable.LoginUserInfo.DisplayName;
                        info.UserName    = GlobalVariable.LoginUserInfo.UserName;

                        var    userJson        = JsonHelper.SerializeObj(info);
                        byte[] userBytes       = Encoding.UTF8.GetBytes(userJson);
                        byte[] userLengthBytes = BitConverter.GetBytes(userBytes.Length);
                        byte[] imgBytes        = FileHelper.ImageToByteArray(thumImg);
                        byte[] imgLengthBytes  = BitConverter.GetBytes(imgBytes.Length);
                        byte[] allLengtBytes   = BitConverter.GetBytes(userBytes.Length + userLengthBytes.Length + imgBytes.Length + imgLengthBytes.Length);


                        List <byte> byteSource = new List <byte>();
                        byteSource.AddRange(allLengtBytes);
                        byteSource.AddRange(userLengthBytes);
                        byteSource.AddRange(userBytes);
                        byteSource.AddRange(imgLengthBytes);
                        byteSource.AddRange(imgBytes);
                        var sendBytes = byteSource.ToArray();

                        GlobalVariable.client.SendDesktopPic(sendBytes);
                        // GlobalVariable.client.StopUdp();
                        Thread.Sleep(1000);
                    }
                    catch (Exception ex)
                    {
                        Loger.LogMessage(ex);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void GetScreenCapture()
        {
            isRunScreen = true;
            while (isRunScreen)
            {
                lock (obLock)
                {
                    try
                    {
                        if (sc == null)
                        {
                            sc = new ScreenCapture();
                        }

                        byte[]            imgBytes = sc.GetCaptureScreenToSmallFile(tempScreenFile, ImageFormat.Jpeg);// sc.CaptureScreen();
                        ScreenCaptureInfo info     = new ScreenCaptureInfo();
                        info.DisplayName = GlobalVariable.LoginUserInfo.DisplayName;
                        info.UserName    = GlobalVariable.LoginUserInfo.UserName;

                        var    userJson        = JsonHelper.SerializeObj(info);
                        byte[] userBytes       = Encoding.UTF8.GetBytes(userJson);
                        byte[] userLengthBytes = BitConverter.GetBytes(userBytes.Length);
                        //     byte[] imgBytes = FileHelper.ImageToByteArray(screenImage);
                        byte[] imgLengthBytes = BitConverter.GetBytes(imgBytes.Length);
                        byte[] allLengtBytes  = BitConverter.GetBytes(userBytes.Length + userLengthBytes.Length + imgBytes.Length + imgLengthBytes.Length);


                        List <byte> byteSource = new List <byte>();
                        byteSource.AddRange(allLengtBytes);
                        byteSource.AddRange(userLengthBytes);
                        byteSource.AddRange(userBytes);
                        byteSource.AddRange(imgLengthBytes);
                        byteSource.AddRange(imgBytes);
                        var sendBytes = byteSource.ToArray();

                        udpClient.SendDesktopPic(sendBytes);
                        //   udpClient.WaitUdp();
                        //    Loger.LogMessage("GetScreenCapture:");
                        Thread.Sleep(5000);
                    }
                    catch (Exception ex)
                    {
                        Loger.LogMessage(ex);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void AddScreen(ScreenCaptureInfo sinfo)
        {
            bool isExist = false;

            foreach (StudentScreen item in flowLayoutPanel1.Controls)
            {
                if (item.UserName == sinfo.UserName)
                {
                    isExist = true;
                    item.UpdateScreen(sinfo.Image);
                    break;
                }
            }

            if (!isExist)
            {
                StudentScreen newItem = new StudentScreen(sinfo);
                flowLayoutPanel1.Controls.Add(newItem);
            }
        }
Exemplo n.º 7
0
 private void ReceiveScreenCapture()
 {
     try
     {
         while (true)
         {
             lock (obLock)
             {
                 sinfo = GlobalVariable.client.GetReceieveDesktopInfo();
                 Loger.LogMessage("收到udp信息:" + JsonHelper.SerializeObj(sinfo));
                 this.InvokeOnUiThreadIfRequired(() =>
                 {
                     AddScreen(sinfo);
                 });
                 Thread.Sleep(200);
             }
         }
     }
     catch (Exception ex)
     {
         Loger.LogMessage(ex);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initial WebRtc Component
        /// </summary>
        protected void RtcInitial()
        {
            try
            {
                WebRtcNative.InitializeSSL();
                ServerUrls.GetStunUrls().ForEach(url =>
                {
                    // Set Stun Servers
                    _WebRtc.AddServerConfig(url, string.Empty, string.Empty);
                });

                // Get audio control
                _WebRtc.SetAudio(true);
                _WebRtc.OpenVideoCaptureDevice("");
                // Set Video Capturer
                {
                    IVedioCaptureInfo cptr = new ScreenCaptureInfo();
                    _WebRtc.SetVideoCapturer(cptr.Width, cptr.Height, cptr.CaptureFps);
                }
                // Relative Connection callback
                {
                    // Be triggered On Success to generate Offer
                    _WebRtc.OnSuccessOffer += (sdp) =>
                    {
                        OfferSpdMsg msg = new OfferSpdMsg
                        {
                            Command = SocketMessage.OfferSpd,
                            SDP     = sdp
                        };
                        _SocketClient.Send(JsonConvert.SerializeObject(msg));
                    };

                    // Be triggered On Success to generate ICE
                    _WebRtc.OnIceCandidate += (sdp_mid, sdp_mline_index, sdp) =>
                    {
                        IceCandidateMsg msg = new IceCandidateMsg
                        {
                            Command       = SocketMessage.OnIceCandidate,
                            SDP           = sdp,
                            SdpMid        = sdp_mid,
                            SdpMlineIndex = sdp_mline_index,
                        };
                        _SocketClient.Send(JsonConvert.SerializeObject(msg));
                    };

                    // Be triggered On OfferRequest
                    _WebRtc.OnSuccessAnswer += (sdp) =>
                    {
                        SuccessAnswerMsg msg = new SuccessAnswerMsg
                        {
                            Command = SocketMessage.OnSuccessAnswer,
                            SDP     = sdp
                        };
                        _SocketClient.Send(JsonConvert.SerializeObject(msg));
                    };
                }
                // Set Local and Remote callback
                {
                    _WebRtc.OnRenderLocal  += _OnRenderLocalCallback;
                    _WebRtc.OnRenderRemote += _OnRenderRemoteCallback;
                }
                // Set Other callback
                {
                    _WebRtc.OnSuccessAnswer     += (sdp) => { Debug.WriteLine($"Success Get SDP:{sdp}"); };
                    _WebRtc.OnFailure           += (failure) => { Debug.WriteLine($"Failure Msg:{failure}"); };
                    _WebRtc.OnError             += (error) => { Debug.WriteLine($"Error Msg:{error}"); };
                    _WebRtc.OnDataMessage       += (dmsg) => { Debug.WriteLine($"OnDataMessage: {dmsg}"); };
                    _WebRtc.OnDataBinaryMessage += (dmsg) => { Debug.WriteLine($"OnDataBinaryMessage: {dmsg.Length}"); };
                }
            }
            catch (Exception ex) { }
        }