コード例 #1
0
        public void ExecJSScript(string data)
        {
            var msg = new PipeProtoMessage()
            {
                Opcode = PipeProto.OPCODE_SCRIPT, Payload = System.Text.Encoding.UTF8.GetBytes(data)
            };

            cef.SendMessage(msg);
        }
コード例 #2
0
        public void LoadPage(string url)
        {
            var msg = new PipeProtoMessage()
            {
                Opcode = PipeProto.OPCODE_NAVIGATE, Payload = System.Text.Encoding.UTF8.GetBytes(url)
            };

            cef.SendMessage(msg);
        }
コード例 #3
0
        public void HandleIncomingMessage(PipeProtoMessage incomingMessage)
        {
            LastActivity = DateTime.Now;

            switch (incomingMessage.Opcode)
            {
            case PipeProto.OPCODE_PING:

                GotRemotePing = true;
                break;

            case PipeProto.OPCODE_FRAME:

                runner.AddTask(new RepaintFrameTask());
                break;

            case PipeProto.OPCODE_MOUSE_EVENT:

                runner.AddTask(new SetMouseTask(new CefUnityLib.Messages.MouseEventPipeMessage(incomingMessage.Payload)));
                break;

            case PipeProto.OPCODE_MOUSE_WHEEL_EVENT:

                runner.AddTask(new SendMouseWheelEventTask(new CefUnityLib.Messages.MouseWheelEventPipeMessage(incomingMessage.Payload)));
                break;

            case PipeProto.OPCODE_KEY_EVENT:

                runner.AddTask(new SendKeyEventTask(new CefUnityLib.Messages.KeyEventPipeMessage(incomingMessage.Payload)));
                break;

            case PipeProto.OPCODE_SHUTDOWN:

                runner.AddTask(new ShutdownTask());
                break;

            case PipeProto.OPCODE_NAVIGATE:

                runner.AddTask(new NavigateTask(Encoding.UTF8.GetString(incomingMessage.Payload)));
                break;

            case PipeProto.OPCODE_RESIZE:

                runner.AddTask(new ResizeTask(Encoding.UTF8.GetString(incomingMessage.Payload)));
                break;

            case PipeProto.OPCODE_SCRIPT:

                runner.AddTask(new ExecScriptTask(Encoding.UTF8.GetString(incomingMessage.Payload)));
                break;

            default:

                Logr.Log("Pipe server error. Could not route message due to unrecognized packet opcode:", incomingMessage.Opcode);
                break;
            }
        }
コード例 #4
0
    protected void OnCefMessage(object sender, PipeProtoMessage p)
    {
        switch (p.Opcode)
        {
        case PipeProto.OPCODE_FRAME:

            frameBuffer        = p.Payload;
            frameBufferChanged = true;
            break;
        }
    }
コード例 #5
0
        public void ResizePage(int width, int height)
        {
            var msg = new PipeProtoMessage()
            {
                Opcode = PipeProto.OPCODE_RESIZE, Payload = System.Text.Encoding.UTF8.GetBytes(width + "x" + height)
            };

            cef.SendMessage(msg);
            this.width  = width;
            this.height = height;
            var tex = new Texture2D(width, height, TextureFormat.BGRA32, false);

            tempImageLength = tex.GetRawTextureData().Length;
            tex             = null;
            sizeChanged     = true;
        }
コード例 #6
0
        protected void OnCefMessage(object sender, PipeProtoMessage p)
        {
            switch (p.Opcode)
            {
            case PipeProto.OPCODE_FRAME:

                frameBuffer        = p.Payload;
                frameBufferChanged = true;
                break;

            case PipeProto.OPCODE_SCRIPT:
                var msg = Encoding.UTF8.GetString(p.Payload);
                Debug.Log(msg);
                break;
            }
        }
コード例 #7
0
        public void MessageReceived(object sender, PipeProtoMessage e)
        {
            switch (e.Opcode)
            {
            case PipeProto.OPCODE_FRAME:

                frameCounterStat++;
                frameCounterCurrent++;

                Rectangle  rect    = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height);
                BitmapData bmpData = _texture.LockBits(rect, ImageLockMode.WriteOnly, _texture.PixelFormat);
                IntPtr     ptr     = bmpData.Scan0;
                System.Runtime.InteropServices.Marshal.Copy(e.Payload, 0, ptr, e.Payload.Length);
                _texture.UnlockBits(bmpData);
                pictureBox1.Image = _texture;
                break;
            }
        }
コード例 #8
0
        public void MessageReceived(object sender, PipeProtoMessage e)
        {
            switch (e.Opcode)
            {
            case PipeProto.OPCODE_FRAME:
                _frameCounterStat++;
                _frameCounterCurrent++;

                var rect    = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height);
                var texture = new Bitmap(defWidth, defHeight);
                var bmpData = texture.LockBits(rect, ImageLockMode.WriteOnly, texture.PixelFormat);

                IntPtr ptr = bmpData.Scan0;
                System.Runtime.InteropServices.Marshal.Copy(e.Payload, 0, ptr, e.Payload.Length);

                texture.UnlockBits(bmpData);
                pictureBox1.Image = texture;

                // NB: Disposing of the texture causes awful issues where the PictureBox will try to access it and crash.
                // Also, re-using the same texture causes locking issues when testing high FPS.
                // Conclusion: we are intentionally leaking memory here, and hoping GC will clean up unused textures fast enough.
                break;
            }
        }
コード例 #9
0
        public void StartAsNewTask()
        {
            // Background task thread: Auto shutdown after inactivity
            Task.Run(new Action(() =>
            {
                while (KeepAlive)
                {
                    DoAutoShutdownCheck();
                    Thread.Sleep(1000);
                }
            }));

            // Background task thread: Accept connections and receive incoming data
            Task.Run(new Action(() =>
            {
                LastActivity = DateTime.Now;

                while (KeepAlive)
                {
                    DoAutoShutdownCheck();

                    if (stream == null)
                    {
                        stream = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                        Logr.Log(String.Format("Started named pipe server [{0}].", pipeName));
                    }

                    try
                    {
                        GotRemotePing = false;
                        stream.WaitForConnection();
                    }
                    catch (Exception e)
                    {
                        Logr.Log("Named pipe: Connection is failing.", e.Message);
                        KillStream();
                        continue;
                    }

                    try
                    {
                        Logr.Log("Named pipe: New connection established.");

                        // Force a repaint to cause frame to be re-sent to the connecting client
                        runner.AddTask(new RepaintFrameTask());

                        while (stream.CanRead && KeepAlive)
                        {
                            var incomingMessage = PipeProtoMessage.ReadFromStream(stream);

                            if (incomingMessage != null)
                            {
                                Task.Run(new Action(() =>
                                {
                                    HandleIncomingMessage(incomingMessage);
                                }));
                            }
                        }

                        Logr.Log("Named pipe: Connection is closing.");
                    }
                    catch (Exception ex)
                    {
                        Logr.Log("Named pipe connection had an unexpected failure:", ex.Message, ex);
                    }
                }

                Logr.Log("Named pipe server has shut down.");

                KillStream();
            }));
        }