()
| 135 | } |
| 136 | |
| 137 | const connectToDebuggerProxy = async () => { |
| 138 | const ws = new WebSocket(`ws://${host}:${port}/debugger-proxy?role=debugger&name=Chrome`) |
| 139 | |
| 140 | const { setDebuggerStatus } = actions |
| 141 | ws.onopen = () => setDebuggerStatus('waiting') |
| 142 | ws.onmessage = async (message) => { |
| 143 | if (!message.data) return |
| 144 | |
| 145 | const object = JSON.parse(message.data) |
| 146 | if (object.$event === 'client-disconnected') { |
| 147 | shutdownJSRuntime() |
| 148 | return |
| 149 | } |
| 150 | if (!object.method) return |
| 151 | |
| 152 | // Special message that asks for a new JS runtime |
| 153 | if (object.method === 'prepareJSRuntime') { |
| 154 | shutdownJSRuntime() |
| 155 | createJSRuntime() |
| 156 | clearLogs() |
| 157 | selectRNDebuggerWorkerContext(currentWindow) |
| 158 | ws.send(JSON.stringify({ replyID: object.id })) |
| 159 | } else if (object.method === '$disconnected') { |
| 160 | shutdownJSRuntime() |
| 161 | } else { |
| 162 | if (!worker) return |
| 163 | if (object.method === 'executeApplicationScript') { |
| 164 | object.networkInspect = networkInspect.isEnabled() |
| 165 | object.reactDevToolsPort = window.reactDevToolsPort |
| 166 | if (isScriptBuildForAndroid(object.url)) { |
| 167 | // Reserve React Inspector port for debug via USB on Android real device |
| 168 | tryADBReverse(window.reactDevToolsPort).catch(() => {}) |
| 169 | } |
| 170 | // Clear logs even if no error catched |
| 171 | clearLogs() |
| 172 | scriptExecuted = true |
| 173 | checkJSLoadCount() |
| 174 | } |
| 175 | if (scriptExecuted) { |
| 176 | // Otherwise, pass through to the worker provided the |
| 177 | // application script has been executed. If not add |
| 178 | // it to a queue until it has been executed. |
| 179 | worker.postMessage(object) |
| 180 | flushQueuedMessages() |
| 181 | } else { |
| 182 | queuedMessages.push(object) |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | ws.onerror = () => {} |
| 188 | ws.onclose = (e) => { |
| 189 | shutdownJSRuntime() |
| 190 | if (e.reason) { |
| 191 | console.warn(e.reason) |
| 192 | } |
| 193 | preconnect(connectToDebuggerProxy, true) |
| 194 | } |
nothing calls this directly
no test coverage detected