Skip to content

Commit

Permalink
Merge pull request #95 from muzzammilshahid/hello-fields
Browse files Browse the repository at this point in the history
Make Hello fields use interface
  • Loading branch information
muzzammilshahid authored May 26, 2024
2 parents 642fcad + 5441107 commit c6a2e94
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export "src/messages/challenge.dart" show Challenge;
export "src/messages/error.dart" show Error;
export "src/messages/event.dart" show Event;
export "src/messages/goodbye.dart" show Goodbye;
export "src/messages/hello.dart" show Hello;
export "src/messages/hello.dart" show Hello, IHelloFields;
export "src/messages/interrupt.dart" show Interrupt;
export "src/messages/invocation.dart" show Invocation;
export "src/messages/message.dart" show Message;
Expand Down
13 changes: 8 additions & 5 deletions lib/src/joiner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "package:wampproto/auth.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";
import "package:wampproto/src/exception.dart";
import "package:wampproto/src/messages/hello.dart";
import "package:wampproto/src/types.dart";

final clientRoles = <String, Map<String, Map>>{
Expand Down Expand Up @@ -29,11 +30,13 @@ class Joiner {

Object sendHello() {
final hello = Hello(
_realm,
clientRoles,
_authenticator.authID,
[_authenticator.authMethod],
authExtra: _authenticator.authExtra,
HelloFields(
_realm,
clientRoles,
_authenticator.authID,
[_authenticator.authMethod],
authExtra: _authenticator.authExtra,
),
);

_state = stateHelloSent;
Expand Down
58 changes: 50 additions & 8 deletions lib/src/messages/hello.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,45 @@ import "package:wampproto/src/messages/message.dart";
import "package:wampproto/src/messages/util.dart";
import "package:wampproto/src/messages/validation_spec.dart";

abstract class IHelloFields {
String get realm;

Map<String, dynamic> get roles;

String get authID;

List<dynamic> get authMethods;

Map<String, dynamic> get authExtra;
}

class HelloFields implements IHelloFields {
HelloFields(this._realm, this._roles, this._authid, this._authmethods, {Map<String, dynamic>? authExtra})
: _authextra = authExtra ?? {};
final String _realm;
final Map<String, dynamic> _roles;
final String _authid;
final List<dynamic> _authmethods;
final Map<String, dynamic> _authextra;

@override
String get realm => _realm;

@override
Map<String, dynamic> get roles => _roles;

@override
String get authID => _authid;

@override
List<dynamic> get authMethods => _authmethods;

@override
Map<String, dynamic> get authExtra => _authextra;
}

class Hello implements Message {
Hello(this.realm, this.roles, this.authID, this.authMethods, {Map<String, dynamic>? authExtra})
: authExtra = authExtra ?? {};
Hello(this._helloFields);

static const int id = 1;
static const String text = "HELLO";
Expand All @@ -19,11 +55,17 @@ class Hello implements Message {
},
);

final String realm;
final Map<String, dynamic> roles;
final String authID;
final List<dynamic> authMethods;
final Map<String, dynamic> authExtra;
final IHelloFields _helloFields;

String get realm => _helloFields.realm;

Map<String, dynamic> get roles => _helloFields.roles;

String get authID => _helloFields.authID;

List<dynamic> get authMethods => _helloFields.authMethods;

Map<String, dynamic> get authExtra => _helloFields.authExtra;

static Hello parse(final List<dynamic> message) {
var fields = validateMessage(message, id, text, _validationSpec);
Expand All @@ -45,7 +87,7 @@ class Hello implements Message {
authExtra = validateMapOrRaise(fields.details!["authextra"], text, "authextra");
}

return Hello(fields.realm!, roles, authid, authMethods, authExtra: authExtra);
return Hello(HelloFields(fields.realm!, roles, authid, authMethods, authExtra: authExtra));
}

@override
Expand Down

0 comments on commit c6a2e94

Please sign in to comment.