Skip to content

Commit

Permalink
Merge pull request #49 from pusher/master
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
proggen-com authored Jun 22, 2022
2 parents b0ba416 + f4b00db commit bddf804
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 190 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
.pub/

build/
.idea/
.idea/

.fvm/
.vscode/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.0

* [BREAKING CHANGE] Convert channel member to Map (instead of Set)
* [FIXED] Add internal member before calling onMemberAdded callback on channel
* [FIXED] onAuthorizer() doesn't work in Flutter web profile/release mode

## 1.0.5

* [FIXED] Android: Subscribing to private channels
Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ a minimal application to connect to a channel and send events.
- [Web specific installation](#web-specific-installation)
- [Initialization](#initialization)
- [Configuration](#configuration)
- [`activityTimeout (double)`](#activitytimeout-double)
- [`apiKey (String)`](#apikey-string)
- [`authParams (Map)`](#authparams-map)
- [`authEndpoint (String)`](#authendpoint-string)
- [`cluster (String)`](#cluster-string)
- [`useTLS (bool)`](#usetls-bool)
- [`activityTimeout (double)`](#activitytimeout-double)
- [`apiKey (String)`](#apikey-string)
- [`authParams (Map)`](#authparams-map)
- [`authEndpoint (String)`](#authendpoint-string)
- [`cluster (String)`](#cluster-string)
- [`useTLS (bool)`](#usetls-bool)
- [Event Callback parameters](#event-callback-parameters)
- [`onEvent`](#onevent)
- [`onSubscriptionSucceeded`](#onsubscriptionsucceeded)
- [`onSubscriptionError`](#onsubscriptionerror)
- [`onDecryptionFailure`](#ondecryptionfailure)
- [`onMemberAdded`](#onmemberadded)
- [`onMemberRemoved`](#onmemberremoved)
- [`onAuthorizer`](#onauthorizer)
- [`onConnectionStateChange`](#onconnectionstatechange)
- [`onError`](#onerror)
- [`onEvent`](#onevent)
- [`onSubscriptionSucceeded`](#onsubscriptionsucceeded)
- [`onSubscriptionError`](#onsubscriptionerror)
- [`onDecryptionFailure`](#ondecryptionfailure)
- [`onMemberAdded`](#onmemberadded)
- [`onMemberRemoved`](#onmemberremoved)
- [`onAuthorizer`](#onauthorizer)
- [`onConnectionStateChange`](#onconnectionstatechange)
- [`onError`](#onerror)
- [Connection handling](#connection-handling)
- [Connecting](#connecting)
- [Disconnecting](#disconnecting)
Expand All @@ -77,6 +77,7 @@ a minimal application to connect to a channel and send events.
- [Parsing event data](#parsing-event-data)
- [Receiving errors](#receiving-errors)
- [Triggering events](#triggering-events)
- [Get a channel by name](#get-a-channel-by-name)
- [Socket information](#socket-information)
- [Communication](#communication)
- [Credits](#credits)
Expand Down Expand Up @@ -199,8 +200,8 @@ await pusher.init(
apiKey: API_KEY,
cluster: API_CLUSTER,
authParams: {
params: { foo: 'bar' },
headers: { baz: 'boo' }
'params': { 'foo': 'bar' },
'headers': { 'baz': 'boo' }
}
});
```
Expand All @@ -216,8 +217,8 @@ final pusher = await pusher.init(
apiKey: API_KEY,
cluster: API_CLUSTER,
authParams: {
params: { foo: 'bar' },
headers: { 'X-CSRF-Token': 'SOME_CSRF_TOKEN' }
'params': { 'foo': 'bar' },
'headers': { 'X-CSRF-Token': 'SOME_CSRF_TOKEN' }
}
);
```
Expand Down Expand Up @@ -306,8 +307,6 @@ Called when a member is removed to the presence channel.

#### `onAuthorizer`

> :warning: Currently on web release/profile mode this doesn't work, we're still investigating this.
When passing the `onAuthorizer()` callback to the `init()` method, this callback is called to request auth information. For more information on how
to generate the correct information, please look here:
https://pusher.com/docs/channels/library_auth_reference/auth-signatures/
Expand Down
13 changes: 3 additions & 10 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -273,13 +273,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
Expand All @@ -302,5 +295,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.16.0-100.0.dev <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.5.0"
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data!.startsWith('Running on:'),
(Widget widget) =>
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
13 changes: 7 additions & 6 deletions lib/pusher-js/core/auth/auth_transports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ library core.auth.auth_transports;
import "package:js/js.dart";
import "../../runtimes/interface.dart" show Runtime;

typedef AuthTransport = void Function(Runtime context, String socketId, Function callback);
typedef AuthTransport = void Function(
Runtime context, String socketId, Function callback);

@anonymous
@JS()
abstract class AuthTransports {
/* Index signature is not yet supported by JavaScript interop. */
}
// @anonymous
// @JS()
// abstract class AuthTransports {

// }
72 changes: 51 additions & 21 deletions lib/pusher-js/core/auth/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,53 @@ import "../channels/channel.dart" show Channel;
@anonymous
@JS()
abstract class AuthOptions {
external dynamic get params;
external set params(dynamic v);
external dynamic get headers;
external set headers(dynamic v);
external factory AuthOptions({dynamic params, dynamic headers});
external Map<String, dynamic> get params;
external set params(Map<String, dynamic> v);
external Map<String, dynamic> get headers;
external set headers(Map<String, dynamic> v);

external factory AuthOptions({
Map<String, dynamic> params,
Map<String, dynamic> headers,
});
}

extension AuthOptionsExt on AuthOptions {
Map<String, dynamic> toMap() => {
'params': params,
'headers': headers,
};
}

@anonymous
@JS()
abstract class AuthData {
external String get auth;
external set auth(String v);
external String get channel_data;
external set channel_data(String v);
external String get shared_secret;
external set shared_secret(String v);
external factory AuthData(
{String auth, String? channel_data, String? shared_secret});
external String? get channel_data;
external set channel_data(String? v);
external String? get shared_secret;
external set shared_secret(String? v);

external factory AuthData({
String auth,
String? channel_data,
String? shared_secret,
});
}

typedef AuthorizerCallback = void Function(Error? error, AuthData authData);

typedef AuthorizeFunc = void Function(
String socketId, AuthorizerCallback callback);

@anonymous
@JS()
abstract class Authorizer {
external void authorize(String socketId, AuthorizerCallback callback);
external set authorize(AuthorizeFunc v);
external AuthorizeFunc get authorize;

external factory Authorizer({AuthorizeFunc authorize});
}

typedef AuthorizerGenerator = Authorizer Function(
Expand All @@ -47,13 +68,22 @@ abstract class AuthorizerOptions {
external set authTransport(String /*'ajax'|'jsonp'*/ v);
external String get authEndpoint;
external set authEndpoint(String v);
external AuthOptions get auth;
external set auth(AuthOptions v);
external AuthorizerGenerator get authorizer;
external set authorizer(AuthorizerGenerator v);
external factory AuthorizerOptions(
{String /*'ajax'|'jsonp'*/ authTransport,
String authEndpoint,
AuthOptions auth,
AuthorizerGenerator authorizer});
external AuthOptions? get auth;
external set auth(AuthOptions? v);
external AuthorizerGenerator? get authorizer;
external set authorizer(AuthorizerGenerator? v);
external factory AuthorizerOptions({
String /*'ajax'|'jsonp'*/ authTransport,
String authEndpoint,
AuthOptions? auth,
AuthorizerGenerator? authorizer,
});
}

extension AuthorizerOptionsExt on AuthorizerOptions {
Map<String, dynamic> toMap() => {
'authTransport': authTransport,
'authEndpoint': authEndpoint,
'auth': auth,
};
}
20 changes: 11 additions & 9 deletions lib/pusher-js/core/auth/pusher_authorizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
library core.auth.pusher_authorizer;

import "package:js/js.dart";
import "options.dart"
show Authorizer, AuthorizerOptions, AuthOptions, AuthorizerCallback;
import "auth_transports.dart" show AuthTransports;
import "options.dart" show Authorizer, AuthorizerOptions, AuthOptions;
import "auth_transports.dart" show AuthTransport;
import "../channels/channel.dart" show Channel;

@JS()
class PusherAuthorizer implements Authorizer {
external static AuthTransports get authorizers;
external static set authorizers(AuthTransports v);
abstract class PusherAuthorizer implements Authorizer {
external static Map<String, AuthTransport> get authorizers;

external Channel get channel;
external set channel(Channel v);
external String get type;
Expand All @@ -19,8 +18,11 @@ class PusherAuthorizer implements Authorizer {
external set options(AuthorizerOptions v);
external AuthOptions get authOptions;
external set authOptions(AuthOptions v);
external factory PusherAuthorizer(Channel channel, AuthorizerOptions options);

external String composeQuery(String socketId);
@override
external void authorize(String socketId, AuthorizerCallback callback);

external factory PusherAuthorizer({
Channel channel,
AuthorizerOptions options,
});
}
3 changes: 0 additions & 3 deletions lib/pusher-js/core/channels/encrypted_channel.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@JS()
library core.channels.encrypted_channel;


import "package:js/js.dart";
import "dart:typed_data";
import "private_channel.dart" show PrivateChannel;
Expand Down Expand Up @@ -33,5 +32,3 @@ class EncryptedChannel extends PrivateChannel {
/// return the utf-8 string
external String getDataToEmit(Uint8List bytes);
}


1 change: 1 addition & 0 deletions lib/pusher-js/core/channels/private_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../auth/options.dart" show AuthorizerCallback;
@JS()
class PrivateChannel extends Channel {
external factory PrivateChannel(String name, Pusher pusher);

/// Authorizes the connection to use the channel.
@override
external authorize(String socketId, AuthorizerCallback callback);
Expand Down
1 change: 0 additions & 1 deletion lib/pusher-js/core/connection/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Connection extends Dispatcher implements Socket {
external bindListeners();
external handleCloseEvent(dynamic closeEvent);


@override
external bool sendRaw(dynamic payload);
@override
Expand Down
1 change: 0 additions & 1 deletion lib/pusher-js/core/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ abstract class Options {
num httpPort,
num httpsPort,
bool ignoreNullOrigin,
// nacl nacl,
num pongTimeout,
String statsHost,
dynamic timelineParams,
Expand Down
2 changes: 1 addition & 1 deletion lib/pusher-js/core/pusher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Pusher {
// external PeriodicTimer get timelineSenderTimer;
// external set timelineSenderTimer(PeriodicTimer v);
external factory Pusher(String app_key, [Options options]);
external Channel channel(String name);
external Channel? channel(String name);
external List<Channel> allChannels();
external connect();
external disconnect();
Expand Down
5 changes: 2 additions & 3 deletions lib/pusher-js/runtimes/interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:html';

import "package:js/js.dart";
import 'package:pusher_channels_flutter/pusher-js/runtimes/web/dom/script_receiver_factory.dart';
import "../core/auth/auth_transports.dart" show AuthTransports;
import "../core/auth/auth_transports.dart" show AuthTransport;
import "../core/timeline/timeline_transport.dart" show TimelineTransport;
import "../core/http/ajax.dart" show Ajax;
import "../core/socket.dart" show Socket;
Expand Down Expand Up @@ -36,7 +36,7 @@ abstract class Runtime {
}*/
PusherClass);
external String getProtocol();
external AuthTransports getAuthorizers();
external Map<String, AuthTransport> getAuthorizers();
external dynamic getLocalStorage();
external TimelineTransport timelineTransport;
//external set TimelineTransport(TimelineTransport v);
Expand Down Expand Up @@ -68,4 +68,3 @@ abstract class Runtime {
}

/* WARNING: export assignment not yet supported. */

Loading

0 comments on commit bddf804

Please sign in to comment.