MCPcopy Index your code
hub / github.com/NativeScript/SimDeck / handle_socket

Method handle_socket

packages/server/src/inspector.rs:116–211  ·  view source on GitHub ↗
(&self, socket: WebSocket)

Source from the content-addressed store, hash-verified

114 }
115
116 pub async fn handle_socket(&self, socket: WebSocket) {
117 let connection_id = self.allocate_connection_id().await;
118 let (mut sender, mut receiver) = socket.split();
119 let (outgoing_tx, mut outgoing_rx) = mpsc::channel::<Value>(32);
120 let outbox = Arc::new(Mutex::new(VecDeque::new()));
121 let outbox_notify = Arc::new(Notify::new());
122 let pending = Arc::new(Mutex::new(HashMap::new()));
123 let process_identifier = Arc::new(Mutex::new(None::<i64>));
124
125 let writer = tokio::spawn(async move {
126 while let Some(message) = outgoing_rx.recv().await {
127 if sender
128 .send(Message::Text(message.to_string().into()))
129 .await
130 .is_err()
131 {
132 break;
133 }
134 }
135 });
136
137 let handle = InspectorAgentHandle {
138 connection_id,
139 created_at: Instant::now(),
140 info: Value::Null,
141 outgoing: outgoing_tx,
142 outbox,
143 outbox_notify,
144 pending,
145 next_request_id: Arc::new(AtomicU64::new(1)),
146 };
147
148 let reader_hub = self.clone();
149 let reader_handle = handle.clone();
150 let reader_pending = reader_handle.pending.clone();
151 let reader_process_identifier = process_identifier.clone();
152 tokio::spawn(async move {
153 while let Some(message) = receiver.next().await {
154 match message {
155 Ok(Message::Text(text)) => {
156 handle_incoming_message(
157 &reader_hub,
158 &reader_handle,
159 &reader_pending,
160 &reader_process_identifier,
161 text.as_str(),
162 )
163 .await;
164 }
165 Ok(Message::Binary(bytes)) => {
166 if let Ok(text) = std::str::from_utf8(&bytes) {
167 handle_incoming_message(
168 &reader_hub,
169 &reader_handle,
170 &reader_pending,
171 &reader_process_identifier,
172 text,
173 )

Callers 1

native_inspector_connectFunction · 0.80

Calls 14

TextInterface · 0.85
handle_incoming_messageFunction · 0.85
fail_all_pendingFunction · 0.85
unregisterMethod · 0.80
queryMethod · 0.80
registerMethod · 0.80
with_infoMethod · 0.80
sendMethod · 0.65
cloneMethod · 0.65
abortMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected