Skip to content

Commit 5abe9cb

Browse files
Pi Songkunthamgrouma
authored andcommitted
Created a skeleton for the backend of Dart Debug Extension. (#488)
* Created a skeleton for the backend of Dart Debug Extension.
1 parent 940e662 commit 5abe9cb

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

dwds/lib/dwds.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1212

1313
import 'src/connections/app_connection.dart';
1414
import 'src/connections/debug_connection.dart';
15-
import 'src/devtools.dart';
1615
import 'src/handlers/asset_handler.dart';
1716
import 'src/handlers/dev_handler.dart';
1817
import 'src/handlers/injected_handler.dart';
18+
import 'src/servers/devtools.dart';
1919

2020
export 'src/connections/app_connection.dart' show AppConnection;
2121
export 'src/connections/debug_connection.dart' show DebugConnection;

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import '../../data/devtools_request.dart';
1818
import '../../data/isolate_events.dart';
1919
import '../../data/serializers.dart';
2020
import '../connections/app_connection.dart';
21-
import '../devtools.dart';
2221
import '../dwds_vm_client.dart';
2322
import '../handlers/asset_handler.dart';
23+
import '../servers/devtools.dart';
2424
import '../services/app_debug_services.dart';
2525
import '../services/debug_service.dart';
2626

File renamed without changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:http_multi_server/http_multi_server.dart';
8+
import 'package:shelf/shelf_io.dart';
9+
import 'package:sse/server/sse_handler.dart';
10+
11+
SseHandler _sseHandler = SseHandler(Uri.parse('/test'));
12+
13+
/// A backend for the Dart Debug Extension which sets up an SSE handler.
14+
///
15+
/// The SSE handler simply sends a simple message and prints the response when
16+
/// a client connects.
17+
class ExtensionBackend {
18+
final String hostname;
19+
final int port;
20+
final HttpServer _server;
21+
22+
ExtensionBackend._(this.hostname, this.port, this._server) {
23+
_listen();
24+
}
25+
26+
// Starts the backend on an open port.
27+
static Future<ExtensionBackend> start() async {
28+
var server = await HttpMultiServer.bind('localhost', 0);
29+
serveRequests(server, _sseHandler.handler);
30+
return ExtensionBackend._(server.address.host, server.port, server);
31+
}
32+
33+
Future<void> close() async {
34+
await _server.close();
35+
}
36+
37+
void _listen() async {
38+
var connections = _sseHandler.connections;
39+
while (await connections.hasNext) {
40+
var connection = await connections.next;
41+
connection.sink.add('foo');
42+
connection.stream.listen(print);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)