serverWebSocketUri 属性

  1. @Since('2.14')
Uri? serverWebSocketUri

通过 WebSocket 连接到服务的 Uri。如果 Web 服务器未运行,此属性将为 null。

实现

@Since('2.14')
Uri? get serverWebSocketUri {
  Uri? uri = serverUri;
  if (uri != null) {
    final pathSegments = <String>[];
    if (uri.pathSegments.isNotEmpty) {
      pathSegments.addAll(uri.pathSegments.where(
        // Strip out the empty string that appears at the end of path segments.
        // Empty string elements will result in an extra '/' being added to the
        // URI.
        (s) => s.isNotEmpty,
      ));
    }
    pathSegments.add('ws');
    uri = uri.replace(scheme: 'ws', pathSegments: pathSegments);
  }
  return uri;
}