Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEA-2879: Include SockJS debug URL #415

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [5.2.0](https://github.com/Workiva/w_transport/compare/5.1.0...5.2.0)

- Added `debugUrl` to `WebSocketConnectEvent` which is emitted via the
`GlobalWebSocketMonitor`. When using SockJS, this will be populated with the
full URL that the underlying transport is using, which can be useful information
for debugging.

## [5.1.0](https://github.com/Workiva/w_transport/compare/5.0.1...5.1.0)

- Added `defaultTimeoutThreshold` top level field to add a timeout for all requests by default.
Expand Down
6 changes: 6 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ homepage: https://github.com/Workiva/w_transport
environment:
sdk: ">=2.11.0 <3.0.0"

dependency_overrides:
sockjs_client_wrapper:
git:
url: git@github.com:Workiva/sockjs_client_wrapper.git
ref: expose-debug-transport-url

dev_dependencies:
_test_server:
path: ../_test_server
Expand Down
17 changes: 10 additions & 7 deletions lib/src/web_socket/browser/sockjs_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ class SockJSWrapperWebSocket extends CommonWebSocket implements WebSocket {
client.onOpen.listen((event) {
connected.complete();
emitWebSocketConnectEvent(newWebSocketConnectEvent(
url: uri.toString(),
wasSuccessful: true,
sockJsProtocolsWhitelist: protocolsWhitelist,
sockJsSelectedProtocol: event.transport));
url: uri.toString(),
wasSuccessful: true,
debugUrl: event.debugUrl.toString(),
sockJsProtocolsWhitelist: protocolsWhitelist,
sockJsSelectedProtocol: event.transport,
));
});
// ignore: unawaited_futures
closed.future.then((_) {
if (!connected.isCompleted) {
connected
.completeError(WebSocketException('Could not connect to $uri'));
emitWebSocketConnectEvent(newWebSocketConnectEvent(
url: uri.toString(),
wasSuccessful: false,
sockJsProtocolsWhitelist: protocolsWhitelist));
url: uri.toString(),
wasSuccessful: false,
sockJsProtocolsWhitelist: protocolsWhitelist,
));
}
});

Expand Down
35 changes: 21 additions & 14 deletions lib/src/web_socket/global_web_socket_monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ void emitWebSocketConnectEvent(WebSocketConnectEvent connectEvent) {
GlobalWebSocketMonitor newGlobalWebSocketMonitor() =>
GlobalWebSocketMonitor._();

WebSocketConnectEvent newWebSocketConnectEvent(
{required String url,
required bool wasSuccessful,
String? sockJsSelectedProtocol,
List<String>? sockJsProtocolsWhitelist}) =>
WebSocketConnectEvent newWebSocketConnectEvent({
required String url,
required bool wasSuccessful,
String? debugUrl,
String? sockJsSelectedProtocol,
List<String>? sockJsProtocolsWhitelist,
}) =>
WebSocketConnectEvent._(
url: url,
wasSuccessful: wasSuccessful,
sockJsProtocolsWhitelist: sockJsProtocolsWhitelist,
sockJsSelectedProtocol: sockJsSelectedProtocol);
url: url,
wasSuccessful: wasSuccessful,
debugUrl: debugUrl,
sockJsProtocolsWhitelist: sockJsProtocolsWhitelist,
sockJsSelectedProtocol: sockJsSelectedProtocol,
);

class GlobalWebSocketMonitor {
StreamController<WebSocketConnectEvent> _didAttemptToConnect =
Expand All @@ -54,14 +58,17 @@ class GlobalWebSocketMonitor {
}

class WebSocketConnectEvent {
final String? debugUrl;
final List<String>? sockJsProtocolsWhitelist;
final String? sockJsSelectedProtocol;
final String url;
final bool wasSuccessful;

WebSocketConnectEvent._(
{required this.url,
required this.wasSuccessful,
this.sockJsProtocolsWhitelist,
this.sockJsSelectedProtocol});
WebSocketConnectEvent._({
required this.url,
required this.wasSuccessful,
this.debugUrl,
this.sockJsProtocolsWhitelist,
this.sockJsSelectedProtocol,
});
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
meta: ^1.6.0
mime: '>=0.9.6+3 <2.0.0'
quiver: '>=2.1.5 <4.0.0'
sockjs_client_wrapper: ^1.0.14
sockjs_client_wrapper: ^1.3.0
collection: ^1.15.0

dev_dependencies:
Expand Down
5 changes: 3 additions & 2 deletions test/integration/global_web_socket_monitor/sockjs_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import 'common.dart';

const _sockjsPort = 8026;

void runCommonSockJSSuite(List<String> protocolsToTest,
{bool usingSockjsPort = true}) {
void runCommonSockJSSuite(List<String> protocolsToTest) {
final naming = Naming()
..platform = platformBrowserSockjsWrapper
..testType = testTypeIntegration
Expand Down Expand Up @@ -62,11 +61,13 @@ void runCommonSockJSSuite(List<String> protocolsToTest,

expect(events[0].url, equals(echoUri.toString()));
expect(events[0].wasSuccessful, isTrue);
expect(events[0].debugUrl, isNotEmpty);
expect(events[0].sockJsProtocolsWhitelist, equals([protocol]));
expect(events[0].sockJsSelectedProtocol, equals(protocol));

expect(events[1].url, equals(fourOhFourUri.toString()));
expect(events[1].wasSuccessful, isFalse);
expect(events[1].debugUrl, isNull);
expect(events[1].sockJsProtocolsWhitelist, equals([protocol]));
expect(events[1].sockJsSelectedProtocol, isNull);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ const _protocolsToTest = [
];

void main() {
runCommonSockJSSuite(_protocolsToTest, usingSockjsPort: false);
runCommonSockJSSuite(_protocolsToTest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
}
</script>
<script src="packages/sockjs_client_wrapper/sockjs_prod.js"></script>
<script src="packages/sockjs_client_wrapper/sockjs.js"></script>
<link rel="x-dart-test" href="sockjs_wrapper_test.dart">
<script src="packages/test/dart.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/integration/ws/sockjs_wrapper_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
}
</script>
<script src="packages/sockjs_client_wrapper/sockjs_prod.js"></script>
<script src="packages/sockjs_client_wrapper/sockjs.js"></script>
<link rel="x-dart-test" href="sockjs_wrapper_test.dart">
<script src="packages/test/dart.js"></script>
</head>
Expand Down
Loading