@@ -141,6 +141,7 @@ class DevHandler {
141
141
/// Sends the provided [request] to all connected injected clients.
142
142
/// Returns the number of clients the request was successfully sent to.
143
143
int _sendRequestToClients (Object request) {
144
+ _logger.finest ('Sending request to injected clients: $request ' );
144
145
var successfulSends = 0 ;
145
146
for (final injectedConnection in _injectedConnections) {
146
147
try {
@@ -358,12 +359,9 @@ class DevHandler {
358
359
}
359
360
if (message is DevToolsRequest ) {
360
361
await _handleDebugRequest (connection, injectedConnection);
361
- } else if (useWebSocketConnection) {
362
- // Handle WebSocket-specific messages
363
- await _handleWebSocketMessage (connection, message);
364
362
} else {
365
- // Handle Chrome-specific messages
366
- await _handleChromeMessage (connection, message);
363
+ // Handle messages for both WebSocket and Chrome proxy services
364
+ await _handleMessage (connection, message);
367
365
}
368
366
}
369
367
} catch (e, s) {
@@ -413,66 +411,40 @@ class DevHandler {
413
411
);
414
412
}
415
413
416
- /// Handles WebSocket-specific messages.
417
- Future <void > _handleWebSocketMessage (
418
- AppConnection connection,
419
- Object ? message,
420
- ) async {
414
+ /// Handles messages for both WebSocket and Chrome proxy services.
415
+ Future <void > _handleMessage (AppConnection connection, Object ? message) async {
421
416
if (message == null ) return ;
422
417
423
418
final appId = connection.request.appId;
424
419
final proxyService = _servicesByAppId[appId]? .proxyService;
425
- final wsService =
426
- proxyService is WebSocketProxyService ? proxyService : null ;
427
420
428
- if (wsService == null ) {
421
+ if (proxyService == null ) {
429
422
_logger.warning (
430
- 'No WebSocketProxyService found for appId: $appId to process $message ' ,
423
+ 'No proxy service found for appId: $appId to process $message ' ,
431
424
);
432
425
return ;
433
426
}
427
+
428
+ // Handle messages that are specific to certain proxy service types
434
429
if (message is HotReloadResponse ) {
435
- wsService .completeHotReload (message);
430
+ proxyService .completeHotReload (message);
436
431
} else if (message is ServiceExtensionResponse ) {
437
- wsService.completeServiceExtension (message);
438
- } else if (message is RegisterEvent ) {
439
- wsService.parseRegisterEvent (message);
440
- } else if (message is BatchedDebugEvents ) {
441
- wsService.parseBatchedDebugEvents (message);
442
- } else if (message is DebugEvent ) {
443
- wsService.parseDebugEvent (message);
444
- } else {
445
- throw UnsupportedError (
446
- 'Message type ${message .runtimeType } is not supported in WebSocket mode' ,
447
- );
448
- }
449
- }
450
-
451
- /// Handles Chrome-specific messages.
452
- Future <void > _handleChromeMessage (
453
- AppConnection connection,
454
- Object ? message,
455
- ) async {
456
- if (message == null ) return ;
457
-
458
- final appId = connection.request.appId;
459
- final proxyService = _servicesByAppId[appId]? .proxyService;
460
- final chromeService =
461
- proxyService is ChromeProxyService ? proxyService : null ;
462
-
463
- if (message is IsolateExit ) {
432
+ proxyService.completeServiceExtension (message);
433
+ } else if (message is IsolateExit ) {
464
434
_handleIsolateExit (connection);
465
435
} else if (message is IsolateStart ) {
466
436
await _handleIsolateStart (connection);
467
437
} else if (message is BatchedDebugEvents ) {
468
- chromeService ? .parseBatchedDebugEvents (message);
438
+ proxyService .parseBatchedDebugEvents (message);
469
439
} else if (message is DebugEvent ) {
470
- chromeService ? .parseDebugEvent (message);
440
+ proxyService .parseDebugEvent (message);
471
441
} else if (message is RegisterEvent ) {
472
- chromeService ? .parseRegisterEvent (message);
442
+ proxyService .parseRegisterEvent (message);
473
443
} else {
444
+ final serviceType =
445
+ proxyService is WebSocketProxyService ? 'WebSocket' : 'Chrome' ;
474
446
throw UnsupportedError (
475
- 'Message type ${message .runtimeType } is not supported in Chrome mode' ,
447
+ 'Message type ${message .runtimeType } is not supported in $ serviceType mode' ,
476
448
);
477
449
}
478
450
}
@@ -649,12 +621,12 @@ class DevHandler {
649
621
// AppConnection is in the KeepAlive state (this means it disconnected but
650
622
// is still waiting for a possible reconnect - this happens during a page
651
623
// reload).
652
- final canReuseConnection =
624
+ final canReconnect =
653
625
services != null &&
654
626
(services.connectedInstanceId == null ||
655
627
existingConnection? .isInKeepAlivePeriod == true );
656
628
657
- if (canReuseConnection ) {
629
+ if (canReconnect ) {
658
630
// Disconnect any old connection (eg. those in the keep-alive waiting
659
631
// state when reloading the page).
660
632
existingConnection? .shutDown ();
@@ -719,13 +691,13 @@ class DevHandler {
719
691
final hasNoActiveConnection = services? .connectedInstanceId == null ;
720
692
final noExistingConnection = existingConnection == null ;
721
693
722
- final canReuseConnection =
694
+ final canReconnect =
723
695
services != null &&
724
696
(isSameInstance ||
725
697
(isKeepAliveReconnect && hasNoActiveConnection) ||
726
698
(noExistingConnection && hasNoActiveConnection));
727
699
728
- if (canReuseConnection ) {
700
+ if (canReconnect ) {
729
701
// Reconnect to existing service.
730
702
await _reconnectToService (
731
703
services,
@@ -739,15 +711,13 @@ class DevHandler {
739
711
readyToRunMainCompleter.complete ();
740
712
741
713
// For WebSocket mode, we need to proactively create and emit a debug connection
742
- // since Flutter tools won't call debugConnection() for WebServerDevice
743
714
try {
744
715
// Initialize the WebSocket service and create debug connection
745
716
final debugConnection = await createDebugConnectionForWebSocket (
746
717
connection,
747
718
);
748
719
749
720
// Emit the debug connection through the extension stream
750
- // This should trigger Flutter tools to pick it up as if it was an extension connection
751
721
extensionDebugConnections.add (debugConnection);
752
722
} catch (e, s) {
753
723
_logger.warning ('Failed to create WebSocket debug connection: $e \n $s ' );
0 commit comments