TxIceServer.fromJson constructor

TxIceServer.fromJson(
  1. Map<String, dynamic> json
)

Creates a TxIceServer from a JSON map.

The map should contain:

  • urls or url: String or List
  • username: Optional String for authentication
  • credential: Optional String for authentication

Implementation

factory TxIceServer.fromJson(Map<String, dynamic> json) {
  final urlsValue = json['urls'] ?? json['url'];
  List<String> urls;

  if (urlsValue is String) {
    urls = [urlsValue];
  } else if (urlsValue is List) {
    urls = urlsValue.cast<String>();
  } else {
    GlobalLogger().w(
      'TxIceServer :: Invalid urls value type in ICE server config: ${urlsValue?.runtimeType}. Expected String or List<String>.',
    );
    urls = [];
  }

  return TxIceServer(
    urls: urls,
    username: json['username'] as String?,
    credential: json['credential'] as String?,
  );
}