Skip to content

Commit

Permalink
Make client params optional and export session, client
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed Apr 30, 2024
1 parent 623d5c0 commit 071fe81
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lib/exports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export "src/client.dart" show Client;
export "src/session.dart" show Session;
export "src/types.dart" show Registration, Subscription;
11 changes: 7 additions & 4 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import "package:wampproto/auth.dart";
import "package:wampproto/serializers.dart";

class Client {
Client(this._authenticator, this._serializer);
Client({IClientAuthenticator? authenticator, Serializer? serializer}) {
_authenticator = authenticator;
_serializer = serializer;
}

final IClientAuthenticator _authenticator;
final Serializer _serializer;
IClientAuthenticator? _authenticator;
Serializer? _serializer;

Future<Session> connect(String url, String realm) async {
WAMPSessionJoiner joiner = WAMPSessionJoiner(_authenticator, serializer: _serializer);
WAMPSessionJoiner joiner = WAMPSessionJoiner(authenticator: _authenticator, serializer: _serializer);
BaseSession baseSession = await joiner.join(url, realm);

return Session(baseSession);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "package:wamp/wamp_session.dart";
import "package:wamp/src/wsjoiner.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

Expand Down
9 changes: 6 additions & 3 deletions lib/src/wsjoiner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import "package:wampproto/joiner.dart";
import "package:wampproto/serializers.dart";

class WAMPSessionJoiner {
WAMPSessionJoiner(this._authenticator, {Serializer? serializer}) : _serializer = serializer ?? JSONSerializer();
WAMPSessionJoiner({IClientAuthenticator? authenticator, Serializer? serializer}) {
_serializer = serializer ?? JSONSerializer();
_authenticator = authenticator;
}

static const String jsonSubProtocol = "wamp.2.json";
static const String cborSubProtocol = "wamp.2.cbor";
static const String msgpackSubProtocol = "wamp.2.msgpack";

final IClientAuthenticator _authenticator;
final Serializer _serializer;
IClientAuthenticator? _authenticator;
late Serializer _serializer;

Future<BaseSession> join(String uri, String realm) async {
// ignore: close_sinks
Expand Down
1 change: 0 additions & 1 deletion lib/wamp_session.dart

This file was deleted.

0 comments on commit 071fe81

Please sign in to comment.