Skip to content

Commit

Permalink
fixes #14 on github. adds event retention feature
Browse files Browse the repository at this point in the history
  • Loading branch information
konsultaner committed Sep 9, 2020
1 parent 7acb01e commit 1b88d12
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 1.0.6

- [#14](https://github.com/konsultaner/connectanum-dart/issues/14) add support for event retention
- added some more code comments

### 1.0.5

- [#13](https://github.com/konsultaner/connectanum-dart/issues/13) changed meta dependency to match latest flutter dependencies
Expand Down
4 changes: 4 additions & 0 deletions lib/src/message/abort.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'message_types.dart';
import 'abstract_message.dart';

/// The WAMP Abort massage
class Abort extends AbstractMessage {
Message message;
String reason;

/// Creates a WAMP Abort message with a [reason] why something was aborted and an
/// optional [message] to describe the issue
Abort(this.reason, {String message}) {
id = MessageTypes.CODE_ABORT;
if (message != null) {
Expand All @@ -13,6 +16,7 @@ class Abort extends AbstractMessage {
}
}

/// The message structure defined by the WAMP-Protocol
class Message {
String message;

Expand Down
2 changes: 2 additions & 0 deletions lib/src/message/abstract_message.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// all WAMP messages have an id, this abstract message provides this default
/// existing field
abstract class AbstractMessage {
int id;
}
6 changes: 6 additions & 0 deletions lib/src/message/authenticate.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import 'abstract_message.dart';
import 'message_types.dart';

/// The WAMP Authenticate massage
class Authenticate extends AbstractMessage {
String signature;
Map<String, Object> extra;

/// Creates a WAMP Authentication message with a [signature] that was
/// cryptographically created by an authentication method of this package
Authenticate({this.signature}) {
id = MessageTypes.CODE_AUTHENTICATE;
}

/// A factory that creates an instance of a WAMP Authenticate massage by
/// passing in a [signature] that was
/// cryptographically created by an authentication method of this package
factory Authenticate.signature(String signature) {
final authenticate = Authenticate();
authenticate.signature = signature;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/message/call.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'abstract_message_with_payload.dart';
import 'message_types.dart';

/// The WAMP Call massage
class Call extends AbstractMessageWithPayload {
int requestId;
CallOptions options;
String procedure;

/// Creates a WAMP Call message with a [requestId] that is kind of like a
/// transaction identifier and a [procedure] that was registered to the router
/// before. The [options] field may be passed to configure the call
Call(this.requestId, this.procedure,
{this.options,
List<Object> arguments,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/message/cancel.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'abstract_message.dart';
import 'message_types.dart';

/// The WAMP Call massage
class Cancel extends AbstractMessage {
@override
int id;
int requestId;
CancelOptions options;

/// Creates a WAMP Cancel message with the canceled calls [requestId] and
/// some optional [options] to configure the cancel behavior
Cancel(this.requestId, {this.options}) {
id = MessageTypes.CODE_CANCEL;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/message/challenge.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'abstract_message.dart';
import 'message_types.dart';

/// The WAMP Challenge massage
class Challenge extends AbstractMessage {
String authMethod;
Extra extra;

/// Creates a WAMP Challenge message that is returned by the router to
/// challenge the client with a given [authMethod] and some [extra]
/// authentication data
Challenge(this.authMethod, this.extra) {
id = MessageTypes.CODE_CHALLENGE;
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/message/error.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'abstract_message_with_payload.dart';
import 'message_types.dart';

/// The WAMP Error massage
class Error extends AbstractMessageWithPayload {
static final String ERROR_INVOCATION_CANCELED =
'wamp.error.invocation_canceled';
Expand Down
6 changes: 5 additions & 1 deletion lib/src/message/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class PublishOptions {
// publisher_identification == true
bool disclose_me;

// event_retention == true
bool retain;

PublishOptions(
{this.acknowledge,
this.exclude,
Expand All @@ -42,5 +45,6 @@ class PublishOptions {
this.eligible_authid,
this.eligible_authrole,
this.exclude_me,
this.disclose_me});
this.disclose_me,
this.retain});
}
3 changes: 2 additions & 1 deletion lib/src/message/subscribe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SubscribeOptions {

String match;
String meta_topic;
bool get_retained;

SubscribeOptions({this.match, this.meta_topic});
SubscribeOptions({this.match, this.meta_topic, this.get_retained});
}
8 changes: 8 additions & 0 deletions lib/src/serializer/json/serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ class Serializer extends AbstractSerializer {
String _serializeSubscribeOptions(SubscribeOptions options) {
var jsonOptions = [];
if (options != null) {
if (options.get_retained != null) {
jsonOptions
.add('"get_retained":${options.get_retained ? "true" : "false"}');
}
if (options.match != null) {
jsonOptions.add('"match":"${options.match}"');
}
Expand Down Expand Up @@ -433,6 +437,10 @@ class Serializer extends AbstractSerializer {
String _serializePublish(PublishOptions options) {
var jsonDetails = [];
if (options != null) {
if (options.retain != null) {
jsonDetails
.add('"retain":${options.retain ? "true" : "false"}');
}
if (options.disclose_me != null) {
jsonDetails
.add('"disclose_me":${options.disclose_me ? "true" : "false"}');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: connectanum
homepage: https://github.com/konsultaner/connectanum-dart
version: 1.0.5
version: 1.0.6
description: >-
This is a WAMP client (Web Application Messaging Protocol) implementation for the dart language and flutter projects.
dependencies:
Expand Down
6 changes: 4 additions & 2 deletions test/serializer/json/serializer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ void main() {
serializer.serializeToString(Subscribe(
713845233, 'com.myapp.mytopic1',
options: SubscribeOptions(
get_retained: true,
match: SubscribeOptions.MATCH_WILDCARD,
meta_topic: 'topic'))),
equals(
'[32,713845233,{"match":"wildcard","meta_topic":"topic"},"com.myapp.mytopic1"]'));
'[32,713845233,{"get_retained":true,"match":"wildcard","meta_topic":"topic"},"com.myapp.mytopic1"]'));
});
test('Unsubscribe', () {
expect(serializer.serializeToString(Unsubscribe(85346237, 5512315355)),
Expand All @@ -222,6 +223,7 @@ void main() {
expect(
serializer.serializeToString(Publish(239714735, 'com.myapp.mytopic1',
options: PublishOptions(
retain: true,
disclose_me: true,
acknowledge: true,
exclude_me: true,
Expand All @@ -232,7 +234,7 @@ void main() {
exclude_authid: ['bbb'],
exclude_authrole: ['admin']))),
equals(
'[16,239714735,{"disclose_me":true,"acknowledge":true,"exclude_me":true,"exclude":[2],"exclude_authid":["bbb"],"exclude_authrole":["admin"],"eligible":[1],"eligible_authid":["aaa"],"eligible_authrole":["role"]},"com.myapp.mytopic1"]'));
'[16,239714735,{"retain":true,"disclose_me":true,"acknowledge":true,"exclude_me":true,"exclude":[2],"exclude_authid":["bbb"],"exclude_authrole":["admin"],"eligible":[1],"eligible_authid":["aaa"],"eligible_authrole":["role"]},"com.myapp.mytopic1"]'));
expect(
serializer.serializeToString(Publish(239714735, 'com.myapp.mytopic1',
arguments: ['Hello, world!'])),
Expand Down

0 comments on commit 1b88d12

Please sign in to comment.