MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / handle_incoming_message

Function handle_incoming_message

packages/server/src/inspector.rs:739–775  ·  view source on GitHub ↗
(
    hub: &InspectorHub,
    handle: &InspectorAgentHandle,
    pending: &PendingResponses,
    process_identifier: &Arc<Mutex<Option<i64>>>,
    text: &str,
)

Source from the content-addressed store, hash-verified

737}
738
739async fn handle_incoming_message(
740 hub: &InspectorHub,
741 handle: &InspectorAgentHandle,
742 pending: &PendingResponses,
743 process_identifier: &Arc<Mutex<Option<i64>>>,
744 text: &str,
745) {
746 let Ok(value) = serde_json::from_str::<Value>(text) else {
747 return;
748 };
749
750 if value.get("id").and_then(Value::as_u64).is_some() {
751 complete_pending_response_value(pending, value).await;
752 return;
753 }
754
755 let method = value
756 .get("method")
757 .or_else(|| value.get("event"))
758 .and_then(Value::as_str);
759 if method != Some("Inspector.ready") {
760 return;
761 }
762
763 let info = value
764 .get("params")
765 .or_else(|| value.get("info"))
766 .cloned()
767 .unwrap_or(Value::Null);
768 let Some(pid) = info.get("processIdentifier").and_then(Value::as_i64) else {
769 warn!("NativeScript inspector ready event did not report processIdentifier.");
770 return;
771 };
772
773 *process_identifier.lock().await = Some(pid);
774 hub.register(pid, handle.with_info(info)).await;
775}
776
777async fn complete_pending_response_value(pending: &PendingResponses, value: Value) {
778 let Some(id) = value.get("id").and_then(Value::as_u64) else {

Callers 1

handle_socketMethod · 0.85

Calls 4

registerMethod · 0.80
with_infoMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected