/// <summary> /// App constructor /// </summary> /// <param name="worker">Main CEF worker</param> /// <param name="memServer">Shared memory file</param> /// <param name="commServer">TCP server</param> // public App(CefWorker worker, SharedMemServer memServer, SocketServer commServer,bool enableWebRtc) public App(CefWorker worker, SharedMemServer memServer, SharedCommServer inServer, SharedCommServer outServer, bool enableWebRtc) { // _renderProcessHandler = new WorkerCefRenderProcessHandler(); _enableWebRtc = enableWebRtc; _memServer = memServer; _mainWorker = worker; //init SharedMem comms _inCommServer = inServer; _outCommServer = outServer; _mainWorker.SetMemServer(_memServer); //attach dialogs and queries _mainWorker.OnJSDialog += _mainWorker_OnJSDialog; _mainWorker.OnBrowserJSQuery += _mainWorker_OnBrowserJSQuery; //attach page events _mainWorker.OnPageLoaded += _mainWorker_OnPageLoaded; IsRunning = true; _exitTimer = new Timer(); _exitTimer.Interval = 10000; _exitTimer.Tick += _exitTimer_Tick; _exitTimer.Start(); }
static int Main(string[] args) { Log.InfoFormat("start at current directory {0}", Directory.GetCurrentDirectory()); Log.Info("parsing command args"); if (!ParseCommandLine(args)) { Log.Error("command line parse error"); return(0); } Log.InfoFormat("Starting plugin, settings:width:{0},height:{1},url:{2},memfile:{3},inMem:{4},outMem:{5}, WebRtc:{6},Enable GPU:{7}", defWidth, defHeight, defUrl, defFileName, defInFileName, defOutFileName, useWebRTC, EnableGPU); Log.InfoFormat("Statring cef runtime"); if (!CefRintimePrepare(args, temporaryDirectoryPath)) { Log.Error("cef runtime initialisation failed"); return(0); //immediate exit } try { Log.Info("starting cef worker"); CefWorker worker = new CefWorker(); worker.Init(defWidth, defHeight, defUrl); Log.Info("Binding shared memory"); SharedTextureWriter server = new SharedTextureWriter(defFileName, defWidth * defHeight * 4); MessageReader inSrv = MessageReader.Create(defInFileName, 10000); MessageWriter outSrv = MessageWriter.Create(defOutFileName, 10000); Log.Info("complete to bind shared memory, ready and wait"); var app = new App(worker, server, inSrv, outSrv, false); Log.Info("Enter main loop"); try { while (app.IsRunning) { Application.DoEvents(); app.CheckMessage(); //check incoming messages } } catch (Exception e) { Log.ErrorFormat("abnormal exit main loop{0}", e.Message); } Log.Info("Exit main loop END DISPOSING ALL"); worker.Dispose(); server.Dispose(); inSrv.Dispose(); outSrv.Dispose(); } catch (Exception e) { Log.ErrorFormat("Unclean exit error {0}", e.Message); } GC.Collect(); GC.WaitForFullGCComplete(-1); Log.Info("CefRuntime.Shutdown"); CefRuntime.Shutdown(); Log.Info("Final exit"); return(0); }
public WorkerCefClient(int windowWidth, int windowHeight, CefWorker mainCefWorker) { _mainWorker = mainCefWorker; _renderHandler = new WorkerCefRenderHandler(windowWidth, windowHeight); _loadHandler = new WorkerCefLoadHandler(_mainWorker); _lifespanHandler = new WorkerCefLifespanHandler(_mainWorker); _requestHandler = new WorkerCefWebRequestHandler(_mainWorker); _jsDialogHandler = new WorkerCefJSDialogHandler(_mainWorker); _contextMenuHandler = new WorkerCefContextMenuHandler(); }
/// <summary> /// App constructor /// </summary> /// <param name="worker">Main CEF worker</param> /// <param name="memServer">Shared memory file</param> /// <param name="commServer">TCP server</param> public App(CefWorker worker, SharedTextureWriter memServer, MessageReader inServer, MessageWriter outServer, bool enableWebRtc) { // _renderProcessHandler = new WorkerCefRenderProcessHandler(); _enableWebRtc = enableWebRtc; _memServer = memServer; _mainWorker = worker; //init SharedMem comms _inCommServer = inServer; _outCommServer = outServer; _mainWorker.SetMemServer(_memServer); _mainWorker.SetQueryHandler(this); //attach page events _mainWorker.OnPageLoaded += _mainWorker_OnPageLoaded; IsRunning = true; }
static int Main(string[] args) { var version = Environment.Version; Log.InfoFormat("start at current directory {0}", Directory.GetCurrentDirectory()); Log.Info("parsing command args"); if (!ParseCommandLine(args)) { Log.Error("command line parse error"); return(0); } Log.InfoFormat("Starting plugin, settings:{0}", parametres); Log.InfoFormat("Statring cef runtime"); if (!CefRintimePrepare(args, temporaryDirectoryPath)) { Log.Error("cef runtime initialisation failed"); return(0); //immediate exit } try { Log.Info("starting cef worker"); var worker = new CefWorker(parametres.SharedFileName); worker.Init(parametres); Log.Info("Binding shared memory"); SharedTextureWriter server = new SharedTextureWriter(parametres.SharedFileName, parametres.TextureSize); MessageReader inSrv = MessageReader.Create(parametres.inCommFile, 10000); MessageWriter outSrv = MessageWriter.Create(parametres.outCommFile, 10000); Log.Info("complete to bind shared memory, ready and wait"); var app = new App(worker, server, inSrv, outSrv, false); Log.Info("Enter main loop"); try { while (app.IsRunning) { Application.DoEvents(); app.CheckMessage(); //check incoming messages } } catch (Exception e) { Log.ErrorFormat("abnormal exit main loop{0}", e.Message); } Log.Info("Exit main loop END DISPOSING ALL"); worker.Dispose(); server.Dispose(); inSrv.Dispose(); outSrv.Dispose(); } catch (Exception e) { Log.ErrorFormat("Unclean exit error {0}", e.Message); } GC.Collect(); GC.WaitForFullGCComplete(-1); Log.Info("CefRuntime.Shutdown"); CefRuntime.Shutdown(); Log.Info("Final exit"); return(0); }
public WorkerCefLifespanHandler(CefWorker mainCefWorker) { _mainWorker = mainCefWorker; }
public WorkerCefJSDialogHandler(CefWorker mainCefWorker) { _mainWorker = mainCefWorker; }
static int Main(string[] args) { log.Info("===============START================"); //////// CEF RUNTIME try { CefRuntime.Load(); } catch (DllNotFoundException ex) { log.ErrorFormat("{0} error", ex.Message); } catch (CefRuntimeException ex) { log.ErrorFormat("{0} error", ex.Message); } catch (Exception ex) { log.ErrorFormat("{0} error", ex.Message); } int defWidth = 1280; int defHeight = 720; string defUrl = "http://test.webrtc.org"; string defFileName = "MainSharedMem"; string defInFileName = "InSharedMem"; string defOutFileName = "OutSharedMem"; bool useWebRTC = false; bool EnableGPU = false; if (args.Length > 0 && args[0] != "--type=renderer") { if (args.Length > 1) { defWidth = Int32.Parse(args[0]); defHeight = Int32.Parse(args[1]); } if (args.Length > 2) { defUrl = args[2]; } if (args.Length > 3) { defFileName = args[3]; } if (args.Length > 4) { defInFileName = args[4]; } if (args.Length > 5) { defOutFileName = args[5]; } if (args.Length > 6) { if (args[6] == "1") { useWebRTC = true; } } if (args.Length > 7) { if (args[7] == "1") { EnableGPU = true; } } } log.InfoFormat("Starting plugin, settings:width:{0},height:{1},url:{2},memfile:{3},inMem:{4},outMem:{5}, WebRtc:{6},Enable GPU:{7}", defWidth, defHeight, defUrl, defFileName, defInFileName, defOutFileName, useWebRTC, EnableGPU); try { CefMainArgs cefMainArgs; cefMainArgs = new CefMainArgs(args); var cefApp = new WorkerCefApp(useWebRTC, EnableGPU); int exit_code = CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero); if (exit_code >= 0) { log.ErrorFormat("CefRuntime return " + exit_code); return(exit_code); } var cefSettings = new CefSettings { SingleProcess = false, MultiThreadedMessageLoop = true, WindowlessRenderingEnabled = true, LogSeverity = CefLogSeverity.Info, }; try { CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero); } catch (CefRuntimeException ex) { log.ErrorFormat("{0} error", ex.Message); } ///////////// } catch (Exception ex) { log.Info("EXCEPTION ON CEF INITIALIZATION:" + ex.Message + "\n" + ex.StackTrace); throw; } CefWorker worker = new CefWorker(); worker.Init(defWidth, defHeight, defUrl); SharedMemServer server = new SharedMemServer(); server.Init(defWidth * defHeight * 4, defFileName); SharedCommServer inSrv = new SharedCommServer(false); //TODO: the sizes may vary, but 10k should be enough? inSrv.InitComm(10000, defInFileName); SharedCommServer outSrv = new SharedCommServer(true); outSrv.InitComm(10000, defOutFileName); var app = new App(worker, server, inSrv, outSrv, false); while (app.IsRunning) { Application.DoEvents(); //check incoming messages and push outcoming app.CheckMessage(); } CefRuntime.Shutdown(); return(0); }
public WorkerCefWebRequestHandler(CefWorker mainCefWorker) { _mainWorker = mainCefWorker; }
public WorkerCefLoadHandler(CefWorker mainWorker) { _mainWorker = mainWorker; }