start method
Implementation
Future<String> start({Duration timeout = const Duration(minutes: 5)}) async {
await close();
_result = Completer<ChatGptOAuthCallback?>();
Object? lastError;
for (final port in const [1455, 1457]) {
try {
_server = await HttpServer.bind(InternetAddress.loopbackIPv4, port);
break;
} on Object catch (error) {
lastError = error;
}
}
if (_server == null) {
throw StateError(
'Could not bind ChatGPT OAuth callback port: $lastError',
);
}
_timer = Timer(timeout, () => _complete(null));
_server!.listen(_handle, onDone: () => _complete(null));
return callbackUrl!;
}