11import * as http from 'http' ;
2- import { EventEmitter } from 'events' ;
3- import { Services } from '../../services/debugAdapterServices' ;
2+ import { EventEmitter } from 'events' ;
3+ import { Services } from '../../services/debugAdapterServices' ;
44import * as Net from 'net' ;
55import { INSDebugConnection } from './INSDebugConnection' ;
66
7+ import { ChromeConnection } from 'vscode-chrome-debug-core' ;
8+
79
810interface IMessageWithId {
911 id : number ;
@@ -17,7 +19,7 @@ class Callbacks {
1719
1820 public wrap ( callback : any ) : number {
1921 var callbackId = this . lastId ++ ;
20- this . callbacks [ callbackId ] = callback || function ( ) { } ;
22+ this . callbacks [ callbackId ] = callback || function ( ) { } ;
2123 return callbackId ;
2224 }
2325
@@ -60,15 +62,15 @@ class ResReqNetSocket extends EventEmitter {
6062 return new Promise < void > ( ( resolve , reject ) => {
6163
6264 that . conn = Net . createConnection ( port , url ) ,
63- that . conn . setEncoding ( 'utf8' ) ;
65+ that . conn . setEncoding ( 'utf8' ) ;
6466
6567 setTimeout ( ( ) => {
6668 reject ( 'Connection timed out' )
6769 } , timeout ) ;
6870
6971 that . conn . on ( 'error' , reject ) ;
7072
71- that . conn . on ( 'connect' , function ( ) {
73+ that . conn . on ( 'connect' , function ( ) {
7274 // Replace the promise-rejecting handler
7375 that . conn . removeListener ( 'error' , reject ) ;
7476
@@ -89,23 +91,22 @@ class ResReqNetSocket extends EventEmitter {
8991 that . emit ( 'error' , e ) ;
9092 } ) ;
9193
92- that . conn . on ( 'data' , function ( data ) {
94+ that . conn . on ( 'data' , function ( data ) {
9395 that . debugBuffer += data ;
94- that . parse ( function ( ) {
95- that . connected = true ;
96- that . emit ( 'connect' ) ;
97- resolve ( ) ;
96+ that . parse ( function ( ) {
97+ that . connected = true ;
98+ that . emit ( 'connect' ) ;
99+ resolve ( ) ;
98100 } ) ;
99101 } ) ;
100102
101103
102- that . conn . on ( 'end' , function ( ) {
104+ that . conn . on ( 'end' , function ( ) {
103105 that . close ( ) ;
104106 } ) ;
105107
106- that . conn . on ( 'close' , function ( ) {
107- if ( ! that . connected )
108- {
108+ that . conn . on ( 'close' , function ( ) {
109+ if ( ! that . connected ) {
109110 reject ( "Can't connect. Check the application is running on the device" ) ;
110111 that . emit ( 'close' , that . lastError || 'Debugged process exited.' ) ;
111112 return ;
@@ -184,7 +185,7 @@ class ResReqNetSocket extends EventEmitter {
184185 Services . logger ( ) . log ( 'To target: ' + data ) ;
185186 this . conn . write ( 'Content-Length: ' + data . length + '\r\n\r\n' + data ) ;
186187 this . hasNewDataMessage = true ;
187- if ( ! this . isMessageFlushLoopStarted ) {
188+ if ( ! this . isMessageFlushLoopStarted ) {
188189 this . isMessageFlushLoopStarted = true ;
189190 setInterval ( ( ) => {
190191 if ( this . hasNewDataMessage ) {
@@ -209,13 +210,17 @@ class ResReqNetSocket extends EventEmitter {
209210 }
210211
211212 if ( params ) {
212- Object . keys ( params ) . forEach ( function ( key ) {
213+ Object . keys ( params ) . forEach ( function ( key ) {
213214 msg [ key ] = params [ key ] ;
214215 } ) ;
215216 }
216217 this . send ( JSON . stringify ( msg ) ) ;
217218 }
218219
220+ public sendMessage ( message : any ) {
221+ this . send ( message ) ;
222+ }
223+
219224 public close ( ) {
220225 if ( this . conn ) {
221226 this . conn . end ( ) ;
@@ -235,7 +240,7 @@ export class AndroidConnection implements INSDebugConnection {
235240 let that = this ;
236241 this . _socket = new ResReqNetSocket ( ) ;
237242
238- this . _socket . on ( "afterCompile" , function ( params ) {
243+ this . _socket . on ( "afterCompile" , function ( params ) {
239244
240245 let scriptData = < WebKitProtocol . Debugger . Script > {
241246 scriptId : String ( params . body . script . id ) ,
@@ -248,15 +253,15 @@ export class AndroidConnection implements INSDebugConnection {
248253 } ) ;
249254
250255
251- this . _socket . on ( "break" , function ( params ) {
256+ this . _socket . on ( "break" , function ( params ) {
252257 that . handleBreakEvent ( params ) ;
253258 } ) ;
254259
255- this . _socket . on ( "exception" , function ( params ) {
260+ this . _socket . on ( "exception" , function ( params ) {
256261 that . handleBreakEvent ( params ) ;
257262 } ) ;
258263
259- this . _socket . on ( "messageAdded" , function ( params ) {
264+ this . _socket . on ( "messageAdded" , function ( params ) {
260265 that . _socket . emit ( "Console.messageAdded" , params . body ) ;
261266 } ) ;
262267 }
@@ -342,7 +347,7 @@ export class AndroidConnection implements INSDebugConnection {
342347 if ( name && name . length > 1 ) {
343348 desc = name [ 1 ] ;
344349 if ( desc === 'Array' || desc === 'Buffer' ) {
345- size = ref . properties . filter ( function ( p ) { return / ^ \d + $ / . test ( p . name ) ; } ) . length ;
350+ size = ref . properties . filter ( function ( p ) { return / ^ \d + $ / . test ( p . name ) ; } ) . length ;
346351 desc += '[' + size + ']' ;
347352 }
348353 } else if ( ref . className === 'Date' ) {
@@ -400,8 +405,8 @@ export class AndroidConnection implements INSDebugConnection {
400405 } )
401406 . then ( response => {
402407 var debuggerFrames = < Array < any > > response . frames || [ ] ;
403- let frames = debuggerFrames . map ( function ( frame ) {
404- var scopeChain = frame . scopes . map ( function ( scope ) {
408+ let frames = debuggerFrames . map ( function ( frame ) {
409+ var scopeChain = frame . scopes . map ( function ( scope ) {
405410 return {
406411 object : {
407412 type : 'object' ,
@@ -481,7 +486,7 @@ export class AndroidConnection implements INSDebugConnection {
481486
482487 return this . request ( "clearbreakpoint" , {
483488 breakpoint : breakpointId
484- } )
489+ } )
485490 . then ( response => {
486491 return < WebKitProtocol . Response > { } ;
487492 } ) ;
@@ -568,9 +573,9 @@ export class AndroidConnection implements INSDebugConnection {
568573 let that = this ;
569574 return this . request ( "evaluate" , requestParams ) . then ( response => {
570575 return < WebKitProtocol . Debugger . EvaluateOnCallFrameResponse > {
571- result : {
572- result : that . v8ResultToInspectorResult ( response ) ,
573- wasThrown : false
576+ result : {
577+ result : that . v8ResultToInspectorResult ( response ) ,
578+ wasThrown : false
574579 }
575580 }
576581 } ) ;
@@ -615,12 +620,10 @@ export class AndroidConnection implements INSDebugConnection {
615620 }
616621
617622 let source = undefined ;
618- if ( Array . isArray ( response ) )
619- {
623+ if ( Array . isArray ( response ) ) {
620624 source = response [ 0 ] . source ;
621625 }
622- else if ( response . result )
623- {
626+ else if ( response . result ) {
624627 source = response . result [ 0 ] . source ;
625628 }
626629 else if ( response . source ) {
@@ -653,7 +656,7 @@ export class AndroidConnection implements INSDebugConnection {
653656 if ( response . refs ) {
654657
655658 let refsLookup = { } ;
656- response . refs . forEach ( function ( r ) { refsLookup [ r . handle ] = r ; } ) ;
659+ response . refs . forEach ( function ( r ) { refsLookup [ r . handle ] = r ; } ) ;
657660
658661 //TODO: response.body may be undefined in that case set it to {} here
659662 response . body . refsLookup = refsLookup ;
@@ -748,7 +751,7 @@ export class AndroidConnection implements INSDebugConnection {
748751 props = obj . properties ;
749752
750753 if ( props ) {
751- props = props . map ( function ( p ) {
754+ props = props . map ( function ( p ) {
752755 var ref = response . refsLookup [ p . ref ] ;
753756 return {
754757 name : String ( p . name ) ,
@@ -776,13 +779,13 @@ export class AndroidConnection implements INSDebugConnection {
776779 throw new Error ( "Not implemented" ) ;
777780 }
778781
779- // private sendMessage(method: any, params?: any): Promise<WebKitProtocol.Response> {
780- // return this._socket.sendMessage({
781- // id: this._nextId++,
782- // method,
783- // params
784- // });
785- // }
782+ private sendMessage ( method : any , params ?: any ) : Promise < WebKitProtocol . Response > {
783+ return this . _socket . sendMessage ( {
784+ id : this . _nextId ++ ,
785+ method,
786+ params
787+ } ) ;
788+ }
786789}
787790
788791/**
0 commit comments