serverIsolateEntryPoint function
void
serverIsolateEntryPoint(
- SendPort isolateToMainStream
)
Implementation
void serverIsolateEntryPoint(SendPort isolateToMainStream) {
ReceivePort mainToIsolateStream = ReceivePort();
isolateToMainStream.send(mainToIsolateStream.sendPort);
IsolateInspector? inspector;
mainToIsolateStream.listen((data) {
handleFrontEndMessage(Map<String, dynamic>? frontEndMessage) {
int? id = frontEndMessage!['id'];
String _method = frontEndMessage['method'];
Map<String, dynamic>? params = frontEndMessage['params'];
List<String> moduleMethod = _method.split('.');
String module = moduleMethod[0];
String method = moduleMethod[1];
// Runtime、Log、Debugger methods should handled on inspector isolate.
if (module == 'Runtime' || module == 'Log' || module == 'Debugger') {
inspector!.messageRouter(id, module, method, params);
} else {
isolateToMainStream.send(InspectorFrontEndMessage(id, module, method, params));
}
}
if (data is InspectorServerInit) {
IsolateInspectorServer server = IsolateInspectorServer(data.port, data.address, data.bundleURL);
server.onStarted = () {
isolateToMainStream.send(InspectorServerStart());
};
server.onFrontendMessage = handleFrontEndMessage;
server.start();
inspector = server;
} else if (data is InspectorServerConnect) {
IsolateInspectorClient client = IsolateInspectorClient(data.url);
client.onStarted = () {
isolateToMainStream.send(InspectorClientConnected());
};
client.onFrontendMessage = handleFrontEndMessage;
client.start();
inspector = client;
} else if (inspector != null && inspector!.connected) {
if (data is InspectorEvent) {
inspector!.sendEventToFrontend(data);
} else if (data is InspectorMethodResult) {
inspector!.sendToFrontend(data.id, data.result);
}
}
});
}