14
14
15
15
public class AndroidJsV8Inspector
16
16
{
17
+ private static boolean DEBUG_LOG_ENABLED = false ;
18
+
17
19
public static final String DISCONNECT_MESSAGE = "nativescript-inspector-disconnect" ;
18
20
private JsV8InspectorServer server ;
19
21
private Logger logger ;
@@ -46,7 +48,10 @@ public void start() throws IOException
46
48
this .server = new JsV8InspectorServer (context .getPackageName () + "-inspectorServer" );
47
49
this .server .start (-1 );
48
50
49
- //Log.d("V8Inspector", "init ThreadId:" + Thread.currentThread().getId());
51
+ if (DEBUG_LOG_ENABLED )
52
+ {
53
+ Log .d ("V8Inspector" , "start debugger ThreadId:" + Thread .currentThread ().getId ());
54
+ }
50
55
51
56
init ();
52
57
}
@@ -72,7 +77,10 @@ public JsV8InspectorServer(String name)
72
77
@ Override
73
78
protected Response serveHttp (IHTTPSession session )
74
79
{
75
- //Log.d("{N}.v8-inspector", "http request for " + session.getUri());
80
+ if (DEBUG_LOG_ENABLED )
81
+ {
82
+ Log .d ("{N}.v8-inspector" , "http request for " + session .getUri ());
83
+ }
76
84
return super .serveHttp (session );
77
85
}
78
86
@@ -94,7 +102,10 @@ public JsV8InspectorWebSocket(NanoHTTPD.IHTTPSession handshakeRequest)
94
102
@ Override
95
103
protected void onOpen ()
96
104
{
97
- //Log.d("V8Inspector", "onOpen: ThreadID: " + Thread.currentThread().getId());
105
+ if (DEBUG_LOG_ENABLED )
106
+ {
107
+ Log .d ("V8Inspector" , "onOpen: ThreadID: " + Thread .currentThread ().getId ());
108
+ }
98
109
99
110
final Object waitObject = new Object ();
100
111
@@ -103,38 +114,24 @@ protected void onOpen()
103
114
@ Override
104
115
public void run ()
105
116
{
106
- try
107
- {
108
- //Log.d("V8Inspector", "onOpen: runnable ThreadID : " + Thread.currentThread().getId());
109
- connect (JsV8InspectorWebSocket .this );
110
- }
111
- finally
117
+ if (DEBUG_LOG_ENABLED )
112
118
{
113
- synchronized (waitObject )
114
- {
115
- waitObject .notify ();
116
- }
119
+ Log .d ("V8Inspector" , "onOpen: runnable ThreadID : " + Thread .currentThread ().getId ());
117
120
}
118
- }
119
- });
120
121
121
- try
122
- {
123
- synchronized (waitObject )
124
- {
125
- waitObject .wait ();
122
+ connect (JsV8InspectorWebSocket .this );
126
123
}
127
- }
128
- catch (InterruptedException e )
129
- {
130
- e .printStackTrace ();
131
- }
124
+ });
132
125
}
133
126
134
127
@ Override
135
128
protected void onClose (NanoWSD .WebSocketFrame .CloseCode code , String reason , boolean initiatedByRemote )
136
129
{
137
- //Log.d("V8Inspector", "onClose");
130
+ if (DEBUG_LOG_ENABLED )
131
+ {
132
+ Log .d ("V8Inspector" , "onClose" );
133
+ }
134
+
138
135
mainHandler .post (new Runnable ()
139
136
{
140
137
@ Override
@@ -150,8 +147,10 @@ public void run()
150
147
@ Override
151
148
protected void onMessage (final NanoWSD .WebSocketFrame message )
152
149
{
153
- //Log.d("V8Inspector", "onMessage");
154
- //Log.d("V8Inspector", "onMessage TextPayload" + message.getTextPayload() + " ThreadId:" + Thread.currentThread().getId());
150
+ if (DEBUG_LOG_ENABLED )
151
+ {
152
+ Log .d ("V8Inspector" , "To dbg backend: " + message .getTextPayload () + " ThreadId:" + Thread .currentThread ().getId ());
153
+ }
155
154
inspectorMessages .offer (message .getTextPayload ());
156
155
157
156
mainHandler .post (new Runnable ()
@@ -172,7 +171,11 @@ public void run()
172
171
@ Override
173
172
public void send (String payload ) throws IOException
174
173
{
175
- //Log.d("V8Inspector", "send " + payload);
174
+ if (DEBUG_LOG_ENABLED )
175
+ {
176
+ Log .d ("V8Inspector" , "To dbg client: " + payload );
177
+ }
178
+
176
179
super .send (payload );
177
180
}
178
181
@@ -184,6 +187,10 @@ public String getInspectorMessage()
184
187
185
188
if (message != null && message .equalsIgnoreCase (DISCONNECT_MESSAGE ))
186
189
{
190
+ if (DEBUG_LOG_ENABLED )
191
+ {
192
+ Log .d ("V8Inspector" , "disconecting" );
193
+ }
187
194
disconnect ();
188
195
return null ;
189
196
}
@@ -198,11 +205,9 @@ public String getInspectorMessage()
198
205
return null ;
199
206
}
200
207
201
-
202
208
@ Override
203
209
protected void onPong (NanoWSD .WebSocketFrame pong )
204
210
{
205
- //Log.d("V8Inspector", "onPong");
206
211
}
207
212
208
213
@ Override
0 commit comments