Skip to content

Commit dee6e47

Browse files
committed
Close previous connection when opening a new inspector
1 parent 9fa2e1f commit dee6e47

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test-app/app/src/main/java/com/tns/AndroidJsV8Inspector.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,22 @@ protected Response serveHttp(IHTTPSession session) {
231231
return super.serveHttp(session);
232232
}
233233

234+
private JsV8InspectorWebSocket webSocket;
235+
234236
@Override
235237
protected WebSocket openWebSocket(IHTTPSession handshake) {
236-
return new JsV8InspectorWebSocket(handshake, currentRuntimeLogger);
238+
// close the previous webSocket
239+
if(this.webSocket != null) {
240+
try {
241+
this.webSocket.close(WebSocketFrame.CloseCode.NormalClosure, "New browser connection is open", false);
242+
} catch (IOException ioException) {
243+
if(this.webSocket.getState() != State.CLOSED) {
244+
Log.e("{N}.v8-inspector", "Error closing previous connection", ioException);
245+
}
246+
}
247+
}
248+
this.webSocket = new JsV8InspectorWebSocket(handshake);
249+
return this.webSocket;
237250
}
238251
}
239252

0 commit comments

Comments
 (0)