@@ -118,11 +118,13 @@ define(function(require, exports, module)
118118
119119 this . API = options . API ;
120120 this . options = options ;
121+ this . debug = this . options . debug || false ;
122+ this . verbose = this . options . verbose || false ;
121123 this . listeners = { } ;
122124 this . sessions = { } ;
123125 this . connected = false ;
124-
125126 // NOTE: The client ID is unique to the environment only, not globally!
127+ // A custom ID may be set via `connect()`.
126128 this . id = "client-" + ( ++ clientCounter ) ;
127129 } ;
128130
@@ -148,13 +150,18 @@ define(function(require, exports, module)
148150 }
149151 }
150152
151- Client . prototype . connect = function ( )
153+ Client . prototype . connect = function ( options )
152154 {
155+ options = options || { } ;
156+
153157 var self = this ;
154158
155159 if ( this . connected )
156160 throw new Error ( "Client already connected!" ) ;
157161
162+ if ( options . id )
163+ self . id = options . id ;
164+
158165 if ( typeof this . options . xdebugPort !== "undefined" )
159166 {
160167 this . engineServer = null ;
@@ -183,11 +190,17 @@ define(function(require, exports, module)
183190 self . sessions [ session . id ] = session ;
184191
185192 self . emit ( "session" , session ) ;
193+
194+ if ( self . verbose )
195+ console . log ( "Got `ready` for session '" + session . name + "' and client '" + self . id + "'." ) ;
186196 } ) ;
187197
188198 session . on ( "end" , function ( )
189199 {
190200 delete self . sessions [ session . id ] ;
201+
202+ if ( self . verbose )
203+ console . log ( "Got `end` for session '" + session . name + "' and client '" + self . id + "'." ) ;
191204 } ) ;
192205
193206 session . listen ( socket ) ;
@@ -214,7 +227,9 @@ define(function(require, exports, module)
214227
215228 clients [ self . id ] = true ;
216229
217- self . proxySocket . emit ( "connect-client" , { } , function ( )
230+ self . proxySocket . emit ( "connect-client" , {
231+ id : self . id
232+ } , function ( )
218233 {
219234 self . connected = true ;
220235
@@ -319,12 +334,15 @@ define(function(require, exports, module)
319334 options = options || { } ;
320335 this . API = options . API ;
321336 this . options = options ;
337+ this . debug = this . options . debug || false ;
338+ this . verbose = this . options . verbose || false ;
322339 this . listeners = { } ;
323340 this . status = "init" ; // init, ready, aborted, ended
324341 this . socketIO = null ;
325342 this . socket = null ;
326343 this . commandCounter = 0 ;
327344 this . commandCallbacks = { } ;
345+ this . lockedClientId = false ;
328346
329347 this . on ( "ready" , function ( )
330348 {
@@ -363,6 +381,14 @@ define(function(require, exports, module)
363381 }
364382 }
365383
384+ Session . prototype . lockToClient = function ( clientId )
385+ {
386+ this . lockedClientId = clientId ;
387+
388+ if ( this . verbose )
389+ console . log ( "Locked session '" + this . name + "' to client '" + this . lockedClientId + "'." ) ;
390+ }
391+
366392 Session . prototype . listen = function ( socket )
367393 {
368394 var self = this ;
@@ -384,7 +410,10 @@ define(function(require, exports, module)
384410
385411 parser . on ( "packet" , function ( packet )
386412 {
387- if ( self . status === "ready" )
413+ if ( self . debug )
414+ console . log ( "Got packet" , packet ) ;
415+
416+ if ( self . status === "ready" )
388417 {
389418 // 6.5 debugger engine errors
390419 // @see http://www.xdebug.org/docs-dbgp.php#id32
@@ -433,7 +462,8 @@ define(function(require, exports, module)
433462 }
434463 else
435464 {
436- console . log ( packet ) ;
465+ console . log ( "ERROR: Got unknown packet type from xdebug!" , packet ) ;
466+ throw new Error ( "Got unknown packet type from xdebug!" ) ;
437467 }
438468
439469 if ( typeof packet [ "@" ] . status !== "undefined" )
@@ -465,8 +495,8 @@ console.log(packet);
465495 }
466496 else
467497 {
468-
469- console . log ( ' status' , packet ) ;
498+ console . log ( "ERROR: Got unknown status from xdebug!" , packet ) ;
499+ throw new Error ( "Got unknown status from xdebug!" ) ;
470500 }
471501 }
472502 }
@@ -540,6 +570,8 @@ console.log('status', packet);
540570 self . id += "-" + packet [ "@" ] . thread ;
541571 if ( packet [ "@" ] . idekey )
542572 self . id += "-" + packet [ "@" ] . idekey ;
573+
574+ self . name = packet [ "@" ] . session ;
543575
544576 self . emit ( "init" , { raw : packet } ) ;
545577
0 commit comments