ShspSocketInfoSingleton constructor

ShspSocketInfoSingleton()

Factory constructor that returns or creates the singleton instance

Parameters:

  • configPath: Optional path to config JSON file
  • defaultAddress: Default address if no config file (default: '127.0.0.1')
  • defaultPort: Default port if no config file (default: 6969)

If a config file path is provided and exists, loads from file. Otherwise, uses default values.

Implementation

factory ShspSocketInfoSingleton() {
  if (_instance != null) return _instance!;

  // Try to load from config file
  const String configPath = 'shsp_socket_config.json';
  const String defaultAddress = '127.0.0.1';
  const int defaultPort = 6969;

  final config = _loadConfig(configPath);

  // Use config values if available, otherwise use defaults
  final address = config?['address'] as String? ?? defaultAddress;
  final port = config?['port'] as int? ?? defaultPort;

  _instance = ShspSocketInfoSingleton._(address, port);
  return _instance!;
}