public async Task Execute(ConnectCmd message, CancellationToken token) { _cwsUrl = message.WsUrl; await StartConnect(token); _logger.LogInformation($"Connected to {message.WsUrl}"); await Send(CdpApi.GetDiscoverTargetsMsg()); }
private void HandleCdpResponse(CdpResponse response) { if (response.IsMsgTargetPageCreated()) { _cdpTargetId = response.GetStrValue("params.targetInfo.targetId"); _logger.LogInformation($"Target Id : {_cdpTargetId}"); Send(CdpApi.GetOpenSessionMsg(_cdpTargetId)).Wait(); return; } if (response.IsMsgSessionCreated()) { _cdpSessionId = response.GetStrValue("result.sessionId"); _logger.LogInformation($"Session Id : {_cdpSessionId}"); foreach (var setting in CdpApi.Configuration) { Publish(setting, new { }); } Publish(CdpApi.Methods.TargetAutoAttach, CdpApi.TargetAutoAttachConfig); Publish(CdpApi.Methods.BrowserGetWinTarget, new { targetId = _cdpTargetId }, (rq, rs) => { rs.WithVal <int>("result.windowId", x => { _cdpWindowId = x; }); _logger.LogInformation($"Window Id : {_cdpWindowId}"); HandleActionResult(_routeService.Execute(NBlinkContext.DefaultRoute())); }); return; } if (string.IsNullOrEmpty(_cdpSessionId)) { return; } if (response.IsMsgFromTargetSession(_cdpSessionId)) { HandleTargetSessionMsg(response); return; } if (response.IsMsgTargetDestroyed(_cdpTargetId)) { _logger.LogError($"{_cdpTargetId} destroyed s******g down application..."); _dispatcher.Publish(new ExitCmd()); } }
private void AddPageScript(string script) { if (_addedInvokerScripts) { return; } Publish(CdpApi.AddScript(script), (r, rs) => { Publish(CdpApi.EvalMsg(script), (r1, rs1) => { foreach (var name in _routeService.GetBindingRoutes()) { Publish(CdpApi.AddBinding(name), (r2, rs2) => Publish(CdpApi.EvalMsg($"bindCode('{name}');"))); } _addedInvokerScripts = true; }); }); }
private void HandleActionResult(ActionResult result) { switch (result) { case NavigateResult nr: { Publish(CdpApi.Navigate(nr.Url.ToString()), (pr, px) => { Publish(CdpApi.SetWindowBounds(_cdpWindowId, nr.Width, nr.Height)); AddPageScript(CdpApi.Scripts.GetInvokerScript()); }); break; } case BindingResult jr: { Publish(CdpApi.EvalMsg(CdpApi.Scripts.GetEvalRequest(jr))); break; } } }