Skip to content

Commit

Permalink
PubNub SDK v2.0.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Aug 31, 2020
1 parent bbce022 commit 92ed058
Show file tree
Hide file tree
Showing 93 changed files with 1,390 additions and 852 deletions.
21 changes: 20 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
---
changelog:
-
changes:
-
text: "Refactors networking module to allow additional flexibility."
type: feature
-
text: "Adds supervisor module that allows reconnection, retry and other additional, cross module functionalities."
type: feature
-
text: "Adds meta parameter to publish call and makes publish using GET instead of POST."
type: feature
-
text: "Exposes `batch`, `objects` and other APIs from the PubNub class."
type: bug
-
text: "Fixes a typo in BatchHistory where timetoken was returned null."
type: bug
date: Aug 31, 20
version: v2.0.0
-
changes:
-
Expand Down Expand Up @@ -284,4 +303,4 @@ supported-platforms:
platforms:
- "Dart SDK >=2.6.0 <3.0.0"
version: "PubNub Dart SDK"
version: "1.4.4"
version: "2.0.0"
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [v2.0.0](https://github.com/pubnub/dart/releases/tag/v2.0.0)
August 31 2020

[Full Changelog](https://github.com/pubnub/dart/compare/v1.4.4...v2.0.0)

- 🌟️ Refactors networking module to allow additional flexibility.
- 🌟️ Adds supervisor module that allows reconnection, retry and other additional, cross module functionalities.
- 🌟️ Adds meta parameter to publish call and makes publish using GET instead of POST.
- 🐛 Exposes `batch`, `objects` and other APIs from the PubNub class. Fixed the following issues reported by [@devopsokdone](https://github.com/devopsokdone): [#11](https://github.com/pubnub/dart/issues/11).
- 🐛 Fixes a typo in BatchHistory where timetoken was returned null. Fixed the following issues reported by [@devopsokdone](https://github.com/devopsokdone): [#13](https://github.com/pubnub/dart/issues/13).

## [v1.4.4](https://github.com/pubnub/dart/releases/tag/v1.4.4)
August 19 2020

Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include: package:pedantic/analysis_options.yaml

analyzer:
errors:
todo: ignore
# todo: ignore
2 changes: 1 addition & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() async {
await pubnub.publish('test', {'message': 'My message!'});

// Unsubscribe
await subscription.unsubscribe();
await subscription.dispose();

// Channel abstraction for easier usage
var channel = pubnub.channel('test');
Expand Down
16 changes: 9 additions & 7 deletions example/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:pubnub/pubnub.dart';
// This is the same example as the `example.dart` file, but shows how to enable extra logging
void main() async {
// Create a root logger
var logger = StreamLogger.root('root', logLevel: Level.warning);
var logger = StreamLogger.root('root', logLevel: Level.all);

// Subscribe to messages with a default printer
logger.stream.listen(
var sub = logger.stream.listen(
LogRecord.createPrinter(r'[$time] (${level.name}) $scope: $message'));

var pubnub = PubNub(
Expand All @@ -17,13 +17,11 @@ void main() async {
var _ = await provideLogger(logger, () async {
var subscription = await pubnub.subscribe(channels: {'test'});

subscription.messages.take(1).listen((message) {
print(message);
});
await pubnub.publish('test', {'message': 'My message'});

await pubnub.publish('test', {'message': 'My message!'});
print(await subscription.messages.first);

await subscription.unsubscribe();
await subscription.dispose();
});

// You can change the log level as well!
Expand All @@ -42,4 +40,8 @@ void main() async {

print('Messages on test channel: $count');
});

await sub.cancel();
await logger.dispose();
print('disposed!');
}
50 changes: 50 additions & 0 deletions example/supervisor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:io';

import 'package:pubnub/pubnub.dart';
import 'package:pubnub/networking.dart';

void main() async {
var logger = StreamLogger.root('root', logLevel: Level.warning);

// Subscribe to messages with a default printer
logger.stream.listen(
LogRecord.createPrinter(r'[$time] (${level.name}) $scope $message'));

await provideLogger(logger, () async {
// Create PubNub instance with default keyset.
var pubnub = PubNub(
networking: NetworkingModule(
retryPolicy: RetryPolicy.exponential(maxRetries: 10)),
defaultKeyset:
Keyset(subscribeKey: 'demo', publishKey: 'demo', uuid: UUID('demo')),
);

print(
'Network reconnection test. Please wait few seconds for further instructions...');

var sub = await pubnub.subscribe(channels: {'test2'});

await Future.delayed(Duration(seconds: 5));

print('Subscribed. Disconnect your network for few seconds.');

await Future.delayed(Duration(seconds: 5));

var f = pubnub.publish('test2', {'myMessage': 'it works!'});

print(
'Now reconnect your network again! If everything goes well, you should see the message. You will see few diagnostic log lines in the meantime.');

await f;

var message = await sub.messages.first;

print(message.payload);

await sub.dispose();

print('Done!');

exit(0);
});
}
2 changes: 2 additions & 0 deletions lib/networking.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'src/net/net.dart';
export 'src/net/meta/meta.dart';
17 changes: 13 additions & 4 deletions lib/pubnub.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
/// PubNub is an SDK that allows you to communicate with
/// PubNub Data Streaming Network in a fast and easy manner.
///
/// The best starting point to take a look around is the [PubNub] class that combines all available features.
library pubnub;

export './src/core/core.dart';
export './src/dx/_utils/ensure.dart' show InvariantException;
export './src/crypto/crypto.dart' show PubNubCryptoModule, CryptoConfiguration;
export './src/crypto/crypto.dart' show CryptoModule, CryptoConfiguration;

export './src/crypto/encryption_mode.dart'
show EncryptionMode, EncryptionModeExtension;

export './src/dx/files/files.dart' show FileDx;
export './src/dx/batch/batch.dart' show BatchDx;
export './src/dx/objects/objects.dart' show ObjectsDx;
export './src/dx/channel/channel_group.dart' show ChannelGroup, ChannelGroupDx;

export './src/dx/channel/channel.dart' show Channel;
export './src/dx/channel/channel_group.dart' show ChannelGroup;
export './src/dx/push/push.dart' show Device;
export './src/dx/_endpoints/publish.dart' show PublishResult;
export './src/dx/_endpoints/file.dart'
export 'src/dx/_endpoints/files.dart'
show
PublishFileMessageResult,
ListFilesResult,
Expand Down Expand Up @@ -51,11 +58,13 @@ export './src/dx/_endpoints/message_action.dart'
DeleteMessageActionResult;

export './src/dx/subscribe/subscription.dart' show Subscription;
export './src/dx/subscribe/extensions/keyset.dart'
show SubscribeKeysetExtension, PresenceKeysetExtension;
export './src/dx/subscribe/envelope.dart'
show Envelope, PresenceAction, PresenceEvent, MessageType;
export './src/dx/channel/channel_history.dart'
show PaginatedChannelHistory, ChannelHistory;
export './src/dx/file/file.dart';
export 'src/dx/files/files.dart' show FileInfo, FileMessage;
export './src/dx/channel/message.dart' show Message;

export './src/dx/_endpoints/objects/objects_types.dart';
Expand Down
21 changes: 14 additions & 7 deletions lib/src/core/core.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:meta/meta.dart';

import 'net/net.dart';
import 'parse.dart';
import 'parser.dart';
import 'crypto/crypto.dart';
import 'supervisor/supervisor.dart';
import 'keyset.dart';

export 'net/net.dart';
export 'parse.dart';
export 'parser.dart';
export 'logging/logging.dart';
export 'crypto/crypto.dart';
export 'supervisor/supervisor.dart';
export 'keyset.dart';
export 'endpoint.dart';
export 'uuid.dart';
Expand All @@ -19,19 +21,24 @@ class Core {
/// Allows to have multiple [Keyset] associated with one instance of [PubNub].
KeysetStore keysets = KeysetStore();

NetworkModule networking;
ParserModule parser;
CryptoModule crypto;
INetworkingModule networking;
IParserModule parser;
ICryptoModule crypto;
SupervisorModule supervisor = SupervisorModule();

static String version = '1.4.4';
static String version = '2.0.0';

Core(
{Keyset defaultKeyset,
@required this.networking,
@required this.parser,
this.crypto}) {
@required this.crypto}) {
if (defaultKeyset != null) {
keysets.add(defaultKeyset, name: 'default', useAsDefault: true);
}

networking.register(this);
parser.register(this);
crypto.register(this);
}
}
5 changes: 4 additions & 1 deletion lib/src/core/crypto/crypto.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../core.dart';
import '../exceptions.dart';
import 'cipher_key.dart';

Expand All @@ -7,7 +8,9 @@ class CryptoException extends PubNubException {
CryptoException([String message]) : super(message);
}

abstract class CryptoModule {
abstract class ICryptoModule {
void register(Core core);

String encrypt(CipherKey key, String input);
dynamic decrypt(CipherKey key, String input);

Expand Down
6 changes: 6 additions & 0 deletions lib/src/core/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ class NotImplementedException extends PubNubException {
class PublishException extends PubNubException {
PublishException(String message) : super(message);
}

class MaximumRetriesException extends PubNubException {
static final String _message = 'Maximum number of retries has been reached.';

MaximumRetriesException() : super(_message);
}
6 changes: 6 additions & 0 deletions lib/src/core/keyset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class KeysetStore {
}
}
}

Keyset obtain(Keyset keyset, String using) {
keyset ??= get(using, defaultIfNameIsNull: true);

return keyset;
}
}

/// Represents a configuration for a given subscribe key.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/core/logging/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'dummy_logger.dart';
final _pubnubLoggerModuleKey = #pubnub.logging;

/// Provides a [logger] to the code inside [body].
Future<R> provideLogger<R>(ILogger logger, R Function() body) async {
var result =
await runZoned<R>(body, zoneValues: {_pubnubLoggerModuleKey: logger});
Future<R> provideLogger<R>(ILogger logger, Future<R> Function() body) async {
var result = await runZoned<Future<R>>(body,
zoneValues: {_pubnubLoggerModuleKey: logger});

return result;
}
Expand Down
15 changes: 11 additions & 4 deletions lib/src/net/exceptions.dart → lib/src/core/net/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import 'package:pubnub/src/core/exceptions.dart';
import 'package:pubnub/pubnub.dart';

class PubNubRequestTimeoutException extends PubNubException {
PubNubRequestTimeoutException() : super('request timed out');
dynamic additionalData;

PubNubRequestTimeoutException([this.additionalData])
: super('request timed out');
}

class PubNubRequestCancelException extends PubNubException {
dynamic additionalData;

PubNubRequestCancelException([this.additionalData])
: super('request cancelled');
}

class PubNubRequestOtherException extends PubNubException {
dynamic additionalData;

PubNubRequestOtherException([this.additionalData]) : super('request failed');
}

class PubNubRequestFailureException extends PubNubException {
dynamic responseData;
PubNubRequestFailureException(this.responseData) : super('request failed');
IResponse response;

PubNubRequestFailureException(this.response)
: super('request returned non-success status code');
}
19 changes: 14 additions & 5 deletions lib/src/core/net/net.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import 'request.dart';
import '../core.dart';
import 'request_handler.dart';

export 'request.dart' show Request, RequestHandler;
export 'request.dart' show Request;
export 'request_type.dart' show RequestType, RequestTypeExtension;
export 'request_handler.dart' show IRequestHandler;
export 'response.dart' show IResponse;
export 'exceptions.dart'
show
PubNubRequestCancelException,
PubNubRequestFailureException,
PubNubRequestOtherException,
PubNubRequestTimeoutException;

abstract class NetworkModule {
Future<RequestHandler> handle(Request request);
abstract class INetworkingModule {
void register(Core core);

Future<RequestHandler> handleCustomRequest(Request request);
Future<IRequestHandler> handler();
}
Loading

0 comments on commit 92ed058

Please sign in to comment.