internal static ActionContext GetActionContext(this CdpResponse response) { var name = response.GetStrValue("params.name"); var plstr = response.GetStrValue("params.payload"); if (!string.IsNullOrEmpty(plstr)) { var jo = JObject.Parse(plstr); if (jo.HasValues) { var id = jo["id"].ToObject <int>(); return(new ActionContext(name, id, jo["args"])); } } return(null); }
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()); } }
internal static CdpResponse GetSessionMessage(this CdpResponse response) { if (response.HasToken("params.message")) { var tkval = response.GetStrValue("params.message"); if (!string.IsNullOrEmpty(tkval)) { return(new CdpResponse(tkval)); } } return(null); }
internal static bool HasKeyValue(this CdpResponse response, string key, string value) { return(string.Compare(response.GetStrValue(key), value, true) == 0); }