Skip to content

Commit

Permalink
Fix after connect
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Feb 24, 2024
1 parent debbe55 commit 9ab3519
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/client/ws_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ final class WebSocketClient implements IWebSocketClient {
}
try {
// Send first messages after connection is established:
await _options.afterConnect?.call(this);
await _options.afterConnect?.call(_client);
} on Object {
_client.disconnect(1006, 'AFTER_CONNECT_ERROR');
}
Expand Down
26 changes: 26 additions & 0 deletions test/client/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,32 @@ void main() {
});
});

group('First message after connect', () {
const url = 'wss://echo.plugfox.dev:443/connect';

late IWebSocketClient client;

setUpAll(() {
client = WebSocketClient(WebSocketOptions.common(
afterConnect: (c) => c.add('auth.abc.123'),
));
});

tearDownAll(() {
client.close();
});

test('Can send first message from options', () async {
await client.connect(url);
var received =
await client.stream.first.timeout(const Duration(seconds: 5));
expect(received, equals('auth.abc.123'));
client.add('message');
received = await client.stream.first.timeout(const Duration(seconds: 5));
expect(received, equals('message'));
});
});

group(
'Binary data as a Blob',
() {
Expand Down

0 comments on commit 9ab3519

Please sign in to comment.