-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for announcements using the vm service, this means from n…
…ow on discovery can work on web as well
- Loading branch information
1 parent
137822e
commit 8be1c96
Showing
6 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,62 @@ | ||
import 'package:dart_service_announcement/src/server_base.dart'; | ||
|
||
import 'package:dart_service_announcement/src/server_empty.dart' | ||
if (dart.library.html) 'package:dart_service_announcement/src/web_server.dart' | ||
if (dart.library.io) 'package:dart_service_announcement/src/io_server.dart'; | ||
import 'package:dart_service_announcement/src/vm_service_server.dart'; | ||
|
||
///Create the announcement server for the tooling server | ||
///Create the announcement server(s) for the tooling server | ||
// ignore: non_constant_identifier_names | ||
BaseServerAnnouncementManager ServerAnnouncementManager( | ||
String packageName, | ||
int announcementPort, | ||
ToolingServer server, | ||
) => | ||
internalCreateServer(packageName, announcementPort, server); | ||
_CombiningServerAnnouncementManager([ | ||
internalCreateServer(packageName, announcementPort, server), | ||
internalCreateVMServiceServer(packageName, announcementPort, server), | ||
]); | ||
|
||
///A proxy ServerAnnouncementManager that combines multiple ServerAnnouncementManagers | ||
class _CombiningServerAnnouncementManager | ||
implements BaseServerAnnouncementManager { | ||
final List<BaseServerAnnouncementManager> _managers; | ||
|
||
_CombiningServerAnnouncementManager(this._managers); | ||
|
||
@override | ||
void addExtension(AnnouncementExtension extension) { | ||
for (final manager in _managers) { | ||
manager.addExtension(extension); | ||
} | ||
} | ||
|
||
@override | ||
int get announcementPort => _managers[0].announcementPort; | ||
|
||
@override | ||
String get packageName => _managers[0].packageName; | ||
|
||
@override | ||
void removeExtension(AnnouncementExtension extension) { | ||
for (final manager in _managers) { | ||
manager.removeExtension(extension); | ||
} | ||
} | ||
|
||
@override | ||
ToolingServer get server => _managers[0].server; | ||
|
||
@override | ||
Future<void> start() async { | ||
for (final manager in _managers) { | ||
await manager.start(); | ||
} | ||
} | ||
|
||
@override | ||
Future<void> stop() async { | ||
for (final manager in _managers) { | ||
await manager.stop(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'dart:convert'; | ||
import 'dart:developer'; | ||
|
||
import 'package:dart_service_announcement/src/server_base.dart'; | ||
|
||
BaseServerAnnouncementManager internalCreateVMServiceServer( | ||
String packageName, | ||
int announcementPort, | ||
ToolingServer server, | ||
) => | ||
_VMServiceServerAnnouncementManager(packageName, announcementPort, server); | ||
|
||
class _VMServiceServerAnnouncementManager | ||
extends BaseServerAnnouncementManager { | ||
final _extensions = <AnnouncementExtension>[]; | ||
var _started = false; | ||
|
||
_VMServiceServerAnnouncementManager( | ||
String packageName, | ||
int announcementPort, | ||
ToolingServer server, | ||
) : super(packageName, announcementPort, server) { | ||
registerExtension('ext.${server.name}.query', (method, params) async { | ||
if (!_started) { | ||
return ServiceExtensionResponse.error( | ||
-1, | ||
'Announcement server stopped', | ||
); | ||
} | ||
|
||
final responseData = <String, dynamic>{}; | ||
responseData['packageName'] = packageName; | ||
responseData['port'] = server.port; | ||
responseData['pid'] = -1; | ||
responseData['protocol'] = server.protocolVersion; | ||
responseData['extensions'] = _extensions.map((ext) { | ||
return { | ||
'name': ext.name, | ||
'data': base64.encoder.convert(ext.data()), | ||
}; | ||
}).toList(); | ||
return ServiceExtensionResponse.result(json.encode(responseData)); | ||
}); | ||
} | ||
|
||
@override | ||
void addExtension(AnnouncementExtension extension) { | ||
_extensions.add(extension); | ||
} | ||
|
||
@override | ||
void removeExtension(AnnouncementExtension extension) { | ||
_extensions.removeWhere((element) => element == extension); | ||
} | ||
|
||
@override | ||
Future<void> start() { | ||
_started = true; | ||
return Future.value(); | ||
} | ||
|
||
@override | ||
Future<void> stop() { | ||
_started = false; | ||
return Future.value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters