From 8e410f2d89b1f6f7c0297f16142b01d3d1d10f35 Mon Sep 17 00:00:00 2001 From: JimmyTai Date: Thu, 6 Mar 2025 23:21:47 +0800 Subject: [PATCH 1/3] Update example web project to latest implementation. --- example/.metadata | 24 ++++++- example/web/favicon.png | Bin 916 -> 917 bytes example/web/icons/Icon-192.png | Bin 5291 -> 5292 bytes example/web/icons/Icon-512.png | Bin 8251 -> 8252 bytes example/web/icons/Icon-maskable-192.png | Bin 5593 -> 5594 bytes example/web/icons/Icon-maskable-512.png | Bin 20997 -> 20998 bytes example/web/index.html | 83 ++++-------------------- example/web/manifest.json | 2 +- 8 files changed, 35 insertions(+), 74 deletions(-) diff --git a/example/.metadata b/example/.metadata index 0f055bf..da6e627 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: ffb2ecea5223acdd139a5039be2f9c796962833d - channel: stable + revision: "c519ee916eaeb88923e67befb89c0f1dabfa83e6" + channel: "stable" project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6 + base_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6 + - platform: web + create_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6 + base_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/web/favicon.png b/example/web/favicon.png index 7d241d30a38e1b8e402a3a4ce796e8aa813e5ba7..8aaa46ac1ae21512746f852a42ba87e4165dfdd1 100644 GIT binary patch delta 14 VcmbQjK9!xdGr-TCcO%OLW&j^e1ONa4 delta 13 UcmbQrK82m7Gr-S%BkKfa032Nd^8f$< diff --git a/example/web/icons/Icon-192.png b/example/web/icons/Icon-192.png index abd83011dae1a86262373f264a2449fd85ca93ec..b749bfef07473333cf1dd31e9eed89862a5d52aa 100644 GIT binary patch delta 14 VcmZ3jxki( + - + + - + + + + pusher_channels_flutter_example - - - + + - + + \ No newline at end of file diff --git a/example/web/manifest.json b/example/web/manifest.json index 257c03c..bd5c6b7 100644 --- a/example/web/manifest.json +++ b/example/web/manifest.json @@ -5,7 +5,7 @@ "display": "standalone", "background_color": "#0175C2", "theme_color": "#0175C2", - "description": "Demonstrates how to use the pusher_channels_flutter plugin.", + "description": "A new Flutter project.", "orientation": "portrait-primary", "prefer_related_applications": false, "icons": [ From 516a655f1b8cc5007131eedbe6fb65f14b09364b Mon Sep 17 00:00:00 2001 From: JimmyTai Date: Thu, 6 Mar 2025 23:24:05 +0800 Subject: [PATCH 2/3] Create pusher-js implementation by using dart:js_interop. --- lib/pusher_channels_flutter_wasm.dart | 306 ++++++++++++++++++ .../auth/deprecated_channel_authorizer.dart | 66 ++++ lib/wasm-pusher-js/core/auth/options.dart | 122 +++++++ lib/wasm-pusher-js/core/channels.dart | 21 ++ lib/wasm-pusher-js/core/channels/channel.dart | 43 +++ .../core/channels/channel_table.dart | 9 + lib/wasm-pusher-js/core/channels/members.dart | 24 ++ .../core/channels/metadata.dart | 6 + .../core/channels/presence_channel.dart | 25 ++ .../core/channels/private_channel.dart | 13 + lib/wasm-pusher-js/core/config.dart | 57 ++++ .../core/connection/connection.dart | 31 ++ .../core/connection/connection_manager.dart | 65 ++++ .../connection_manager_options.dart | 19 ++ .../connection/protocol/message_types.dart | 19 ++ lib/wasm-pusher-js/core/events/callback.dart | 7 + .../core/events/callback_registry.dart | 17 + .../core/events/callback_table.dart | 9 + .../core/events/dispatcher.dart | 32 ++ lib/wasm-pusher-js/core/options.dart | 94 ++++++ lib/wasm-pusher-js/core/pusher.dart | 100 ++++++ lib/wasm-pusher-js/core/socket.dart | 26 ++ .../core/strategies/strategy.dart | 9 + .../core/strategies/strategy_runner.dart | 17 + lib/wasm-pusher-js/core/timeline/level.dart | 9 + .../core/timeline/timeline.dart | 60 ++++ .../core/timeline/timeline_sender.dart | 32 ++ lib/wasm-pusher-js/core/user.dart | 25 ++ lib/wasm-pusher-js/error.dart | 30 ++ 29 files changed, 1293 insertions(+) create mode 100644 lib/pusher_channels_flutter_wasm.dart create mode 100644 lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart create mode 100644 lib/wasm-pusher-js/core/auth/options.dart create mode 100644 lib/wasm-pusher-js/core/channels.dart create mode 100644 lib/wasm-pusher-js/core/channels/channel.dart create mode 100644 lib/wasm-pusher-js/core/channels/channel_table.dart create mode 100644 lib/wasm-pusher-js/core/channels/members.dart create mode 100644 lib/wasm-pusher-js/core/channels/metadata.dart create mode 100644 lib/wasm-pusher-js/core/channels/presence_channel.dart create mode 100644 lib/wasm-pusher-js/core/channels/private_channel.dart create mode 100644 lib/wasm-pusher-js/core/config.dart create mode 100644 lib/wasm-pusher-js/core/connection/connection.dart create mode 100644 lib/wasm-pusher-js/core/connection/connection_manager.dart create mode 100644 lib/wasm-pusher-js/core/connection/connection_manager_options.dart create mode 100644 lib/wasm-pusher-js/core/connection/protocol/message_types.dart create mode 100644 lib/wasm-pusher-js/core/events/callback.dart create mode 100644 lib/wasm-pusher-js/core/events/callback_registry.dart create mode 100644 lib/wasm-pusher-js/core/events/callback_table.dart create mode 100644 lib/wasm-pusher-js/core/events/dispatcher.dart create mode 100644 lib/wasm-pusher-js/core/options.dart create mode 100644 lib/wasm-pusher-js/core/pusher.dart create mode 100644 lib/wasm-pusher-js/core/socket.dart create mode 100644 lib/wasm-pusher-js/core/strategies/strategy.dart create mode 100644 lib/wasm-pusher-js/core/strategies/strategy_runner.dart create mode 100644 lib/wasm-pusher-js/core/timeline/level.dart create mode 100644 lib/wasm-pusher-js/core/timeline/timeline.dart create mode 100644 lib/wasm-pusher-js/core/timeline/timeline_sender.dart create mode 100644 lib/wasm-pusher-js/core/user.dart create mode 100644 lib/wasm-pusher-js/error.dart diff --git a/lib/pusher_channels_flutter_wasm.dart b/lib/pusher_channels_flutter_wasm.dart new file mode 100644 index 0000000..403a5c8 --- /dev/null +++ b/lib/pusher_channels_flutter_wasm.dart @@ -0,0 +1,306 @@ +import 'dart:async'; +import 'dart:js_interop'; + +// In order to *not* need this ignore, consider extracting the 'web' version +// of your plugin as a separate package, instead of inlining it in the same +// package as the core of your plugin. +// ignore: avoid_web_libraries_in_flutter +import 'package:flutter/services.dart'; +import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:js/js_util.dart' as js_util; +import 'package:pusher_channels_flutter/wasm-pusher-js/core/auth/options.dart'; + +import 'wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart'; +import 'wasm-pusher-js/core/channels/channel.dart'; +import 'wasm-pusher-js/core/channels/presence_channel.dart'; +import 'wasm-pusher-js/core/options.dart'; +import 'wasm-pusher-js/core/pusher.dart'; +import 'wasm-pusher-js/error.dart'; + +@JS('JSON.stringify') +external String stringify(JSObject obj); + +@JS('Object.keys') +external JSArray objectKeys(JSObject object); + +bool _isBasicType(value) { + if (value == null || value is num || value is bool || value is String) { + return true; + } + return false; +} + +T dartify(dynamic jsObject) { + if (_isBasicType(jsObject)) { + return jsObject as T; + } + if (jsObject is List) { + return jsObject.map(dartify).toList() as T; + } + var keys = objectKeys(jsObject); + var result = {}; + for (var key in keys.toDart.map((e) => e.toDart)) { + result[key] = dartify(js_util.getProperty(jsObject, key)); + } + return result as T; +} + +/// A web implementation of the PusherChannelsFlutter plugin. +class PusherChannelsFlutterWasm { + Pusher? pusher; + MethodChannel? methodChannel; + + static void registerWith(Registrar registrar) { + final pluginInstance = PusherChannelsFlutterWasm(); + pluginInstance.methodChannel = MethodChannel( + 'pusher_channels_flutter', + const StandardMethodCodec(), + registrar, + ); + pluginInstance.methodChannel! + .setMethodCallHandler(pluginInstance.handleMethodCall); + } + + Future handleMethodCall(MethodCall call) async { + switch (call.method) { + case 'init': + init(call); + break; + case 'connect': + assertPusher(); + pusher!.connect(); + break; + case 'disconnect': + assertPusher(); + pusher!.disconnect(); + break; + case 'subscribe': + subscribe(call); + break; + case 'unsubscribe': + unsubscribe(call); + break; + case 'trigger': + trigger(call); + break; + case 'getSocketId': + return pusher!.connection.socketId; + default: + throw PlatformException( + code: 'Unimplemented', + details: + 'pusher_channels for web doesn\'t implement \'${call.method}\'', + ); + } + } + + void assertPusher() { + if (pusher == null) { + throw ArgumentError.notNull('Pusher not initialized'); + } + } + + void assertChannel(String channelName) { + if (pusher!.channel(channelName) == null) { + throw ArgumentError.notNull('Not subscribed to channel: $channelName'); + } + } + + void onError(JSAny jsError) { + final Map error = dartify>(jsError); + + print('onError, error: $error'); + + if (error['type'] == 'PusherError') { + methodChannel!.invokeMethod('onError', { + 'message': error['data']?['message'], + 'code': error['data']?['code'], + 'error': error, + }); + } + } + + void onMessage(JSAny jsMessage) { + final Map msg = dartify>(jsMessage); + final String event = msg['event'] ?? ''; + final String channel = msg['channel'] ?? ''; + final Map data = msg['data'] ?? {}; + String? userId = data['user_id']; + final Map? userInfo = data['user_info']; + + print('onMessage, event: $event, channel: $channel, data: $data'); + + if (event == 'pusher_internal:subscription_error') { + methodChannel!.invokeMethod( + 'onSubscriptionError', {'message': msg['error'], 'error': data}); + } else if (event == 'pusher_internal:member_added') { + methodChannel!.invokeMethod('onMemberAdded', { + 'channelName': channel, + 'user': { + 'userId': userId, + 'userInfo': userInfo, + } + }); + } else if (event == 'pusher_internal:member_removed') { + methodChannel!.invokeMethod('onMemberRemoved', { + 'channelName': channel, + 'user': { + 'userId': userId, + 'userInfo': userInfo, + } + }); + } else { + if (event == 'pusher_internal:subscription_succeeded') { + if (channel.startsWith('presence-')) { + final presenceChannel = pusher!.channel(channel) as PresenceChannel; + final id = presenceChannel.members.myId; + if (id.isA()) { + userId = (id as JSString).toDart; + } + } + } + methodChannel!.invokeMethod('onEvent', { + 'channelName': channel, + 'eventName': event, + 'data': data, + 'userId': userId, + }); + } + } + + void onStateChange(JSAny? jsState) { + final Map state = + dartify>(jsState ?? {}); + final String current = state['current'] ?? ''; + final String previous = state['previous'] ?? ''; + methodChannel!.invokeMethod('onConnectionStateChange', { + 'currentState': current, + 'previousState': previous, + }); + } + + void onConnected(JSAny jsMessage) {} + + void onDisconnected() {} + + DeprecatedChannelAuthorizer onAuthorizer( + Channel channel, + DeprecatedAuthorizerOptions options, + ) => + DeprecatedChannelAuthorizer.create( + FlutterDartDeprecatedChannelAuthorizer( + methodChannel: methodChannel!, + channel: channel, + options: options, + ), + ); + + void subscribe(MethodCall call) { + assertPusher(); + var channelName = call.arguments['channelName']; + pusher!.subscribe(channelName); + } + + void unsubscribe(MethodCall call) { + var channelName = call.arguments['channelName']; + var channel = pusher!.channel(channelName); + pusher!.unsubscribe(channelName); + channel?.unbindAll(); + } + + void trigger(MethodCall call) { + var channelName = call.arguments['channelName']; + var channel = pusher!.channel(channelName); + channel?.trigger(call.arguments['eventName'], call.arguments['data']); + } + + void init(MethodCall call) { + if (pusher != null) { + pusher!.unbindAll(); + pusher!.disconnect(); + } + var options = Options(); + if (call.arguments['cluster'] != null) { + options.cluster = call.arguments['cluster']; + } + if (call.arguments['forceTLS'] != null) { + options.forceTLS = call.arguments['forceTLS']; + } + if (call.arguments['pongTimeout'] != null) { + options.pongTimeout = call.arguments['pongTimeout']; + } + if (call.arguments['enableStats'] != null) { + options.enableStats = call.arguments['enableStats']; + } + if (call.arguments['disabledTransports'] != null) { + options.disabledTransports = call.arguments['disabledTransports']; + } + if (call.arguments['enabledTransports'] != null) { + options.enabledTransports = call.arguments['enabledTransports']; + } + if (call.arguments['ignoreNullOrigin'] != null) { + options.ignoreNullOrigin = call.arguments['ignoreNullOrigin']; + } + if (call.arguments['authTransport'] != null) { + options.authTransport = call.arguments['authTransport']; + } + if (call.arguments['authEndpoint'] != null) { + options.authEndpoint = call.arguments['authEndpoint']; + } + if (call.arguments['authParams'] != null) { + options.auth = call.arguments['authParams']; + } + if (call.arguments['logToConsole'] != null) { + Pusher.logToConsole = call.arguments['logToConsole']; + } + if (call.arguments['authorizer'] != null) { + options.authorizer = ChannelAuthorizerGenerator.create(onAuthorizer); + } + pusher = Pusher(call.arguments['apiKey'], options); + pusher!.connection.bind('error', onError.toJS); + pusher!.connection.bind('message', onMessage.toJS); + pusher!.connection.bind('state_change', onStateChange.toJS); + pusher!.connection.bind('connected', onConnected.toJS); + pusher!.connection.bind('disconnected', onDisconnected.toJS); + } +} + +final class FlutterDartDeprecatedChannelAuthorizer + implements DartDeprecatedChannelAuthorizer { + const FlutterDartDeprecatedChannelAuthorizer({ + required this.methodChannel, + required this.channel, + required this.options, + }); + + final MethodChannel methodChannel; + final Channel channel; + final DeprecatedAuthorizerOptions options; + + @override + void authorize(String socketId, ChannelAuthorizationCallback callback) async { + try { + var authData = await methodChannel.invokeMethod('onAuthorizer', { + 'socketId': socketId, + 'channelName': channel.name, + 'options': options.toMap(), + }); + callback.call( + null, + ChannelAuthorizationData.create( + auth: authData['auth'], + channelData: authData['channel_data'], + sharedSecret: authData['shared_secret'], + ), + ); + } catch (e, stackTrace) { + callback.call( + JSError.create( + message: '$e', + stackTrace: stackTrace, + ), + null, + ); + } + } +} diff --git a/lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart b/lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart new file mode 100644 index 0000000..b1e3afc --- /dev/null +++ b/lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart @@ -0,0 +1,66 @@ +import 'dart:js_interop'; + +import '../channels/channel.dart'; +import 'options.dart'; + +@JSExport() +abstract class DartDeprecatedChannelAuthorizer { + @JSExport() + void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ) {} +} + +extension type DeprecatedChannelAuthorizer._(JSObject _) implements JSObject { + static DeprecatedChannelAuthorizer create( + DartDeprecatedChannelAuthorizer authorizer, + ) => + createJSInteropWrapper(authorizer) + as DeprecatedChannelAuthorizer; + + external void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ); +} + +typedef DartChannelAuthorizerGenerator = DeprecatedChannelAuthorizer Function( + Channel channel, + DeprecatedAuthorizerOptions options, +); + +extension type ChannelAuthorizerGenerator._(JSFunction _) + implements JSFunction { + static ChannelAuthorizerGenerator create( + DartChannelAuthorizerGenerator function) => + function.toJS as ChannelAuthorizerGenerator; +} + +extension type DeprecatedAuthOptions._(JSObject _) implements JSObject { + external DeprecatedAuthOptions({JSAny? params, JSAny? headers}); + + external JSAny? params; + + external JSAny? headers; +} + +extension type DeprecatedAuthorizerOptions._(JSObject _) implements JSObject { + /// Allow 'ajax' | 'jsonp' + external String authTransport; + + external String authEndpoint; + + external DeprecatedAuthOptions? auth; +} + +extension DeprecatedAuthorizerOptionsToDart on DeprecatedAuthorizerOptions { + Map toMap() => { + 'authTransport': authTransport, + 'authEndpoint': authEndpoint, + 'auth': { + 'params': auth?.params?.toExternalReference.toDartObject, + 'headers': auth?.headers?.toExternalReference.toDartObject + } + }; +} diff --git a/lib/wasm-pusher-js/core/auth/options.dart b/lib/wasm-pusher-js/core/auth/options.dart new file mode 100644 index 0000000..40d3e58 --- /dev/null +++ b/lib/wasm-pusher-js/core/auth/options.dart @@ -0,0 +1,122 @@ +import 'dart:js_interop'; + +import '../../error.dart'; + +extension type ChannelAuthorizationData._(JSObject _) implements JSObject { + static ChannelAuthorizationData create({ + required String auth, + String? channelData, + String? sharedSecret, + }) { + return (JSObject() as ChannelAuthorizationData) + ..auth = auth + ..channelData = channelData + ..sharedSecret = sharedSecret; + } + + external String auth; + + @JS('channel_data') + external String? channelData; + + @JS('shared_secret') + external String? sharedSecret; +} + +extension type ChannelAuthorizationCallback._(JSFunction _) + implements JSFunction { + void call( + JSError? error, + ChannelAuthorizationData? authData, + ) => + callAsFunction(null, error, authData); +} + +extension type ChannelAuthorizationRequestParams._(JSObject _) + implements JSObject { + external ChannelAuthorizationRequestParams({ + String socketId, + String channelName, + }); + + external String socketId; + + external String channelName; +} + +typedef DartChannelAuthorizationHandler = void Function( + ChannelAuthorizationRequestParams params, + ChannelAuthorizationCallback callback, +); + +extension type ChannelAuthorizationHandler._(JSFunction _) + implements JSFunction { + static ChannelAuthorizationHandler create( + DartChannelAuthorizationHandler handler, + ) => + handler.toJS as ChannelAuthorizationHandler; +} + +extension type UserAuthenticationData._(JSObject _) implements JSObject { + static UserAuthenticationData create({ + required String auth, + required String userData, + }) { + return (JSObject() as UserAuthenticationData) + ..auth = auth + ..userData = userData; + } + + external String auth; + + @JS('user_data') + external String userData; +} + +extension type UserAuthenticationCallback._(JSFunction _) + implements JSFunction { + void call( + JSError? error, + UserAuthenticationData? authData, + ) => + callAsFunction(null, error, authData); +} + +extension type UserAuthenticationRequestParams._(JSObject _) + implements JSObject { + external String socketId; +} + +typedef DartUserAuthenticationHandler = void Function( + UserAuthenticationRequestParams params, + UserAuthenticationCallback callback, +); + +extension type UserAuthenticationHandler._(JSFunction _) implements JSFunction { + static UserAuthenticationHandler create( + DartUserAuthenticationHandler handler, + ) => + handler.toJS as UserAuthenticationHandler; +} + +typedef UserAuthenticationOptions = AuthOptionsT; + +typedef ChannelAuthorizationOptions = AuthOptionsT; + +extension type AuthOptionsT._(JSObject _) + implements JSObject { + // Allow 'ajax' | 'jsonp' + external String transport; + + external String endpoint; + + external JSAny params; + + external JSAny headers; + + external JSFunction? paramsProvider; + + external JSFunction? headersProvider; + + external AuthHandler? customHandler; +} diff --git a/lib/wasm-pusher-js/core/channels.dart b/lib/wasm-pusher-js/core/channels.dart new file mode 100644 index 0000000..1d92373 --- /dev/null +++ b/lib/wasm-pusher-js/core/channels.dart @@ -0,0 +1,21 @@ +import 'dart:js_interop'; + +import 'channels/channel.dart'; +import 'channels/channel_table.dart'; +import 'pusher.dart'; + +extension type Channels._(JSObject _) implements JSObject { + external Channels(); + + external ChannelTable channels; + + external Channel add(String name, Pusher pusher); + + external JSArray all(); + + external Channel find(String name); + + external Channel remove(String name); + + external void disconnect(); +} diff --git a/lib/wasm-pusher-js/core/channels/channel.dart b/lib/wasm-pusher-js/core/channels/channel.dart new file mode 100644 index 0000000..3c17bd1 --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/channel.dart @@ -0,0 +1,43 @@ +import 'dart:js_interop'; + +import '../auth/options.dart'; +import '../connection/protocol/message_types.dart'; +import '../events/dispatcher.dart'; +import '../pusher.dart'; + +extension type Channel._(Dispatcher _) implements Dispatcher { + external Channel(String name, Pusher pusher); + + external String name; + + external Pusher pusher; + + external bool subscribed; + + external bool subscriptionPending; + + external bool subscriptionCancelled; + + external void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ); + + external bool trigger(String event, [JSAny data]); + + external void disconnect(); + + external void handleEvent(PusherEvent event); + + external void handleSubscriptionSucceededEvent(PusherEvent event); + + external void handleSubscriptionCountEvent(PusherEvent event); + + external void subscribe(); + + external void unsubscribe(); + + external void cancelSubscription(); + + external void reinstateSubscription(); +} diff --git a/lib/wasm-pusher-js/core/channels/channel_table.dart b/lib/wasm-pusher-js/core/channels/channel_table.dart new file mode 100644 index 0000000..df67cf5 --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/channel_table.dart @@ -0,0 +1,9 @@ +import 'dart:js_interop'; + +import 'channel.dart'; + +extension type ChannelTable._(JSObject _) implements JSObject { + external Channel? operator [](String index); + + external void operator []=(String index, Channel value); +} diff --git a/lib/wasm-pusher-js/core/channels/members.dart b/lib/wasm-pusher-js/core/channels/members.dart new file mode 100644 index 0000000..7b9dfcb --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/members.dart @@ -0,0 +1,24 @@ +import 'dart:js_interop'; + +extension type Members._(JSObject _) implements JSObject { + external Members(); + + external JSAny members; + + external num count; + + @JS('myID') + external JSAny myId; + + external JSAny get(String id); + + external void each(JSFunction callback); + + external void onSubscription(JSAny subscriptionData); + + external JSAny addMember(JSAny memberData); + + external JSAny removeMember(JSAny memberData); + + external void reset(); +} diff --git a/lib/wasm-pusher-js/core/channels/metadata.dart b/lib/wasm-pusher-js/core/channels/metadata.dart new file mode 100644 index 0000000..a261dec --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/metadata.dart @@ -0,0 +1,6 @@ +import 'dart:js_interop'; + +extension type Metadata._(JSObject _) implements JSObject { + @JS('user_id') + external String? userId; +} diff --git a/lib/wasm-pusher-js/core/channels/presence_channel.dart b/lib/wasm-pusher-js/core/channels/presence_channel.dart new file mode 100644 index 0000000..8a34e3d --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/presence_channel.dart @@ -0,0 +1,25 @@ +import 'dart:js_interop'; + +import '../connection/protocol/message_types.dart'; +import '../pusher.dart'; +import 'members.dart'; +import 'private_channel.dart'; + +extension type PresenceChannel._(PrivateChannel _) implements PrivateChannel { + external PresenceChannel({ + String name, + Pusher pusher, + }); + + external Members members; + + external void authorize(String socketId, JSFunction callback); + + external void handleEvent(PusherEvent event); + + external void handleInternalEvent(PusherEvent event); + + external void handleSubscriptionSucceededEvent(PusherEvent event); + + external void disconnect(); +} diff --git a/lib/wasm-pusher-js/core/channels/private_channel.dart b/lib/wasm-pusher-js/core/channels/private_channel.dart new file mode 100644 index 0000000..12bf822 --- /dev/null +++ b/lib/wasm-pusher-js/core/channels/private_channel.dart @@ -0,0 +1,13 @@ +// export default class PrivateChannel extends Channel { +// authorize(socketId: string, callback: ChannelAuthorizationCallback): void; +// } + +import '../auth/options.dart'; +import 'channel.dart'; + +extension type PrivateChannel._(Channel _) implements Channel { + external void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ); +} diff --git a/lib/wasm-pusher-js/core/config.dart b/lib/wasm-pusher-js/core/config.dart new file mode 100644 index 0000000..6338628 --- /dev/null +++ b/lib/wasm-pusher-js/core/config.dart @@ -0,0 +1,57 @@ +import 'dart:js_interop'; + +/// Allow 'ajax' | 'jsonp' +typedef AuthTransport = JSString; + +/// Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' +typedef Transport = JSString; + +extension type Config._(JSObject _) implements JSObject { + external num activityTimeout; + + external bool enableStats; + + external String httpHost; + + external String httpPath; + + external num httpPort; + + external num httpsPort; + + external num pongTimeout; + + external String statsHost; + + external num unavailableTimeout; + + @JS('useTLS') + external bool useTls; + + external String wsHost; + + external String wsPath; + + external num wsPort; + + external num wssPort; + + external JSFunction userAuthenticator; + + external JSFunction channelAuthorizer; + + @JS('forceTLS') + external bool? forceTls; + + external String? cluster; + + external JSArray? disabledTransports; + + external JSArray? enabledTransports; + + external bool? ignoreNullOrigin; + + // external Nacl? nacl; + + external JSAny timelineParams; +} diff --git a/lib/wasm-pusher-js/core/connection/connection.dart b/lib/wasm-pusher-js/core/connection/connection.dart new file mode 100644 index 0000000..344644b --- /dev/null +++ b/lib/wasm-pusher-js/core/connection/connection.dart @@ -0,0 +1,31 @@ +import 'dart:js_interop'; + +import '../events/dispatcher.dart'; + +extension type Connection._(Dispatcher _) implements Dispatcher { + external Connection( + String id, + // TransportConnection transport, + ); + + external String id; + + // external TransportConnection transport; + + external num activityTimeout; + + external bool handlesActivityChecks(); + + external bool send(JSAny? data); + + @JS('send_event') + external bool sendEvent( + String name, + JSAny? data, [ + String? channel, + ]); + + external void ping(); + + external void close(); +} diff --git a/lib/wasm-pusher-js/core/connection/connection_manager.dart b/lib/wasm-pusher-js/core/connection/connection_manager.dart new file mode 100644 index 0000000..09ba714 --- /dev/null +++ b/lib/wasm-pusher-js/core/connection/connection_manager.dart @@ -0,0 +1,65 @@ +import 'dart:js_interop'; + +import '../events/dispatcher.dart'; +import '../strategies/strategy.dart'; +import '../strategies/strategy_runner.dart'; +import '../timeline/timeline.dart'; +import 'connection.dart'; +import 'connection_manager_options.dart'; + +extension type ConnectionManager._(Dispatcher _) implements Dispatcher { + external ConnectionManager({ + String key, + ConnectionManagerOptions options, + }); + + external String key; + + external ConnectionManagerOptions options; + + external String state; + + external Connection connection; + + @JS('usingTLS') + external bool usingTls; + + external Timeline timeline; + + @JS('socket_id') + external String socketId; + + // external Timer unavailableTimer; + + // external Timer activityTimer; + + // external Timer retryTimer; + + external num activityTimeout; + + external Strategy strategy; + + external StrategyRunner runner; + + // external ErrorCallbacks errorCallbacks; + + // external HandshakeCallbacks handshakeCallbacks; + + // external ConnectionCallbacks connectionCallbacks; + + external void connect(); + + external bool send(JSAny? data); + + @JS('send_event') + external bool sendEvent( + String name, + JSAny? data, [ + String? channel, + ]); + + external void disconnect(); + + @JS('isUsingTLS') + external bool isUsingTls(); +} diff --git a/lib/wasm-pusher-js/core/connection/connection_manager_options.dart b/lib/wasm-pusher-js/core/connection/connection_manager_options.dart new file mode 100644 index 0000000..eea8f19 --- /dev/null +++ b/lib/wasm-pusher-js/core/connection/connection_manager_options.dart @@ -0,0 +1,19 @@ +import 'dart:js_interop'; + +import '../timeline/timeline.dart'; + +extension type ConnectionManagerOptions._(JSObject _) implements JSObject { + external Timeline timeline; + + external JSFunction getStrategy; + + external num unavailableTimeout; + + external num pongTimeout; + + external num activityTimeout; + + @JS('useTLS') + external bool useTls; +} + diff --git a/lib/wasm-pusher-js/core/connection/protocol/message_types.dart b/lib/wasm-pusher-js/core/connection/protocol/message_types.dart new file mode 100644 index 0000000..503960f --- /dev/null +++ b/lib/wasm-pusher-js/core/connection/protocol/message_types.dart @@ -0,0 +1,19 @@ +import 'dart:js_interop'; + +extension type PusherEvent._(JSObject _) implements JSObject { + external PusherEvent({ + String event, + String? channel, + JSAny data, + String? userId, + }); + + external String event; + + external String? channel; + + external JSAny data; + + @JS('user_id') + external String? userId; +} diff --git a/lib/wasm-pusher-js/core/events/callback.dart b/lib/wasm-pusher-js/core/events/callback.dart new file mode 100644 index 0000000..91cede0 --- /dev/null +++ b/lib/wasm-pusher-js/core/events/callback.dart @@ -0,0 +1,7 @@ +import 'dart:js_interop'; + +extension type Callback._(JSObject _) implements JSObject { + external JSFunction fn; + + external JSAny? context; +} diff --git a/lib/wasm-pusher-js/core/events/callback_registry.dart b/lib/wasm-pusher-js/core/events/callback_registry.dart new file mode 100644 index 0000000..78a31e0 --- /dev/null +++ b/lib/wasm-pusher-js/core/events/callback_registry.dart @@ -0,0 +1,17 @@ +import 'dart:js_interop'; + +import 'callback.dart'; +import 'callback_table.dart'; + +extension type CallbackRegistry._(JSObject _) implements JSObject { + external CallbackRegistry(); + + @JS('_callbacks') + external CallbackTable callbacks; + + external JSArray get(JSString name); + + external void add(String name, JSFunction callback, JSAny? context); + + external void remove([String? name, JSFunction? callback, JSAny? context]); +} diff --git a/lib/wasm-pusher-js/core/events/callback_table.dart b/lib/wasm-pusher-js/core/events/callback_table.dart new file mode 100644 index 0000000..28f1c18 --- /dev/null +++ b/lib/wasm-pusher-js/core/events/callback_table.dart @@ -0,0 +1,9 @@ +import 'dart:js_interop'; + +import 'callback.dart'; + +extension type CallbackTable._(JSObject _) implements JSObject { + external Callback? operator [](String index); + + external void operator []=(String index, Callback value); +} diff --git a/lib/wasm-pusher-js/core/events/dispatcher.dart b/lib/wasm-pusher-js/core/events/dispatcher.dart new file mode 100644 index 0000000..ee1429c --- /dev/null +++ b/lib/wasm-pusher-js/core/events/dispatcher.dart @@ -0,0 +1,32 @@ +import 'dart:js_interop'; + +import '../channels/metadata.dart'; +import 'callback_registry.dart'; + +extension type Dispatcher._(JSObject _) implements JSObject { + external Dispatcher([JSFunction? failThrough]); + + external CallbackRegistry callbacks; + + @JS('global_callbacks') + external JSArray globalCallbacks; + + external JSFunction failThrough; + + external Dispatcher bind(String eventName, JSFunction callback, + [JSAny? context]); + + @JS('bind_global') + external Dispatcher bindGlobal(JSFunction callback); + + external Dispatcher unbind( + [String? eventName, JSFunction? callback, JSAny? context]); + + @JS('unbind_global') + external Dispatcher unbindGlobal([JSFunction? callback]); + + @JS('unbind_all') + external Dispatcher unbindAll(); + + external Dispatcher emit(String eventName, [JSAny? data, Metadata? metadata]); +} diff --git a/lib/wasm-pusher-js/core/options.dart b/lib/wasm-pusher-js/core/options.dart new file mode 100644 index 0000000..26135d5 --- /dev/null +++ b/lib/wasm-pusher-js/core/options.dart @@ -0,0 +1,94 @@ +import 'dart:js_interop'; + +import 'auth/deprecated_channel_authorizer.dart'; +import 'auth/options.dart'; + +extension type Options._(JSObject _) implements JSObject { + external Options({ + num? activityTimeout, + DeprecatedAuthOptions? auth, + String? authEndpoint, + String? authTransport, + ChannelAuthorizerGenerator? authorizer, + ChannelAuthorizationOptions? channelAuthorization, + UserAuthenticationOptions? userAuthentication, + String? cluster, + bool? enableStats, + bool? disableStats, + JSArray? disabledTransports, + JSArray? enabledTransports, + bool? forceTLS, + String? httpHost, + String? httpPath, + num? httpPort, + bool? ignoreNullOrigin, + // Nacl? nacl; + num? pongTimeout, + String? statsHost, + JSAny timelineParams, + num? unavailableTimeout, + String? wsHost, + String? wsPath, + num? wsPort, + num? wssPort, + }); + + external num? activityTimeout; + + @Deprecated('Use channelAuthorization instead') + external DeprecatedAuthOptions? auth; + + @Deprecated('Use channelAuthorization instead') + external String? authEndpoint; + + /// Allow 'ajax' | 'jsonp' + @Deprecated('Use channelAuthorization instead') + external String? authTransport; + + @Deprecated('Use channelAuthorization instead') + external ChannelAuthorizerGenerator? authorizer; + + external ChannelAuthorizationOptions? channelAuthorization; + + external UserAuthenticationOptions? userAuthentication; + + external String? cluster; + + external bool? enableStats; + + external bool? disableStats; + + // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' + external JSArray? disabledTransports; + + // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' + external JSArray? enabledTransports; + + external bool? forceTLS; + + external String? httpHost; + + external String? httpPath; + + external num? httpPort; + + external bool? ignoreNullOrigin; + + // external Nacl? nacl; + + external num? pongTimeout; + + external String? statsHost; + + external JSAny? timelineParams; + + external num? unavailableTimeout; + + external String? wsHost; + + external String? wsPath; + + external num? wsPort; + + external num? wssPort; +} diff --git a/lib/wasm-pusher-js/core/pusher.dart b/lib/wasm-pusher-js/core/pusher.dart new file mode 100644 index 0000000..aaba4da --- /dev/null +++ b/lib/wasm-pusher-js/core/pusher.dart @@ -0,0 +1,100 @@ +import 'dart:js_interop'; + +import 'channels.dart'; +import 'channels/channel.dart'; +import 'config.dart'; +import 'connection/connection_manager.dart'; +import 'events/dispatcher.dart'; +import 'options.dart'; +import 'timeline/timeline.dart'; +import 'timeline/timeline_sender.dart'; +import 'user.dart'; + +extension type Pusher._(JSObject _) implements JSObject { + external Pusher(String appKey, Options options); + + /// STATIC PROPERTIES + external static JSArray instances; + + external static bool isRead; + + external static bool logToConsole; + + // static Runtime: AbstractRuntime; + // static ScriptReceivers: any; + // static DependenciesReceivers: any; + // static auth_callbacks: any; + + external static void ready(); + + external static void log(JSAny? message); + + external static JSAny? get getClientFeatures; + + external String key; + + external Config config; + + external Channels channels; + + @JS('global_emitter') + external Dispatcher globalEmitter; + + @JS('sessionID') + external num sessionId; + + external Timeline timeline; + + external TimelineSender timelineSender; + + external ConnectionManager connection; + + external UserFacade user; + + external Channel? channel(String name); + + external JSArray allChannels(); + + external void connect(); + + external void disconnect(); + + external Pusher bind( + String eventName, + JSFunction callback, [ + JSAny? context, + ]); + + external Pusher unbind([ + String? eventName, + JSFunction? callback, + JSAny? context, + ]); + + @JS('bind_global') + external Pusher bindGlobal(JSFunction callback); + + @JS('unbind_global') + external Pusher unbindGlobal([JSFunction? callback]); + + @JS('unbind_all') + external void unbindAll([JSFunction? callback]); + + external void subscribeAll(); + + external Channel subscribe(String channelName); + + external void unsubscribe(String channelName); + + @JS('send_event') + external bool sendEvent( + String eventName, + JSAny? data, [ + String? channel, + ]); + + @JS('shouldUseTLS') + external bool shouldUseTls(); + + external void signin(); +} diff --git a/lib/wasm-pusher-js/core/socket.dart b/lib/wasm-pusher-js/core/socket.dart new file mode 100644 index 0000000..e3672f0 --- /dev/null +++ b/lib/wasm-pusher-js/core/socket.dart @@ -0,0 +1,26 @@ +import 'dart:js_interop'; + +abstract class Socket { + external void send(dynamic payload); + + external void Function()? ping; + + external dynamic close([dynamic code, dynamic reason]); + + external bool Function(dynamic payload)? sendRaw; + + @JS('onopen') + external void Function([dynamic evt])? onOpen; + + @JS('onerror') + external void Function(dynamic error)? onerror; + + @JS('onclose') + external void Function(dynamic closeEvent)? onclose; + + @JS('onmessage') + external void Function(dynamic message)? onMessage; + + @JS('onactivity') + external void Function()? onActivity; +} diff --git a/lib/wasm-pusher-js/core/strategies/strategy.dart b/lib/wasm-pusher-js/core/strategies/strategy.dart new file mode 100644 index 0000000..7b52e9d --- /dev/null +++ b/lib/wasm-pusher-js/core/strategies/strategy.dart @@ -0,0 +1,9 @@ +import 'dart:js_interop'; + +import 'strategy_runner.dart'; + +extension type Strategy._(JSObject _) implements JSObject { + external bool isSupported(); + + external StrategyRunner connect(num minPriority, JSFunction callback); +} diff --git a/lib/wasm-pusher-js/core/strategies/strategy_runner.dart b/lib/wasm-pusher-js/core/strategies/strategy_runner.dart new file mode 100644 index 0000000..d769aec --- /dev/null +++ b/lib/wasm-pusher-js/core/strategies/strategy_runner.dart @@ -0,0 +1,17 @@ +import 'dart:js_interop'; + +extension type StrategyRunnerForceMinPriorityFunction._(JSFunction _) + implements JSFunction { + void call(JSAny? number) => callAsFunction(null, number); +} + +extension type StrategyRunnerAbortFunction._(JSFunction _) + implements JSFunction { + void call() => callAsFunction(null); +} + +extension type StrategyRunner._(JSObject _) implements JSObject { + external StrategyRunnerForceMinPriorityFunction forceMinPriority; + + external StrategyRunnerAbortFunction abort; +} diff --git a/lib/wasm-pusher-js/core/timeline/level.dart b/lib/wasm-pusher-js/core/timeline/level.dart new file mode 100644 index 0000000..70da50b --- /dev/null +++ b/lib/wasm-pusher-js/core/timeline/level.dart @@ -0,0 +1,9 @@ +enum TimelineLevel { + error(3), + info(6), + debug(7); + + const TimelineLevel(this.value); + + final int value; +} diff --git a/lib/wasm-pusher-js/core/timeline/timeline.dart b/lib/wasm-pusher-js/core/timeline/timeline.dart new file mode 100644 index 0000000..1736728 --- /dev/null +++ b/lib/wasm-pusher-js/core/timeline/timeline.dart @@ -0,0 +1,60 @@ +import 'dart:js_interop'; + +extension type TimelineOptions._(JSObject _) implements JSObject { + external TimelineOptions({ + num? level, + num? limit, + String? version, + String? cluster, + JSArray? features, + JSAny? params, + }); + + external num? level; + + external num? limit; + + external String? version; + + external String? cluster; + + external JSArray? features; + + external JSAny? params; +} + +extension type Timeline._(JSObject _) implements JSObject { + external Timeline( + String key, + num session, + TimelineOptions options, + ); + + external String key; + + external num session; + + external JSArray events; + + external TimelineOptions options; + + external num sent; + + @JS('uniqueID') + external num uniqueId; + + external void log(JSAny? level, JSAny? event); + + external void error(JSAny? event); + + external void info(JSAny? event); + + external void debug(JSAny? event); + + external bool isEmpty(); + + external bool send(JSAny? sendfn, JSAny? callback); + + @JS('generateUniqueID') + external num generationUniqueId(); +} diff --git a/lib/wasm-pusher-js/core/timeline/timeline_sender.dart b/lib/wasm-pusher-js/core/timeline/timeline_sender.dart new file mode 100644 index 0000000..27c43d0 --- /dev/null +++ b/lib/wasm-pusher-js/core/timeline/timeline_sender.dart @@ -0,0 +1,32 @@ +import 'dart:js_interop'; + +import 'timeline.dart'; + +extension type TimelineSenderOptions._(JSObject _) implements JSObject { + external TimelineSenderOptions({ + String? host, + num? port, + String? path, + }); + + external String? host; + + external num? port; + + external String? path; +} + +extension type TimelineSender._(JSObject _) implements JSObject { + external TimelineSender({ + Timeline timeline, + TimelineSenderOptions options, + }); + + external Timeline timeline; + + external TimelineSenderOptions options; + + external String host; + + external void send(bool useTls, [JSFunction? callback]); +} diff --git a/lib/wasm-pusher-js/core/user.dart b/lib/wasm-pusher-js/core/user.dart new file mode 100644 index 0000000..5c9549b --- /dev/null +++ b/lib/wasm-pusher-js/core/user.dart @@ -0,0 +1,25 @@ +import 'dart:js_interop'; + +import 'channels/channel.dart'; +import 'events/dispatcher.dart'; +import 'pusher.dart'; + +extension type UserFacade._(Dispatcher _) implements Dispatcher { + external UserFacade({Pusher pusher}); + + external Pusher pusher; + + @JS('signin_requested') + external bool signinRequested; + + @JS('user_data') + external JSAny? userData; + + external Channel serverToUserChannel; + + external JSPromise signinDonePromise; + + // external WatchlistFacade watchlist; + + external void signin(); +} diff --git a/lib/wasm-pusher-js/error.dart b/lib/wasm-pusher-js/error.dart new file mode 100644 index 0000000..f922745 --- /dev/null +++ b/lib/wasm-pusher-js/error.dart @@ -0,0 +1,30 @@ +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; + +@JS('Error') +external JSErrorConstructor get _jsErrorConstructor; + +extension type JSErrorConstructor._(JSFunction _) implements JSFunction { + JSError call({String message = '', StackTrace? stackTrace}) { + final wrapper = callAsConstructor(message.toJS); + if (stackTrace != null) { + wrapper['stack'] = stackTrace.toString().toJS; + } + return wrapper; + } +} + +extension type JSError._(JSObject _) implements JSObject { + static JSError create({String message = '', StackTrace? stackTrace}) { + return _jsErrorConstructor( + message: message, + stackTrace: stackTrace, + ); + } + + external String get name; + + external String get message; + + external String? get stack; +} From 68fcf3cfb89c69215132381b17e1b735f5ad0e3f Mon Sep 17 00:00:00 2001 From: JimmyTai Date: Thu, 6 Mar 2025 23:37:05 +0800 Subject: [PATCH 3/3] Remove pusher-js legacy. --- example/pubspec.lock | 10 +- lib/pusher-js/core/auth/auth_transports.dart | 14 - .../auth/deprecated_channel_authorizer.dart | 0 lib/pusher-js/core/auth/options.dart | 173 ++++++---- .../core/auth/pusher_authorizer.dart | 28 -- .../core/channels.dart | 0 lib/pusher-js/core/channels/channel.dart | 93 +++--- .../core/channels/channel_table.dart | 15 +- lib/pusher-js/core/channels/channels.dart | 35 -- .../core/channels/encrypted_channel.dart | 34 -- lib/pusher-js/core/channels/members.dart | 44 +-- lib/pusher-js/core/channels/metadata.dart | 18 +- .../core/channels/presence_channel.dart | 55 ++-- .../core/channels/private_channel.dart | 24 +- lib/pusher-js/core/config.dart | 178 ++++------ lib/pusher-js/core/connection/callbacks.dart | 55 ---- lib/pusher-js/core/connection/connection.dart | 75 ++--- .../core/connection/connection_manager.dart | 169 ++++------ .../connection_manager_options.dart | 47 +-- lib/pusher-js/core/connection/handshake.dart | 36 --- .../handshake/handshake_payload.dart | 25 -- .../core/connection/protocol/action.dart | 21 -- .../connection/protocol/message-types.dart | 21 -- .../connection/protocol/message_types.dart | 0 .../core/connection/protocol/protocol.dart | 10 - lib/pusher-js/core/defaults.dart | 75 ----- lib/pusher-js/core/errors.dart | 48 --- lib/pusher-js/core/events/callback.dart | 17 +- .../core/events/callback_registry.dart | 35 +- lib/pusher-js/core/events/callback_table.dart | 15 +- lib/pusher-js/core/events/dispatcher.dart | 56 ++-- lib/pusher-js/core/http/ajax.dart | 35 -- lib/pusher-js/core/http/http_factory.dart | 22 -- .../core/http/http_polling_socket.dart | 11 - lib/pusher-js/core/http/http_request.dart | 34 -- lib/pusher-js/core/http/http_socket.dart | 65 ---- .../core/http/http_streaming_socket.dart | 11 - lib/pusher-js/core/http/request_hooks.dart | 16 - lib/pusher-js/core/http/socket_hooks.dart | 18 -- lib/pusher-js/core/http/state.dart | 13 - lib/pusher-js/core/http/url_location.dart | 16 - lib/pusher-js/core/logger.dart | 40 --- lib/pusher-js/core/options.dart | 183 +++++------ lib/pusher-js/core/pusher.dart | 173 +++++----- .../core/pusher_with_encryption.dart | 13 - lib/pusher-js/core/reachability.dart | 13 - lib/pusher-js/core/socket.dart | 38 ++- .../best_connected_ever_strategy.dart | 32 -- .../core/strategies/cached_strategy.dart | 47 --- .../core/strategies/delayed_strategy.dart | 24 -- .../strategies/first_connected_strategy.dart | 20 -- .../core/strategies/if_strategy.dart | 25 -- .../core/strategies/sequential_strategy.dart | 35 -- lib/pusher-js/core/strategies/strategy.dart | 15 +- .../core/strategies/strategy_options.dart | 49 --- .../core/strategies/strategy_runner.dart | 26 +- .../core/strategies/transport_strategy.dart | 35 -- lib/pusher-js/core/timeline/level.dart | 18 +- lib/pusher-js/core/timeline/timeline.dart | 107 +++--- .../core/timeline/timeline_sender.dart | 56 ++-- .../core/timeline/timeline_transport.dart | 22 -- .../assistant_to_the_transport_manager.dart | 43 --- .../core/transports/ping_delay_options.dart | 19 -- lib/pusher-js/core/transports/transport.dart | 30 -- .../core/transports/transport_connection.dart | 85 ----- .../transport_connection_options.dart | 18 -- .../core/transports/transport_hooks.dart | 26 -- .../core/transports/transport_manager.dart | 42 --- .../core/transports/transports_table.dart | 33 -- lib/pusher-js/core/transports/url_scheme.dart | 28 -- .../core/transports/url_schemes.dart | 23 -- .../core/user.dart | 0 lib/pusher-js/core/util.dart | 11 - lib/pusher-js/core/utils/collections.dart | 119 ------- lib/pusher-js/core/utils/factory.dart | 11 - lib/pusher-js/core/utils/timers.dart | 24 -- .../core/utils/timers/abstract_timer.dart | 24 -- .../core/utils/timers/scheduling.dart | 9 - .../core/utils/timers/timed_callback.dart | 7 - lib/pusher-js/core/utils/url_store.dart | 12 - lib/{wasm-pusher-js => pusher-js}/error.dart | 0 lib/pusher-js/runtimes/interface.dart | 70 ---- .../runtimes/isomorphic/auth/xhr_auth.dart | 11 - .../runtimes/isomorphic/default_strategy.dart | 13 - .../runtimes/isomorphic/http/http.dart | 13 - .../isomorphic/http/http_xhr_request.dart | 11 - .../runtimes/isomorphic/runtime.dart | 12 - .../isomorphic/timeline/xhr_timeline.dart | 13 - .../isomorphic/transports/transports.dart | 48 --- lib/pusher-js/runtimes/node/net_info.dart | 19 -- .../runtimes/react-native/net_info.dart | 25 -- .../runtimes/web/auth/jsonp_auth.dart | 11 - lib/pusher-js/runtimes/web/browser.dart | 42 --- .../runtimes/web/default_strategy.dart | 13 - .../runtimes/web/dom/dependencies.dart | 15 - .../runtimes/web/dom/dependency_loader.dart | 35 -- .../runtimes/web/dom/jsonp_request.dart | 31 -- .../runtimes/web/dom/script_receiver.dart | 21 -- .../web/dom/script_receiver_factory.dart | 34 -- .../runtimes/web/dom/script_request.dart | 25 -- lib/pusher-js/runtimes/web/http/http.dart | 5 - .../web/http/http_xdomain_request.dart | 11 - lib/pusher-js/runtimes/web/net_info.dart | 29 -- lib/pusher-js/runtimes/web/runtime.dart | 13 - .../runtimes/web/timeline/jsonp_timeline.dart | 13 - .../runtimes/web/transports/transports.dart | 28 -- .../runtimes/worker/auth/fetch_auth.dart | 11 - lib/pusher-js/runtimes/worker/net_info.dart | 20 -- .../worker/timeline/fetch_timeline.dart | 14 - lib/pusher_channels_flutter_wasm.dart | 306 ------------------ lib/pusher_channels_flutter_web.dart | 134 +++++--- lib/wasm-pusher-js/core/auth/options.dart | 122 ------- lib/wasm-pusher-js/core/channels/channel.dart | 43 --- .../core/channels/channel_table.dart | 9 - lib/wasm-pusher-js/core/channels/members.dart | 24 -- .../core/channels/metadata.dart | 6 - .../core/channels/presence_channel.dart | 25 -- .../core/channels/private_channel.dart | 13 - lib/wasm-pusher-js/core/config.dart | 57 ---- .../core/connection/connection.dart | 31 -- .../core/connection/connection_manager.dart | 65 ---- .../connection_manager_options.dart | 19 -- lib/wasm-pusher-js/core/events/callback.dart | 7 - .../core/events/callback_registry.dart | 17 - .../core/events/callback_table.dart | 9 - .../core/events/dispatcher.dart | 32 -- lib/wasm-pusher-js/core/options.dart | 94 ------ lib/wasm-pusher-js/core/pusher.dart | 100 ------ lib/wasm-pusher-js/core/socket.dart | 26 -- .../core/strategies/strategy.dart | 9 - .../core/strategies/strategy_runner.dart | 17 - lib/wasm-pusher-js/core/timeline/level.dart | 9 - .../core/timeline/timeline.dart | 60 ---- .../core/timeline/timeline_sender.dart | 32 -- pubspec.lock | 8 - pubspec.yaml | 2 +- 136 files changed, 817 insertions(+), 4267 deletions(-) delete mode 100644 lib/pusher-js/core/auth/auth_transports.dart rename lib/{wasm-pusher-js => pusher-js}/core/auth/deprecated_channel_authorizer.dart (100%) delete mode 100644 lib/pusher-js/core/auth/pusher_authorizer.dart rename lib/{wasm-pusher-js => pusher-js}/core/channels.dart (100%) delete mode 100644 lib/pusher-js/core/channels/channels.dart delete mode 100644 lib/pusher-js/core/channels/encrypted_channel.dart delete mode 100644 lib/pusher-js/core/connection/callbacks.dart delete mode 100644 lib/pusher-js/core/connection/handshake.dart delete mode 100644 lib/pusher-js/core/connection/handshake/handshake_payload.dart delete mode 100644 lib/pusher-js/core/connection/protocol/action.dart delete mode 100644 lib/pusher-js/core/connection/protocol/message-types.dart rename lib/{wasm-pusher-js => pusher-js}/core/connection/protocol/message_types.dart (100%) delete mode 100644 lib/pusher-js/core/connection/protocol/protocol.dart delete mode 100644 lib/pusher-js/core/defaults.dart delete mode 100644 lib/pusher-js/core/errors.dart delete mode 100644 lib/pusher-js/core/http/ajax.dart delete mode 100644 lib/pusher-js/core/http/http_factory.dart delete mode 100644 lib/pusher-js/core/http/http_polling_socket.dart delete mode 100644 lib/pusher-js/core/http/http_request.dart delete mode 100644 lib/pusher-js/core/http/http_socket.dart delete mode 100644 lib/pusher-js/core/http/http_streaming_socket.dart delete mode 100644 lib/pusher-js/core/http/request_hooks.dart delete mode 100644 lib/pusher-js/core/http/socket_hooks.dart delete mode 100644 lib/pusher-js/core/http/state.dart delete mode 100644 lib/pusher-js/core/http/url_location.dart delete mode 100644 lib/pusher-js/core/logger.dart delete mode 100644 lib/pusher-js/core/pusher_with_encryption.dart delete mode 100644 lib/pusher-js/core/reachability.dart delete mode 100644 lib/pusher-js/core/strategies/best_connected_ever_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/cached_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/delayed_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/first_connected_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/if_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/sequential_strategy.dart delete mode 100644 lib/pusher-js/core/strategies/strategy_options.dart delete mode 100644 lib/pusher-js/core/strategies/transport_strategy.dart delete mode 100644 lib/pusher-js/core/timeline/timeline_transport.dart delete mode 100644 lib/pusher-js/core/transports/assistant_to_the_transport_manager.dart delete mode 100644 lib/pusher-js/core/transports/ping_delay_options.dart delete mode 100644 lib/pusher-js/core/transports/transport.dart delete mode 100644 lib/pusher-js/core/transports/transport_connection.dart delete mode 100644 lib/pusher-js/core/transports/transport_connection_options.dart delete mode 100644 lib/pusher-js/core/transports/transport_hooks.dart delete mode 100644 lib/pusher-js/core/transports/transport_manager.dart delete mode 100644 lib/pusher-js/core/transports/transports_table.dart delete mode 100644 lib/pusher-js/core/transports/url_scheme.dart delete mode 100644 lib/pusher-js/core/transports/url_schemes.dart rename lib/{wasm-pusher-js => pusher-js}/core/user.dart (100%) delete mode 100644 lib/pusher-js/core/util.dart delete mode 100644 lib/pusher-js/core/utils/collections.dart delete mode 100644 lib/pusher-js/core/utils/factory.dart delete mode 100644 lib/pusher-js/core/utils/timers.dart delete mode 100644 lib/pusher-js/core/utils/timers/abstract_timer.dart delete mode 100644 lib/pusher-js/core/utils/timers/scheduling.dart delete mode 100644 lib/pusher-js/core/utils/timers/timed_callback.dart delete mode 100644 lib/pusher-js/core/utils/url_store.dart rename lib/{wasm-pusher-js => pusher-js}/error.dart (100%) delete mode 100644 lib/pusher-js/runtimes/interface.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/auth/xhr_auth.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/default_strategy.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/http/http.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/http/http_xhr_request.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/runtime.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/timeline/xhr_timeline.dart delete mode 100644 lib/pusher-js/runtimes/isomorphic/transports/transports.dart delete mode 100644 lib/pusher-js/runtimes/node/net_info.dart delete mode 100644 lib/pusher-js/runtimes/react-native/net_info.dart delete mode 100644 lib/pusher-js/runtimes/web/auth/jsonp_auth.dart delete mode 100644 lib/pusher-js/runtimes/web/browser.dart delete mode 100644 lib/pusher-js/runtimes/web/default_strategy.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/dependencies.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/dependency_loader.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/jsonp_request.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/script_receiver.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/script_receiver_factory.dart delete mode 100644 lib/pusher-js/runtimes/web/dom/script_request.dart delete mode 100644 lib/pusher-js/runtimes/web/http/http.dart delete mode 100644 lib/pusher-js/runtimes/web/http/http_xdomain_request.dart delete mode 100644 lib/pusher-js/runtimes/web/net_info.dart delete mode 100644 lib/pusher-js/runtimes/web/runtime.dart delete mode 100644 lib/pusher-js/runtimes/web/timeline/jsonp_timeline.dart delete mode 100644 lib/pusher-js/runtimes/web/transports/transports.dart delete mode 100644 lib/pusher-js/runtimes/worker/auth/fetch_auth.dart delete mode 100644 lib/pusher-js/runtimes/worker/net_info.dart delete mode 100644 lib/pusher-js/runtimes/worker/timeline/fetch_timeline.dart delete mode 100644 lib/pusher_channels_flutter_wasm.dart delete mode 100644 lib/wasm-pusher-js/core/auth/options.dart delete mode 100644 lib/wasm-pusher-js/core/channels/channel.dart delete mode 100644 lib/wasm-pusher-js/core/channels/channel_table.dart delete mode 100644 lib/wasm-pusher-js/core/channels/members.dart delete mode 100644 lib/wasm-pusher-js/core/channels/metadata.dart delete mode 100644 lib/wasm-pusher-js/core/channels/presence_channel.dart delete mode 100644 lib/wasm-pusher-js/core/channels/private_channel.dart delete mode 100644 lib/wasm-pusher-js/core/config.dart delete mode 100644 lib/wasm-pusher-js/core/connection/connection.dart delete mode 100644 lib/wasm-pusher-js/core/connection/connection_manager.dart delete mode 100644 lib/wasm-pusher-js/core/connection/connection_manager_options.dart delete mode 100644 lib/wasm-pusher-js/core/events/callback.dart delete mode 100644 lib/wasm-pusher-js/core/events/callback_registry.dart delete mode 100644 lib/wasm-pusher-js/core/events/callback_table.dart delete mode 100644 lib/wasm-pusher-js/core/events/dispatcher.dart delete mode 100644 lib/wasm-pusher-js/core/options.dart delete mode 100644 lib/wasm-pusher-js/core/pusher.dart delete mode 100644 lib/wasm-pusher-js/core/socket.dart delete mode 100644 lib/wasm-pusher-js/core/strategies/strategy.dart delete mode 100644 lib/wasm-pusher-js/core/strategies/strategy_runner.dart delete mode 100644 lib/wasm-pusher-js/core/timeline/level.dart delete mode 100644 lib/wasm-pusher-js/core/timeline/timeline.dart delete mode 100644 lib/wasm-pusher-js/core/timeline/timeline_sender.dart diff --git a/example/pubspec.lock b/example/pubspec.lock index b79d5c5..df33e75 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -96,14 +96,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive - description: - name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf - url: "https://pub.dev" - source: hosted - version: "0.7.1" leak_tracker: dependency: transitive description: @@ -214,7 +206,7 @@ packages: path: ".." relative: true source: path - version: "2.4.0" + version: "2.5.0" shared_preferences: dependency: "direct main" description: diff --git a/lib/pusher-js/core/auth/auth_transports.dart b/lib/pusher-js/core/auth/auth_transports.dart deleted file mode 100644 index 0ec69bb..0000000 --- a/lib/pusher-js/core/auth/auth_transports.dart +++ /dev/null @@ -1,14 +0,0 @@ -@JS() -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); - -// @anonymous -// @JS() -// abstract class AuthTransports { - -// } diff --git a/lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart b/lib/pusher-js/core/auth/deprecated_channel_authorizer.dart similarity index 100% rename from lib/wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart rename to lib/pusher-js/core/auth/deprecated_channel_authorizer.dart diff --git a/lib/pusher-js/core/auth/options.dart b/lib/pusher-js/core/auth/options.dart index 99956e5..40d3e58 100644 --- a/lib/pusher-js/core/auth/options.dart +++ b/lib/pusher-js/core/auth/options.dart @@ -1,89 +1,122 @@ -// ignore_for_file: non_constant_identifier_names +import 'dart:js_interop'; -@JS() -library core.auth.options; +import '../../error.dart'; -import "package:js/js.dart"; -import "../channels/channel.dart" show Channel; +extension type ChannelAuthorizationData._(JSObject _) implements JSObject { + static ChannelAuthorizationData create({ + required String auth, + String? channelData, + String? sharedSecret, + }) { + return (JSObject() as ChannelAuthorizationData) + ..auth = auth + ..channelData = channelData + ..sharedSecret = sharedSecret; + } -@anonymous -@JS() -abstract class AuthOptions { - external Map get params; - external set params(Map v); - external Map get headers; - external set headers(Map v); + external String auth; - external factory AuthOptions({ - Map params, - Map headers, - }); + @JS('channel_data') + external String? channelData; + + @JS('shared_secret') + external String? sharedSecret; } -extension AuthOptionsExt on AuthOptions { - Map toMap() => { - 'params': params, - 'headers': headers, - }; +extension type ChannelAuthorizationCallback._(JSFunction _) + implements JSFunction { + void call( + JSError? error, + ChannelAuthorizationData? authData, + ) => + callAsFunction(null, error, authData); } -@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, +extension type ChannelAuthorizationRequestParams._(JSObject _) + implements JSObject { + external ChannelAuthorizationRequestParams({ + String socketId, + String channelName, }); + + external String socketId; + + external String channelName; +} + +typedef DartChannelAuthorizationHandler = void Function( + ChannelAuthorizationRequestParams params, + ChannelAuthorizationCallback callback, +); + +extension type ChannelAuthorizationHandler._(JSFunction _) + implements JSFunction { + static ChannelAuthorizationHandler create( + DartChannelAuthorizationHandler handler, + ) => + handler.toJS as ChannelAuthorizationHandler; } -typedef AuthorizerCallback = void Function(Error? error, AuthData authData); +extension type UserAuthenticationData._(JSObject _) implements JSObject { + static UserAuthenticationData create({ + required String auth, + required String userData, + }) { + return (JSObject() as UserAuthenticationData) + ..auth = auth + ..userData = userData; + } -typedef AuthorizeFunc = void Function( - String socketId, AuthorizerCallback callback); + external String auth; -@anonymous -@JS() -abstract class Authorizer { - external set authorize(AuthorizeFunc v); - external AuthorizeFunc get authorize; + @JS('user_data') + external String userData; +} - external factory Authorizer({AuthorizeFunc authorize}); +extension type UserAuthenticationCallback._(JSFunction _) + implements JSFunction { + void call( + JSError? error, + UserAuthenticationData? authData, + ) => + callAsFunction(null, error, authData); } -typedef AuthorizerGenerator = Authorizer Function( - Channel channel, AuthorizerOptions options); - -@anonymous -@JS() -abstract class AuthorizerOptions { - external String /*'ajax'|'jsonp'*/ get authTransport; - 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, - }); +extension type UserAuthenticationRequestParams._(JSObject _) + implements JSObject { + external String socketId; +} + +typedef DartUserAuthenticationHandler = void Function( + UserAuthenticationRequestParams params, + UserAuthenticationCallback callback, +); + +extension type UserAuthenticationHandler._(JSFunction _) implements JSFunction { + static UserAuthenticationHandler create( + DartUserAuthenticationHandler handler, + ) => + handler.toJS as UserAuthenticationHandler; } -extension AuthorizerOptionsExt on AuthorizerOptions { - Map toMap() => { - 'authTransport': authTransport, - 'authEndpoint': authEndpoint, - 'auth': auth?.toMap(), - }; +typedef UserAuthenticationOptions = AuthOptionsT; + +typedef ChannelAuthorizationOptions = AuthOptionsT; + +extension type AuthOptionsT._(JSObject _) + implements JSObject { + // Allow 'ajax' | 'jsonp' + external String transport; + + external String endpoint; + + external JSAny params; + + external JSAny headers; + + external JSFunction? paramsProvider; + + external JSFunction? headersProvider; + + external AuthHandler? customHandler; } diff --git a/lib/pusher-js/core/auth/pusher_authorizer.dart b/lib/pusher-js/core/auth/pusher_authorizer.dart deleted file mode 100644 index 5efe02e..0000000 --- a/lib/pusher-js/core/auth/pusher_authorizer.dart +++ /dev/null @@ -1,28 +0,0 @@ -@JS() -library core.auth.pusher_authorizer; - -import "package:js/js.dart"; -import "options.dart" show Authorizer, AuthorizerOptions, AuthOptions; -import "auth_transports.dart" show AuthTransport; -import "../channels/channel.dart" show Channel; - -@JS() -abstract class PusherAuthorizer implements Authorizer { - external static Map get authorizers; - - external Channel get channel; - external set channel(Channel v); - external String get type; - external set type(String v); - external AuthorizerOptions get options; - external set options(AuthorizerOptions v); - external AuthOptions get authOptions; - external set authOptions(AuthOptions v); - - external String composeQuery(String socketId); - - external factory PusherAuthorizer({ - Channel channel, - AuthorizerOptions options, - }); -} diff --git a/lib/wasm-pusher-js/core/channels.dart b/lib/pusher-js/core/channels.dart similarity index 100% rename from lib/wasm-pusher-js/core/channels.dart rename to lib/pusher-js/core/channels.dart diff --git a/lib/pusher-js/core/channels/channel.dart b/lib/pusher-js/core/channels/channel.dart index 9a725f4..3c17bd1 100644 --- a/lib/pusher-js/core/channels/channel.dart +++ b/lib/pusher-js/core/channels/channel.dart @@ -1,52 +1,43 @@ -@JS() -library core.channels.channel; - -import "package:js/js.dart"; -import "../events/dispatcher.dart" show Dispatcher; -import "../pusher.dart" show Pusher; -import "../auth/options.dart" show AuthorizerCallback; -import "../connection/protocol/message-types.dart" show PusherEvent; - -/// Provides base public channel interface with an event emitter. -/// Emits: -/// - pusher:subscription_succeeded - after subscribing successfully -/// - other non-internal events -@JS() -class Channel extends Dispatcher { - external String get name; - external set name(String v); - external Pusher get pusher; - external set pusher(Pusher v); - external bool get subscribed; - external set subscribed(bool v); - external bool get subscriptionPending; - external set subscriptionPending(bool v); - external bool get subscriptionCancelled; - external set subscriptionCancelled(bool v); - external factory Channel(String name, Pusher pusher); - - /// Skips authorization, since public channels don't require it. - external authorize(String socketId, AuthorizerCallback callback); - - /// Triggers an event - external trigger(String event, dynamic data); - - /// Signals disconnection to the channel. For internal use only. - external disconnect(); - - /// Handles a PusherEvent. For internal use only. - external handleEvent(PusherEvent event); - external handleSubscriptionSucceededEvent(PusherEvent event); - - /// Sends a subscription request. For internal use only. - external subscribe(); - - /// Sends an unsubscription request. For internal use only. - external unsubscribe(); - - /// Cancels an in progress subscription. For internal use only. - external cancelSubscription(); - - /// Reinstates an in progress subscripiton. For internal use only. - external reinstateSubscription(); +import 'dart:js_interop'; + +import '../auth/options.dart'; +import '../connection/protocol/message_types.dart'; +import '../events/dispatcher.dart'; +import '../pusher.dart'; + +extension type Channel._(Dispatcher _) implements Dispatcher { + external Channel(String name, Pusher pusher); + + external String name; + + external Pusher pusher; + + external bool subscribed; + + external bool subscriptionPending; + + external bool subscriptionCancelled; + + external void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ); + + external bool trigger(String event, [JSAny data]); + + external void disconnect(); + + external void handleEvent(PusherEvent event); + + external void handleSubscriptionSucceededEvent(PusherEvent event); + + external void handleSubscriptionCountEvent(PusherEvent event); + + external void subscribe(); + + external void unsubscribe(); + + external void cancelSubscription(); + + external void reinstateSubscription(); } diff --git a/lib/pusher-js/core/channels/channel_table.dart b/lib/pusher-js/core/channels/channel_table.dart index 464e8c7..df67cf5 100644 --- a/lib/pusher-js/core/channels/channel_table.dart +++ b/lib/pusher-js/core/channels/channel_table.dart @@ -1,12 +1,9 @@ -@JS() -library core.channels.channel_table; +import 'dart:js_interop'; -import "package:js/js.dart"; +import 'channel.dart'; -@anonymous -@JS() -abstract class ChannelTable { - /* Index signature is not yet supported by JavaScript interop. */ -} +extension type ChannelTable._(JSObject _) implements JSObject { + external Channel? operator [](String index); -/* WARNING: export assignment not yet supported. */ + external void operator []=(String index, Channel value); +} diff --git a/lib/pusher-js/core/channels/channels.dart b/lib/pusher-js/core/channels/channels.dart deleted file mode 100644 index 2e14d6c..0000000 --- a/lib/pusher-js/core/channels/channels.dart +++ /dev/null @@ -1,35 +0,0 @@ -@JS() -library core.channels.channels; - -import "package:js/js.dart"; -import "channel_table.dart" show ChannelTable; -import "../pusher.dart" show Pusher; -import "channel.dart" show Channel; - -/// Handles a channel map. -@JS() -class Channels { - // @Ignore - // Channels.fakeConstructor$(); - external ChannelTable get channels; - external set channels(ChannelTable v); - external factory Channels(); - - /// Creates or retrieves an existing channel by its name. - external add(String name, Pusher pusher); - - /// Returns a list of all channels - external List all(); - - /// Finds a channel by its name. - external find(String name); - - /// Removes a channel from the map. - external remove(String name); - - /// Proxies disconnection signal to all channels. - external disconnect(); -} - -@JS() -external Channel createChannel(String name, Pusher pusher); diff --git a/lib/pusher-js/core/channels/encrypted_channel.dart b/lib/pusher-js/core/channels/encrypted_channel.dart deleted file mode 100644 index 3f29a38..0000000 --- a/lib/pusher-js/core/channels/encrypted_channel.dart +++ /dev/null @@ -1,34 +0,0 @@ -@JS() -library core.channels.encrypted_channel; - -import "package:js/js.dart"; -import "dart:typed_data"; -import "private_channel.dart" show PrivateChannel; -import "../pusher.dart" show Pusher; -import "../auth/options.dart" show AuthorizerCallback; -import "../connection/protocol/message-types.dart" show PusherEvent; - -/// Extends private channels to provide encrypted channel interface. -@JS() -class EncryptedChannel extends PrivateChannel { - external Uint8List get key; - external set key(Uint8List v); - external dynamic get nacl; - external set nacl(dynamic v); - external factory EncryptedChannel(String name, Pusher pusher, dynamic nacl); - - /// Authorizes the connection to use the channel. - @override - external authorize(String socketId, AuthorizerCallback callback); - @override - external bool trigger(String event, dynamic data); - - /// Handles an event. For internal use only. - @override - external handleEvent(PusherEvent event); - external void handleEncryptedEvent(String event, dynamic data); - - /// Try and parse the decrypted bytes as JSON. If we can't parse it, just - /// return the utf-8 string - external String getDataToEmit(Uint8List bytes); -} diff --git a/lib/pusher-js/core/channels/members.dart b/lib/pusher-js/core/channels/members.dart index a129173..7b9dfcb 100644 --- a/lib/pusher-js/core/channels/members.dart +++ b/lib/pusher-js/core/channels/members.dart @@ -1,40 +1,24 @@ -@JS() -library core.channels.members; +import 'dart:js_interop'; -import "package:js/js.dart"; +extension type Members._(JSObject _) implements JSObject { + external Members(); -/// Represents a collection of members of a presence channel. -@JS() -class Members { - external dynamic get members; - external set members(dynamic v); - external num get count; - external set count(num v); - external dynamic get myID; - external set myID(dynamic v); - external dynamic get me; - external set me(dynamic v); - external factory Members(); + external JSAny members; - /// Returns member's info for given id. - /// Resulting object containts two fields - id and info. - external dynamic get(String id); + external num count; - /// Calls back for each member in unspecified order. - external each(Function callback); + @JS('myID') + external JSAny myId; - /// Updates the id for connected member. For internal use only. - external setMyID(String id); + external JSAny get(String id); - /// Handles subscription data. For internal use only. - external onSubscription(dynamic subscriptionData); + external void each(JSFunction callback); - /// Adds a new member to the collection. For internal use only. - external addMember(dynamic memberData); + external void onSubscription(JSAny subscriptionData); - /// Adds a member from the collection. For internal use only. - external removeMember(dynamic memberData); + external JSAny addMember(JSAny memberData); - /// Resets the collection to the initial state. For internal use only. - external reset(); + external JSAny removeMember(JSAny memberData); + + external void reset(); } diff --git a/lib/pusher-js/core/channels/metadata.dart b/lib/pusher-js/core/channels/metadata.dart index ccd5c05..a261dec 100644 --- a/lib/pusher-js/core/channels/metadata.dart +++ b/lib/pusher-js/core/channels/metadata.dart @@ -1,16 +1,6 @@ -// ignore_for_file: non_constant_identifier_names +import 'dart:js_interop'; -@JS() -library core.channels.metadata; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class Metadata { - external String get user_id; - external set user_id(String v); - external factory Metadata({String user_id}); +extension type Metadata._(JSObject _) implements JSObject { + @JS('user_id') + external String? userId; } - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/channels/presence_channel.dart b/lib/pusher-js/core/channels/presence_channel.dart index ca441cc..8a34e3d 100644 --- a/lib/pusher-js/core/channels/presence_channel.dart +++ b/lib/pusher-js/core/channels/presence_channel.dart @@ -1,32 +1,25 @@ -@JS() -library core.channels.presence_channel; - -import "package:js/js.dart"; -import "private_channel.dart" show PrivateChannel; -import "members.dart" show Members; -import "../pusher.dart" show Pusher; -import "../connection/protocol/message-types.dart" show PusherEvent; - -@JS() -class PresenceChannel extends PrivateChannel { - external Members get members; - external set members(Members v); - - /// Adds presence channel functionality to private channels. - external factory PresenceChannel(String name, Pusher pusher); - - /// Authenticates the connection as a member of the channel. - @override - external authorize(String socketId, Function callback); - - /// Handles presence and subscription events. For internal use only. - @override - external handleEvent(PusherEvent event); - external handleInternalEvent(PusherEvent event); - @override - external handleSubscriptionSucceededEvent(PusherEvent event); - - /// Resets the channel state, including members map. For internal use only. - @override - external disconnect(); +import 'dart:js_interop'; + +import '../connection/protocol/message_types.dart'; +import '../pusher.dart'; +import 'members.dart'; +import 'private_channel.dart'; + +extension type PresenceChannel._(PrivateChannel _) implements PrivateChannel { + external PresenceChannel({ + String name, + Pusher pusher, + }); + + external Members members; + + external void authorize(String socketId, JSFunction callback); + + external void handleEvent(PusherEvent event); + + external void handleInternalEvent(PusherEvent event); + + external void handleSubscriptionSucceededEvent(PusherEvent event); + + external void disconnect(); } diff --git a/lib/pusher-js/core/channels/private_channel.dart b/lib/pusher-js/core/channels/private_channel.dart index a795c0a..12bf822 100644 --- a/lib/pusher-js/core/channels/private_channel.dart +++ b/lib/pusher-js/core/channels/private_channel.dart @@ -1,17 +1,13 @@ -@JS() -library core.channels.private_channel; +// export default class PrivateChannel extends Channel { +// authorize(socketId: string, callback: ChannelAuthorizationCallback): void; +// } -import "package:js/js.dart"; -import 'package:pusher_channels_flutter/pusher-js/core/pusher.dart'; -import "channel.dart" show Channel; -import "../auth/options.dart" show AuthorizerCallback; +import '../auth/options.dart'; +import 'channel.dart'; -/// Extends public channels to provide private channel interface. -@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); +extension type PrivateChannel._(Channel _) implements Channel { + external void authorize( + String socketId, + ChannelAuthorizationCallback callback, + ); } diff --git a/lib/pusher-js/core/config.dart b/lib/pusher-js/core/config.dart index 3e82932..6338628 100644 --- a/lib/pusher-js/core/config.dart +++ b/lib/pusher-js/core/config.dart @@ -1,123 +1,57 @@ -@JS() -library core.config; - -import "package:js/js.dart"; -import "auth/options.dart" show AuthOptions, AuthorizerGenerator; -import "options.dart" show Options; - -/*export type AuthTransport = 'ajax' | 'jsonp';*/ -/*export type Transport = - | 'ws' - | 'wss' - | 'xhr_streaming' - | 'xhr_polling' - | 'sockjs'; -*/ -@anonymous -@JS() -abstract class Config { - /// these are all 'required' config parameters, it's not necessary for the user - /// to set them, but they have configured defaults. - external num get activityTimeout; - external set activityTimeout(num v); - external String get authEndpoint; - external set authEndpoint(String v); - external String /*'ajax'|'jsonp'*/ get authTransport; - external set authTransport(String /*'ajax'|'jsonp'*/ v); - external bool get enableStats; - external set enableStats(bool v); - external String get httpHost; - external set httpHost(String v); - external String get httpPath; - external set httpPath(String v); - external num get httpPort; - external set httpPort(num v); - external num get httpsPort; - external set httpsPort(num v); - external num get pongTimeout; - external set pongTimeout(num v); - external String get statsHost; - external set statsHost(String v); - external num get unavailableTimeout; - external set unavailableTimeout(num v); - external bool get useTLS; - external set useTLS(bool v); - external String get wsHost; - external set wsHost(String v); - external String get wsPath; - external set wsPath(String v); - external num get wsPort; - external set wsPort(num v); - external num get wssPort; - external set wssPort(num v); - - /// these are all optional parameters or overrrides. The customer can set these - /// but it's not strictly necessary - external bool get forceTLS; - external set forceTLS(bool v); - external AuthOptions get auth; - external set auth(AuthOptions v); - external AuthorizerGenerator get authorizer; - external set authorizer(AuthorizerGenerator v); - external String get cluster; - external set cluster(String v); - external List - get disabledTransports; - external set disabledTransports( - List v); - external List - get enabledTransports; - external set enabledTransports( - List v); - external bool get ignoreNullOrigin; - external set ignoreNullOrigin(bool v); -// external nacl get nacl; -// external set nacl(nacl v); - external dynamic get timelineParams; - external set timelineParams(dynamic v); - external factory Config( - {num activityTimeout, - String authEndpoint, - String /*'ajax'|'jsonp'*/ authTransport, - bool enableStats, - String httpHost, - String httpPath, - num httpPort, - num httpsPort, - num pongTimeout, - String statsHost, - num unavailableTimeout, - bool useTLS, - String wsHost, - String wsPath, - num wsPort, - num wssPort, - bool forceTLS, - AuthOptions auth, - AuthorizerGenerator authorizer, - String cluster, - List - disabledTransports, - List - enabledTransports, - bool ignoreNullOrigin, -// nacl nacl, - dynamic timelineParams}); -} +import 'dart:js_interop'; + +/// Allow 'ajax' | 'jsonp' +typedef AuthTransport = JSString; + +/// Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' +typedef Transport = JSString; + +extension type Config._(JSObject _) implements JSObject { + external num activityTimeout; + + external bool enableStats; + + external String httpHost; + + external String httpPath; + + external num httpPort; + + external num httpsPort; + + external num pongTimeout; + + external String statsHost; + + external num unavailableTimeout; + + @JS('useTLS') + external bool useTls; -@JS() -external Config getConfig(Options opts); -@JS() -external String getHttpHost(Options opts); -@JS() -external String getWebsocketHost(Options opts); -@JS() -external String getWebsocketHostFromCluster(String cluster); -@JS() -external bool shouldUseTLS(Options opts); - -/// if enableStats is set take the value -/// if disableStats is set take the inverse -/// otherwise default to false -@JS() -external bool getEnableStatsConfig(Options opts); + external String wsHost; + + external String wsPath; + + external num wsPort; + + external num wssPort; + + external JSFunction userAuthenticator; + + external JSFunction channelAuthorizer; + + @JS('forceTLS') + external bool? forceTls; + + external String? cluster; + + external JSArray? disabledTransports; + + external JSArray? enabledTransports; + + external bool? ignoreNullOrigin; + + // external Nacl? nacl; + + external JSAny timelineParams; +} diff --git a/lib/pusher-js/core/connection/callbacks.dart b/lib/pusher-js/core/connection/callbacks.dart deleted file mode 100644 index 94ccd47..0000000 --- a/lib/pusher-js/core/connection/callbacks.dart +++ /dev/null @@ -1,55 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.connection.callbacks; - -import "package:js/js.dart"; -import "handshake/handshake_payload.dart" show HandshakePayload; - -@anonymous -@JS() -abstract class ErrorCallbacks { - external void Function(dynamic /*Action|HandshakePayload*/) get tls_only; - external set tls_only(void Function(dynamic /*Action|HandshakePayload*/) v); - external void Function(dynamic /*Action|HandshakePayload*/) get refused; - external set refused(void Function(dynamic /*Action|HandshakePayload*/) v); - external void Function(dynamic /*Action|HandshakePayload*/) get backoff; - external set backoff(void Function(dynamic /*Action|HandshakePayload*/) v); - external void Function(dynamic /*Action|HandshakePayload*/) get retry; - external set retry(void Function(dynamic /*Action|HandshakePayload*/) v); - external factory ErrorCallbacks( - {void Function(dynamic /*Action|HandshakePayload*/) tls_only, - void Function(dynamic /*Action|HandshakePayload*/) refused, - void Function(dynamic /*Action|HandshakePayload*/) backoff, - void Function(dynamic /*Action|HandshakePayload*/) retry}); -} - -@anonymous -@JS() -abstract class HandshakeCallbacks { - external void Function(HandshakePayload) get connected; - external set connected(void Function(HandshakePayload) v); - external factory HandshakeCallbacks( - {void Function(HandshakePayload) connected}); -} - -@anonymous -@JS() -abstract class ConnectionCallbacks { - external void Function(dynamic) get message; - external set message(void Function(dynamic) v); - external void Function() get ping; - external set ping(void Function() v); - external void Function() get activity; - external set activity(void Function() v); - external void Function(dynamic) get error; - external set error(void Function(dynamic) v); - external void Function() get closed; - external set closed(void Function() v); - external factory ConnectionCallbacks( - {void Function(dynamic) message, - void Function() ping, - void Function() activity, - void Function(dynamic) error, - void Function() closed}); -} diff --git a/lib/pusher-js/core/connection/connection.dart b/lib/pusher-js/core/connection/connection.dart index d0bde74..344644b 100644 --- a/lib/pusher-js/core/connection/connection.dart +++ b/lib/pusher-js/core/connection/connection.dart @@ -1,64 +1,31 @@ -// ignore_for_file: non_constant_identifier_names +import 'dart:js_interop'; -@JS() -library core.connection.connection; +import '../events/dispatcher.dart'; -import "package:js/js.dart"; -import "../events/dispatcher.dart" show Dispatcher; -import "../socket.dart" show Socket; -import "../transports/transport_connection.dart" show TransportConnection; +extension type Connection._(Dispatcher _) implements Dispatcher { + external Connection( + String id, + // TransportConnection transport, + ); -/// Provides Pusher protocol interface for transports. -/// Emits following events: -/// - message - on received messages -/// - ping - on ping requests -/// - pong - on pong responses -/// - error - when the transport emits an error -/// - closed - after closing the transport -/// It also emits more events when connection closes with a code. -/// See Protocol.getCloseAction to get more details. -@JS() -class Connection extends Dispatcher implements Socket { - external String get id; - external set id(String v); - external TransportConnection get transport; - external set transport(TransportConnection v); - external num get activityTimeout; - external set activityTimeout(num v); - external factory Connection(String id, TransportConnection transport); + external String id; - /// Returns whether used transport handles activity checks by itself - external handlesActivityChecks(); + // external TransportConnection transport; - /// Sends raw data. - @override - external bool send(dynamic data); + external num activityTimeout; - /// Sends an event. - external bool send_event(String name, dynamic data, [String channel]); + external bool handlesActivityChecks(); - /// Sends a ping message to the server. - /// Basing on the underlying transport, it might send either transport's - /// protocol-specific ping or pusher:ping event. - @override - external ping(); + external bool send(JSAny? data); - /// Closes the connection. - @override - external close([dynamic code, dynamic reason]); - external bindListeners(); - external handleCloseEvent(dynamic closeEvent); + @JS('send_event') + external bool sendEvent( + String name, + JSAny? data, [ + String? channel, + ]); - @override - external bool sendRaw(dynamic payload); - @override - external Function([dynamic evt])? onopen; - @override - external Function(dynamic)? onerror; - @override - external Function(dynamic)? onclose; - @override - external Function(dynamic)? onmessage; - @override - external Function? onactivity; + external void ping(); + + external void close(); } diff --git a/lib/pusher-js/core/connection/connection_manager.dart b/lib/pusher-js/core/connection/connection_manager.dart index 0aa36db..09ba714 100644 --- a/lib/pusher-js/core/connection/connection_manager.dart +++ b/lib/pusher-js/core/connection/connection_manager.dart @@ -1,106 +1,65 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.connection.connection_manager; - -import "package:js/js.dart"; -import "../events/dispatcher.dart" show Dispatcher; -import "connection_manager_options.dart" show ConnectionManagerOptions; -import "connection.dart" show Connection; -import "../timeline/timeline.dart" show Timeline; -import "../strategies/strategy.dart" show Strategy; -import "../strategies/strategy_runner.dart" show StrategyRunner; -import "../utils/timers/abstract_timer.dart" show Timer; -import "callbacks.dart" - show ErrorCallbacks, HandshakeCallbacks, ConnectionCallbacks; - -/// Manages connection to Pusher. -/// Uses a strategy (currently only default), timers and network availability -/// info to establish a connection and export its state. In case of failures, -/// manages reconnection attempts. -/// Exports state changes as following events: -/// - "state_change", { previous: p, current: state } -/// - state -/// States: -/// - initialized - initial state, never transitioned to -/// - connecting - connection is being established -/// - connected - connection has been fully established -/// - disconnected - on requested disconnection -/// - unavailable - after connection timeout or when there's no network -/// - failed - when the connection strategy is not supported -/// Options: -/// - unavailableTimeout - time to transition to unavailable state -/// - activityTimeout - time after which ping message should be sent -/// - pongTimeout - time for Pusher to respond with pong before reconnecting -@JS() -class ConnectionManager extends Dispatcher { - external String get key; - external set key(String v); - external ConnectionManagerOptions get options; - external set options(ConnectionManagerOptions v); - external String get state; - external set state(String v); - external Connection get connection; - external set connection(Connection v); - external bool get usingTLS; - external set usingTLS(bool v); - external Timeline get timeline; - external set timeline(Timeline v); - external String get socket_id; - external set socket_id(String v); - external Timer get unavailableTimer; - external set unavailableTimer(Timer v); - external Timer get activityTimer; - external set activityTimer(Timer v); - external Timer get retryTimer; - external set retryTimer(Timer v); - external num get activityTimeout; - external set activityTimeout(num v); - external Strategy get strategy; - external set strategy(Strategy v); - external StrategyRunner get runner; - external set runner(StrategyRunner v); - external ErrorCallbacks get errorCallbacks; - external set errorCallbacks(ErrorCallbacks v); - external HandshakeCallbacks get handshakeCallbacks; - external set handshakeCallbacks(HandshakeCallbacks v); - external ConnectionCallbacks get connectionCallbacks; - external set connectionCallbacks(ConnectionCallbacks v); - external factory ConnectionManager( - String key, ConnectionManagerOptions options); - - /// Establishes a connection to Pusher. - /// Does nothing when connection is already established. See top-level doc - /// to find events emitted on connection attempts. - external connect(); - - /// Sends raw data. - external send(data); - - /// Sends an event. - external send_event(String name, dynamic data, [String channel]); - - /// Closes the connection. - external disconnect(); - external isUsingTLS(); - external startConnecting(); - external abortConnecting(); - external disconnectInternally(); - external updateStrategy(); - external retryIn(delay); - external clearRetryTimer(); - external setUnavailableTimer(); - external clearUnavailableTimer(); - external sendActivityCheck(); - external resetActivityCheck(); - external stopActivityCheck(); - external ConnectionCallbacks buildConnectionCallbacks( - ErrorCallbacks errorCallbacks); - external HandshakeCallbacks buildHandshakeCallbacks( - ErrorCallbacks errorCallbacks); - external ErrorCallbacks buildErrorCallbacks(); - external setConnection(connection); - external abandonConnection(); - external updateState(String newState, [dynamic data]); - external bool shouldRetry(); +import 'dart:js_interop'; + +import '../events/dispatcher.dart'; +import '../strategies/strategy.dart'; +import '../strategies/strategy_runner.dart'; +import '../timeline/timeline.dart'; +import 'connection.dart'; +import 'connection_manager_options.dart'; + +extension type ConnectionManager._(Dispatcher _) implements Dispatcher { + external ConnectionManager({ + String key, + ConnectionManagerOptions options, + }); + + external String key; + + external ConnectionManagerOptions options; + + external String state; + + external Connection connection; + + @JS('usingTLS') + external bool usingTls; + + external Timeline timeline; + + @JS('socket_id') + external String socketId; + + // external Timer unavailableTimer; + + // external Timer activityTimer; + + // external Timer retryTimer; + + external num activityTimeout; + + external Strategy strategy; + + external StrategyRunner runner; + + // external ErrorCallbacks errorCallbacks; + + // external HandshakeCallbacks handshakeCallbacks; + + // external ConnectionCallbacks connectionCallbacks; + + external void connect(); + + external bool send(JSAny? data); + + @JS('send_event') + external bool sendEvent( + String name, + JSAny? data, [ + String? channel, + ]); + + external void disconnect(); + + @JS('isUsingTLS') + external bool isUsingTls(); } diff --git a/lib/pusher-js/core/connection/connection_manager_options.dart b/lib/pusher-js/core/connection/connection_manager_options.dart index 1a1df39..eea8f19 100644 --- a/lib/pusher-js/core/connection/connection_manager_options.dart +++ b/lib/pusher-js/core/connection/connection_manager_options.dart @@ -1,32 +1,19 @@ -@JS() -library core.connection.connection_manager_options; - -import "package:js/js.dart"; -import "../timeline/timeline.dart" show Timeline; -import "../strategies/strategy.dart" show Strategy; - -@anonymous -@JS() -abstract class ConnectionManagerOptions { - external Timeline get timeline; - external set timeline(Timeline v); - external Strategy Function(dynamic) get getStrategy; - external set getStrategy(Strategy Function(dynamic) v); - external num get unavailableTimeout; - external set unavailableTimeout(num v); - external num get pongTimeout; - external set pongTimeout(num v); - external num get activityTimeout; - external set activityTimeout(num v); - external bool get useTLS; - external set useTLS(bool v); - external factory ConnectionManagerOptions( - {Timeline timeline, - Strategy Function(dynamic) getStrategy, - num unavailableTimeout, - num pongTimeout, - num activityTimeout, - bool useTLS}); +import 'dart:js_interop'; + +import '../timeline/timeline.dart'; + +extension type ConnectionManagerOptions._(JSObject _) implements JSObject { + external Timeline timeline; + + external JSFunction getStrategy; + + external num unavailableTimeout; + + external num pongTimeout; + + external num activityTimeout; + + @JS('useTLS') + external bool useTls; } -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/connection/handshake.dart b/lib/pusher-js/core/connection/handshake.dart deleted file mode 100644 index 28718fc..0000000 --- a/lib/pusher-js/core/connection/handshake.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.connection.handshake; - -import "package:js/js.dart"; -import "../transports/transport_connection.dart" show TransportConnection; - -/// Handles Pusher protocol handshakes for transports. -/// Calls back with a result object after handshake is completed. Results -/// always have two fields: -/// - action - string describing action to be taken after the handshake -/// - transport - the transport object passed to the constructor -/// Different actions can set different additional properties on the result. -/// In the case of 'connected' action, there will be a 'connection' property -/// containing a Connection object for the transport. Other actions should -/// carry an 'error' property. -@JS() -class Handshake { - // @Ignore - Handshake.fakeConstructor$(); - external TransportConnection get transport; - external set transport(TransportConnection v); - external void Function(dynamic) get callback; - external set callback(void Function(dynamic) v); - external Function get onMessage; - external set onMessage(Function v); - external Function get onClosed; - external set onClosed(Function v); - external factory Handshake( - TransportConnection transport, void callback(HandshakePayload)); - external close(); - external bindListeners(); - external unbindListeners(); - external finish(String action, dynamic params); -} diff --git a/lib/pusher-js/core/connection/handshake/handshake_payload.dart b/lib/pusher-js/core/connection/handshake/handshake_payload.dart deleted file mode 100644 index d856952..0000000 --- a/lib/pusher-js/core/connection/handshake/handshake_payload.dart +++ /dev/null @@ -1,25 +0,0 @@ -@JS() -library core.connection.handshake.handshake_payload; - -import "package:js/js.dart"; -import "../protocol/action.dart" show Action; -import "../../transports/transport_connection.dart" show TransportConnection; -import "../connection.dart" show Connection; - -@anonymous -@JS() -abstract class HandshakePayload implements Action { - external TransportConnection get transport; - external set transport(TransportConnection v); - external Connection get connection; - external set connection(Connection v); - external factory HandshakePayload( - {TransportConnection transport, - Connection connection, - String action, - String id, - num activityTimeout, - dynamic error}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/connection/protocol/action.dart b/lib/pusher-js/core/connection/protocol/action.dart deleted file mode 100644 index 7fa7bc4..0000000 --- a/lib/pusher-js/core/connection/protocol/action.dart +++ /dev/null @@ -1,21 +0,0 @@ -@JS() -library core.connection.protocol.action; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class Action { - external String get action; - external set action(String v); - external String get id; - external set id(String v); - external num get activityTimeout; - external set activityTimeout(num v); - external dynamic get error; - external set error(dynamic v); - external factory Action( - {String action, String id, num activityTimeout, dynamic error}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/connection/protocol/message-types.dart b/lib/pusher-js/core/connection/protocol/message-types.dart deleted file mode 100644 index d358f9f..0000000 --- a/lib/pusher-js/core/connection/protocol/message-types.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: non_constant_identifier_names, file_names - -@JS() -library core.connection.protocol.message_types; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class PusherEvent { - external String get event; - external set event(String v); - external String get channel; - external set channel(String v); - external dynamic get data; - external set data(dynamic v); - external String get user_id; - external set user_id(String v); - external factory PusherEvent( - {String event, String channel, dynamic data, String user_id}); -} diff --git a/lib/wasm-pusher-js/core/connection/protocol/message_types.dart b/lib/pusher-js/core/connection/protocol/message_types.dart similarity index 100% rename from lib/wasm-pusher-js/core/connection/protocol/message_types.dart rename to lib/pusher-js/core/connection/protocol/message_types.dart diff --git a/lib/pusher-js/core/connection/protocol/protocol.dart b/lib/pusher-js/core/connection/protocol/protocol.dart deleted file mode 100644 index 94c28a1..0000000 --- a/lib/pusher-js/core/connection/protocol/protocol.dart +++ /dev/null @@ -1,10 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.connection.protocol.protocol; - -import "package:js/js.dart"; - -/// Provides functions for handling Pusher protocol-specific messages. -@JS() -external get Protocol; /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/defaults.dart b/lib/pusher-js/core/defaults.dart deleted file mode 100644 index 18b2471..0000000 --- a/lib/pusher-js/core/defaults.dart +++ /dev/null @@ -1,75 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.defaults; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class DefaultConfig { - external String get VERSION; - external set VERSION(String v); - external num get PROTOCOL; - external set PROTOCOL(num v); - external num get wsPort; - external set wsPort(num v); - external num get wssPort; - external set wssPort(num v); - external String get wsPath; - external set wsPath(String v); - external String get httpHost; - external set httpHost(String v); - external num get httpPort; - external set httpPort(num v); - external num get httpsPort; - external set httpsPort(num v); - external String get httpPath; - external set httpPath(String v); - external String get stats_host; - external set stats_host(String v); - external String get authEndpoint; - external set authEndpoint(String v); - external String /*'ajax'|'jsonp'*/ get authTransport; - external set authTransport(String /*'ajax'|'jsonp'*/ v); - external num get activityTimeout; - external set activityTimeout(num v); - external num get pongTimeout; - external set pongTimeout(num v); - external num get unavailableTimeout; - external set unavailableTimeout(num v); - external String get cluster; - external set cluster(String v); - external String get cdn_http; - external set cdn_http(String v); - external String get cdn_https; - external set cdn_https(String v); - external String get dependency_suffix; - external set dependency_suffix(String v); - external factory DefaultConfig( - {String VERSION, - num PROTOCOL, - num wsPort, - num wssPort, - String wsPath, - String httpHost, - num httpPort, - num httpsPort, - String httpPath, - String stats_host, - String authEndpoint, - String /*'ajax'|'jsonp'*/ authTransport, - num activityTimeout, - num pongTimeout, - num unavailableTimeout, - String cluster, - String cdn_http, - String cdn_https, - String dependency_suffix}); -} - -@JS() -external DefaultConfig get Defaults; -@JS() -external set Defaults( - DefaultConfig v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/errors.dart b/lib/pusher-js/core/errors.dart deleted file mode 100644 index 5f4f571..0000000 --- a/lib/pusher-js/core/errors.dart +++ /dev/null @@ -1,48 +0,0 @@ -@JS() -library core.errors; - -import "package:js/js.dart"; - -/// Error classes used throughout the library. -/// https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work -@JS() -class BadEventName extends Error { - external factory BadEventName([String msg]); -} - -@JS() -class RequestTimedOut extends Error { - external factory RequestTimedOut([String msg]); -} - -@JS() -class TransportPriorityTooLow extends Error { - external factory TransportPriorityTooLow([String msg]); -} - -@JS() -class TransportClosed extends Error { - external factory TransportClosed([String msg]); -} - -@JS() -class UnsupportedFeature extends Error { - external factory UnsupportedFeature([String msg]); -} - -@JS() -class UnsupportedTransport extends Error { - external factory UnsupportedTransport([String msg]); -} - -@JS() -class UnsupportedStrategy extends Error { - external factory UnsupportedStrategy([String msg]); -} - -@JS() -class HTTPAuthError extends Error { - external num get status; - external set status(num v); - external factory HTTPAuthError(num status, [String msg]); -} diff --git a/lib/pusher-js/core/events/callback.dart b/lib/pusher-js/core/events/callback.dart index 5e252dc..91cede0 100644 --- a/lib/pusher-js/core/events/callback.dart +++ b/lib/pusher-js/core/events/callback.dart @@ -1,16 +1,7 @@ -@JS() -library core.events.callback; +import 'dart:js_interop'; -import "package:js/js.dart"; +extension type Callback._(JSObject _) implements JSObject { + external JSFunction fn; -@anonymous -@JS() -abstract class Callback { - external Function get fn; - external set fn(Function v); - external dynamic get context; - external set context(dynamic v); - external factory Callback({Function fn, dynamic context}); + external JSAny? context; } - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/events/callback_registry.dart b/lib/pusher-js/core/events/callback_registry.dart index 44b0e21..78a31e0 100644 --- a/lib/pusher-js/core/events/callback_registry.dart +++ b/lib/pusher-js/core/events/callback_registry.dart @@ -1,26 +1,17 @@ -// ignore_for_file: non_constant_identifier_names +import 'dart:js_interop'; -@JS() -library core.events.callback_registry; +import 'callback.dart'; +import 'callback_table.dart'; -import "package:js/js.dart"; -import "callback_table.dart" show CallbackTable; -import "callback.dart" show Callback; +extension type CallbackRegistry._(JSObject _) implements JSObject { + external CallbackRegistry(); -@JS() -class CallbackRegistry { - // @Ignore - // CallbackRegistry.fakeConstructor$(); - external CallbackTable get JS$_callbacks; - external set JS$_callbacks(CallbackTable v); - external factory CallbackRegistry(); - external List get(String name); - external add(String name, Function callback, dynamic context); - external remove([String name, Function callback, dynamic context]); - external removeCallback( - List names, Function callback, dynamic context); - external removeAllCallbacks(List names); -} + @JS('_callbacks') + external CallbackTable callbacks; + + external JSArray get(JSString name); -@JS() -external String prefix(String name); + external void add(String name, JSFunction callback, JSAny? context); + + external void remove([String? name, JSFunction? callback, JSAny? context]); +} diff --git a/lib/pusher-js/core/events/callback_table.dart b/lib/pusher-js/core/events/callback_table.dart index b417faf..28f1c18 100644 --- a/lib/pusher-js/core/events/callback_table.dart +++ b/lib/pusher-js/core/events/callback_table.dart @@ -1,12 +1,9 @@ -@JS() -library core.events.callback_table; +import 'dart:js_interop'; -import "package:js/js.dart"; +import 'callback.dart'; -@anonymous -@JS() -abstract class CallbackTable { - /* Index signature is not yet supported by JavaScript interop. */ -} +extension type CallbackTable._(JSObject _) implements JSObject { + external Callback? operator [](String index); -/* WARNING: export assignment not yet supported. */ + external void operator []=(String index, Callback value); +} diff --git a/lib/pusher-js/core/events/dispatcher.dart b/lib/pusher-js/core/events/dispatcher.dart index 811a422..ee1429c 100644 --- a/lib/pusher-js/core/events/dispatcher.dart +++ b/lib/pusher-js/core/events/dispatcher.dart @@ -1,26 +1,32 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.events.dispatcher; - -import "package:js/js.dart"; -import "callback_registry.dart" show CallbackRegistry; -import "../channels/metadata.dart" show Metadata; - -/// Manages callback bindings and event emitting. -@JS() -class Dispatcher { - external CallbackRegistry get callbacks; - external set callbacks(CallbackRegistry v); - external List get global_callbacks; - external set global_callbacks(List v); - external Function get failThrough; - external set failThrough(Function v); - external factory Dispatcher([Function failThrough]); - external bind(String eventName, Function callback, [dynamic context]); - external bind_global(Function callback); - external unbind([String eventName, Function callback, dynamic context]); - external unbind_global([Function callback]); - external unbind_all(); - external Dispatcher emit(String eventName, [dynamic data, Metadata metadata]); +import 'dart:js_interop'; + +import '../channels/metadata.dart'; +import 'callback_registry.dart'; + +extension type Dispatcher._(JSObject _) implements JSObject { + external Dispatcher([JSFunction? failThrough]); + + external CallbackRegistry callbacks; + + @JS('global_callbacks') + external JSArray globalCallbacks; + + external JSFunction failThrough; + + external Dispatcher bind(String eventName, JSFunction callback, + [JSAny? context]); + + @JS('bind_global') + external Dispatcher bindGlobal(JSFunction callback); + + external Dispatcher unbind( + [String? eventName, JSFunction? callback, JSAny? context]); + + @JS('unbind_global') + external Dispatcher unbindGlobal([JSFunction? callback]); + + @JS('unbind_all') + external Dispatcher unbindAll(); + + external Dispatcher emit(String eventName, [JSAny? data, Metadata? metadata]); } diff --git a/lib/pusher-js/core/http/ajax.dart b/lib/pusher-js/core/http/ajax.dart deleted file mode 100644 index 32a6012..0000000 --- a/lib/pusher-js/core/http/ajax.dart +++ /dev/null @@ -1,35 +0,0 @@ -@JS() -library core.http.ajax; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class Ajax { - external void open(String method, String url, - [bool async, String user, String password]); - external void send([dynamic payload]); - external void setRequestHeader(String key, String value); - external Function get onreadystatechange; - external set onreadystatechange(Function v); - external num get readyState; - external set readyState(num v); - external String get responseText; - external set responseText(String v); - external num get status; - external set status(num v); - external bool get withCredentials; - external set withCredentials(bool v); - external Function get ontimeout; - external set ontimeout(Function v); - external Function get onerror; - external set onerror(Function v); - external Function get onprogress; - external set onprogress(Function v); - external Function get onload; - external set onload(Function v); - external Function get abort; - external set abort(Function v); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/http_factory.dart b/lib/pusher-js/core/http/http_factory.dart deleted file mode 100644 index fe837ad..0000000 --- a/lib/pusher-js/core/http/http_factory.dart +++ /dev/null @@ -1,22 +0,0 @@ -@JS() -library core.http.http_factory; - -import "package:js/js.dart"; -import "http_socket.dart" show HTTPSocket; -import "socket_hooks.dart" show SocketHooks; -import "http_request.dart" show HTTPRequest; -import "request_hooks.dart" show RequestHooks; - -@anonymous -@JS() -abstract class HTTPFactory { - external HTTPSocket createStreamingSocket(String url); - external HTTPSocket createPollingSocket(String url); - external HTTPSocket createSocket(SocketHooks hooks, String url); - external HTTPRequest createXHR(String method, String url); - external HTTPRequest createXDR(String method, String url); - external HTTPRequest createRequest( - RequestHooks hooks, String method, String url); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/http_polling_socket.dart b/lib/pusher-js/core/http/http_polling_socket.dart deleted file mode 100644 index 40bce13..0000000 --- a/lib/pusher-js/core/http/http_polling_socket.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library core.http.http_polling_socket; - -import "package:js/js.dart"; -import "socket_hooks.dart" show SocketHooks; - -@JS() -external SocketHooks get hooks; -@JS() -external set hooks( - SocketHooks v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/http_request.dart b/lib/pusher-js/core/http/http_request.dart deleted file mode 100644 index d67090b..0000000 --- a/lib/pusher-js/core/http/http_request.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.http.http_request; - -import "package:js/js.dart"; -import "../events/dispatcher.dart" show Dispatcher; -import "request_hooks.dart" show RequestHooks; -import "ajax.dart" show Ajax; - -@JS() -external get MAX_BUFFER_LENGTH; - -@JS() -class HTTPRequest extends Dispatcher { - external RequestHooks get hooks; - external set hooks(RequestHooks v); - external String get method; - external set method(String v); - external String get url; - external set url(String v); - external num get position; - external set position(num v); - external Ajax get xhr; - external set xhr(Ajax v); - external Function get unloader; - external set unloader(Function v); - external factory HTTPRequest(RequestHooks hooks, String method, String url); - external start([dynamic payload]); - external close(); - external onChunk(num status, dynamic data); - external dynamic advanceBuffer(List buffer); - external bool isBufferTooLong(dynamic buffer); -} diff --git a/lib/pusher-js/core/http/http_socket.dart b/lib/pusher-js/core/http/http_socket.dart deleted file mode 100644 index cf9a988..0000000 --- a/lib/pusher-js/core/http/http_socket.dart +++ /dev/null @@ -1,65 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library http_socket; - -import "package:js/js.dart"; -import "../socket.dart" show Socket; -import "socket_hooks.dart" show SocketHooks; -import "url_location.dart" show URLLocation; -import "http_request.dart" show HTTPRequest; - -@JS() -class State { - external static num get CONNECTING; - external static num get OPEN; - external static num get CLOSED; -} - -@JS() -class HTTPSocket implements Socket { - external SocketHooks get hooks; - external set hooks(SocketHooks v); - external String get session; - external set session(String v); - external URLLocation get location; - external set location(URLLocation v); - external State readyState; - external HTTPRequest get stream; - external set stream(HTTPRequest v); - @override - external Function([dynamic evt])? onopen; - @override - external Function(dynamic)? onerror; - @override - external Function(dynamic)? onclose; - @override - external Function(dynamic)? onmessage; - @override - external Function? onactivity; - external factory HTTPSocket(SocketHooks hooks, String url); - @override - external bool send(dynamic payload); - @override - external void ping(); - @override - external void close([dynamic code, dynamic reason]); - @override - external bool sendRaw(dynamic payload); - external void reconnect(); - external void onClose(dynamic code, dynamic reason, dynamic wasClean); - external get onChunk; - external set onChunk(v); - external get onOpen; - external set onOpen(v); - external get onEvent; - external set onEvent(v); - external get onActivity; - external set onActivity(v); - external get onError; - external set onError(v); - external get openStream; - external set openStream(v); - external get closeStream; - external set closeStream(v); -} /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/http_streaming_socket.dart b/lib/pusher-js/core/http/http_streaming_socket.dart deleted file mode 100644 index d587d49..0000000 --- a/lib/pusher-js/core/http/http_streaming_socket.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library core.http.http_streaming_socket; - -import "package:js/js.dart"; -import "socket_hooks.dart" show SocketHooks; - -@JS() -external SocketHooks get hooks; -@JS() -external set hooks( - SocketHooks v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/request_hooks.dart b/lib/pusher-js/core/http/request_hooks.dart deleted file mode 100644 index 558d85a..0000000 --- a/lib/pusher-js/core/http/request_hooks.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.http.request_hooks; - -import "package:js/js.dart"; -import "ajax.dart" show Ajax; - -@anonymous -@JS() -abstract class RequestHooks { - external Ajax getRequest(HTTPRequest); - external void abortRequest(HTTPRequest); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/socket_hooks.dart b/lib/pusher-js/core/http/socket_hooks.dart deleted file mode 100644 index 52bb43b..0000000 --- a/lib/pusher-js/core/http/socket_hooks.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.http.socket_hooks; - -import "package:js/js.dart"; -import "url_location.dart" show URLLocation; - -@anonymous -@JS() -abstract class SocketHooks { - external String getReceiveURL(URLLocation url, String session); - external void onHeartbeat(Socket); - external void sendHeartbeat(Socket); - external void onFinished(Socket, Status); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/state.dart b/lib/pusher-js/core/http/state.dart deleted file mode 100644 index fc19703..0000000 --- a/lib/pusher-js/core/http/state.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.http.state; - -import "package:js/js.dart"; - -@JS() -class State { - external static num get CONNECTING; - external static num get OPEN; - external static num get CLOSED; -} /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/http/url_location.dart b/lib/pusher-js/core/http/url_location.dart deleted file mode 100644 index ac71b76..0000000 --- a/lib/pusher-js/core/http/url_location.dart +++ /dev/null @@ -1,16 +0,0 @@ -@JS() -library core.http.url_location; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class URLLocation { - external String get base; - external set base(String v); - external String get queryString; - external set queryString(String v); - external factory URLLocation({String base, String queryString}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/logger.dart b/lib/pusher-js/core/logger.dart deleted file mode 100644 index 7c82ffa..0000000 --- a/lib/pusher-js/core/logger.dart +++ /dev/null @@ -1,40 +0,0 @@ -@JS() -library core.logger; - -import "package:js/js.dart"; - -@JS() -class Logger { - // @Ignore - Logger.fakeConstructor$(); - external debug( - [dynamic args1, - dynamic args2, - dynamic args3, - dynamic args4, - dynamic args5]); - external warn( - [dynamic args1, - dynamic args2, - dynamic args3, - dynamic args4, - dynamic args5]); - external error( - [dynamic args1, - dynamic args2, - dynamic args3, - dynamic args4, - dynamic args5]); - external get globalLog; - external set globalLog(v); - external globalLogWarn(String message); - external globalLogError(String message); - external log(void Function(String message) defaultLoggingFunction, - [dynamic args1, - dynamic args2, - dynamic args3, - dynamic args4, - dynamic args5]); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/options.dart b/lib/pusher-js/core/options.dart index 7637369..26135d5 100644 --- a/lib/pusher-js/core/options.dart +++ b/lib/pusher-js/core/options.dart @@ -1,91 +1,94 @@ -@JS() -library core.options; - -import "package:js/js.dart"; -import "auth/options.dart" show AuthOptions, AuthorizerGenerator; - -@anonymous -@JS() -abstract class Options { - external num get activityTimeout; - external set activityTimeout(num v); - external AuthOptions get auth; - external set auth(AuthOptions v); - external String get authEndpoint; - external set authEndpoint(String v); - external String /*'ajax'|'jsonp'*/ get authTransport; - external set authTransport(String /*'ajax'|'jsonp'*/ v); - external AuthorizerGenerator get authorizer; - external set authorizer(AuthorizerGenerator v); - external String get cluster; - external set cluster(String v); - external bool get enableStats; - external set enableStats(bool v); - external bool get disableStats; - external set disableStats(bool v); - external List - get disabledTransports; - external set disabledTransports( - List v); - external List - get enabledTransports; - external set enabledTransports( - List v); - external bool get forceTLS; - external set forceTLS(bool v); - external String get httpHost; - external set httpHost(String v); - external String get httpPath; - external set httpPath(String v); - external num get httpPort; - external set httpPort(num v); - external num get httpsPort; - external set httpsPort(num v); - external bool get ignoreNullOrigin; - external set ignoreNullOrigin(bool v); -// external nacl get nacl; -// external set nacl(nacl v); - external num get pongTimeout; - external set pongTimeout(num v); - external String get statsHost; - external set statsHost(String v); - external dynamic get timelineParams; - external set timelineParams(dynamic v); - external num get unavailableTimeout; - external set unavailableTimeout(num v); - external String get wsHost; - external set wsHost(String v); - external String get wsPath; - external set wsPath(String v); - external num get wsPort; - external set wsPort(num v); - external num get wssPort; - external set wssPort(num v); - external factory Options( - {num activityTimeout, - AuthOptions auth, - String authEndpoint, - String /*'ajax'|'jsonp'*/ authTransport, - AuthorizerGenerator authorizer, - String cluster, - bool enableStats, - bool disableStats, - List - disabledTransports, - List - enabledTransports, - bool forceTLS, - String httpHost, - String httpPath, - num httpPort, - num httpsPort, - bool ignoreNullOrigin, - num pongTimeout, - String statsHost, - dynamic timelineParams, - num unavailableTimeout, - String wsHost, - String wsPath, - num wsPort, - num wssPort}); +import 'dart:js_interop'; + +import 'auth/deprecated_channel_authorizer.dart'; +import 'auth/options.dart'; + +extension type Options._(JSObject _) implements JSObject { + external Options({ + num? activityTimeout, + DeprecatedAuthOptions? auth, + String? authEndpoint, + String? authTransport, + ChannelAuthorizerGenerator? authorizer, + ChannelAuthorizationOptions? channelAuthorization, + UserAuthenticationOptions? userAuthentication, + String? cluster, + bool? enableStats, + bool? disableStats, + JSArray? disabledTransports, + JSArray? enabledTransports, + bool? forceTLS, + String? httpHost, + String? httpPath, + num? httpPort, + bool? ignoreNullOrigin, + // Nacl? nacl; + num? pongTimeout, + String? statsHost, + JSAny timelineParams, + num? unavailableTimeout, + String? wsHost, + String? wsPath, + num? wsPort, + num? wssPort, + }); + + external num? activityTimeout; + + @Deprecated('Use channelAuthorization instead') + external DeprecatedAuthOptions? auth; + + @Deprecated('Use channelAuthorization instead') + external String? authEndpoint; + + /// Allow 'ajax' | 'jsonp' + @Deprecated('Use channelAuthorization instead') + external String? authTransport; + + @Deprecated('Use channelAuthorization instead') + external ChannelAuthorizerGenerator? authorizer; + + external ChannelAuthorizationOptions? channelAuthorization; + + external UserAuthenticationOptions? userAuthentication; + + external String? cluster; + + external bool? enableStats; + + external bool? disableStats; + + // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' + external JSArray? disabledTransports; + + // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' + external JSArray? enabledTransports; + + external bool? forceTLS; + + external String? httpHost; + + external String? httpPath; + + external num? httpPort; + + external bool? ignoreNullOrigin; + + // external Nacl? nacl; + + external num? pongTimeout; + + external String? statsHost; + + external JSAny? timelineParams; + + external num? unavailableTimeout; + + external String? wsHost; + + external String? wsPath; + + external num? wsPort; + + external num? wssPort; } diff --git a/lib/pusher-js/core/pusher.dart b/lib/pusher-js/core/pusher.dart index 508d8bd..aaba4da 100644 --- a/lib/pusher-js/core/pusher.dart +++ b/lib/pusher-js/core/pusher.dart @@ -1,79 +1,100 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.pusher; - -import "package:js/js.dart"; -//import "../runtimes/interface.dart" show Runtime; -import "config.dart" show Config; -import "channels/channels.dart" show Channels; -// import "events/dispatcher.dart" show Dispatcher; -//import "timeline/timeline.dart" show Timeline; -// import "timeline/timeline_sender.dart" show TimelineSender; -import "connection/connection_manager.dart" show ConnectionManager; -import "options.dart" show Options; -import "channels/channel.dart" show Channel; - -@JS() -class Pusher { +import 'dart:js_interop'; + +import 'channels.dart'; +import 'channels/channel.dart'; +import 'config.dart'; +import 'connection/connection_manager.dart'; +import 'events/dispatcher.dart'; +import 'options.dart'; +import 'timeline/timeline.dart'; +import 'timeline/timeline_sender.dart'; +import 'user.dart'; + +extension type Pusher._(JSObject _) implements JSObject { + external Pusher(String appKey, Options options); + /// STATIC PROPERTIES - external static List get instances; - external static set instances(List v); - external static bool get isReady; - external static set isReady(bool v); - external static bool get logToConsole; - external static set logToConsole(bool v); - - /// for jsonp -// external static Runtime get Runtime; -// external static set Runtime(Runtime v); - external static dynamic get ScriptReceivers; - external static set ScriptReceivers(dynamic v); - external static dynamic get DependenciesReceivers; - external static set DependenciesReceivers(dynamic v); - external static dynamic get auth_callbacks; - external static set auth_callbacks(dynamic v); - external static ready(); - external static void Function(dynamic) get log; - external static set log(void Function(dynamic) v); - external static List getClientFeatures(); - - /// INSTANCE PROPERTIES - external String get key; - external set key(String v); - external Config get config; - external set config(Config v); - external Channels get channels; - external set channels(Channels v); -// external Dispatcher get global_emitter; -// external set global_emitter(Dispatcher v); - external num get sessionID; - external set sessionID(num v); -// external Timeline get timeline; -// external set timeline(Timeline v); -// external TimelineSender get timelineSender; -// external set timelineSender(TimelineSender v); - external ConnectionManager get connection; - external set connection(ConnectionManager v); -// external PeriodicTimer get timelineSenderTimer; -// external set timelineSenderTimer(PeriodicTimer v); - external factory Pusher(String app_key, [Options options]); + external static JSArray instances; + + external static bool isRead; + + external static bool logToConsole; + + // static Runtime: AbstractRuntime; + // static ScriptReceivers: any; + // static DependenciesReceivers: any; + // static auth_callbacks: any; + + external static void ready(); + + external static void log(JSAny? message); + + external static JSAny? get getClientFeatures; + + external String key; + + external Config config; + + external Channels channels; + + @JS('global_emitter') + external Dispatcher globalEmitter; + + @JS('sessionID') + external num sessionId; + + external Timeline timeline; + + external TimelineSender timelineSender; + + external ConnectionManager connection; + + external UserFacade user; + external Channel? channel(String name); - external List allChannels(); - external connect(); - external disconnect(); - external Pusher bind(String event_name, Function callback, [dynamic context]); - external Pusher unbind( - [String event_name, Function callback, dynamic context]); - external Pusher bind_global(Function callback); - external Pusher unbind_global([Function callback]); - external Pusher unbind_all([Function callback]); - external subscribeAll(); - external subscribe(String channel_name); - external unsubscribe(String channel_name); - external send_event(String event_name, dynamic data, [String channel]); - external bool shouldUseTLS(); -} -@JS() -external checkAppKey(key); + external JSArray allChannels(); + + external void connect(); + + external void disconnect(); + + external Pusher bind( + String eventName, + JSFunction callback, [ + JSAny? context, + ]); + + external Pusher unbind([ + String? eventName, + JSFunction? callback, + JSAny? context, + ]); + + @JS('bind_global') + external Pusher bindGlobal(JSFunction callback); + + @JS('unbind_global') + external Pusher unbindGlobal([JSFunction? callback]); + + @JS('unbind_all') + external void unbindAll([JSFunction? callback]); + + external void subscribeAll(); + + external Channel subscribe(String channelName); + + external void unsubscribe(String channelName); + + @JS('send_event') + external bool sendEvent( + String eventName, + JSAny? data, [ + String? channel, + ]); + + @JS('shouldUseTLS') + external bool shouldUseTls(); + + external void signin(); +} diff --git a/lib/pusher-js/core/pusher_with_encryption.dart b/lib/pusher-js/core/pusher_with_encryption.dart deleted file mode 100644 index 445782a..0000000 --- a/lib/pusher-js/core/pusher_with_encryption.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.pusher_with_encryption; - -import "package:js/js.dart"; -import "pusher.dart" show Pusher; -import "options.dart" show Options; - -@JS() -class PusherWithEncryption extends Pusher { - external factory PusherWithEncryption(String app_key, [Options options]); -} diff --git a/lib/pusher-js/core/reachability.dart b/lib/pusher-js/core/reachability.dart deleted file mode 100644 index ee9e229..0000000 --- a/lib/pusher-js/core/reachability.dart +++ /dev/null @@ -1,13 +0,0 @@ -@JS() -library core.reachability; - -import "package:js/js.dart"; -import "events/dispatcher.dart" show Dispatcher; - -@anonymous -@JS() -abstract class Reachability implements Dispatcher { - external bool isOnline(); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/socket.dart b/lib/pusher-js/core/socket.dart index c04cf2c..e3672f0 100644 --- a/lib/pusher-js/core/socket.dart +++ b/lib/pusher-js/core/socket.dart @@ -1,20 +1,26 @@ -@JS() -library core.socket; +import 'dart:js_interop'; -import "package:js/js.dart"; - -@anonymous -@JS() abstract class Socket { external void send(dynamic payload); - external void ping(); - external void close([dynamic code, dynamic reason]); - external bool sendRaw(dynamic payload); - external Function([dynamic evt])? onopen; - external Function(dynamic error)? onerror; - external Function(dynamic closeEvent)? onclose; - external Function(dynamic message)? onmessage; - external Function? onactivity; -} -/* WARNING: export assignment not yet supported. */ + external void Function()? ping; + + external dynamic close([dynamic code, dynamic reason]); + + external bool Function(dynamic payload)? sendRaw; + + @JS('onopen') + external void Function([dynamic evt])? onOpen; + + @JS('onerror') + external void Function(dynamic error)? onerror; + + @JS('onclose') + external void Function(dynamic closeEvent)? onclose; + + @JS('onmessage') + external void Function(dynamic message)? onMessage; + + @JS('onactivity') + external void Function()? onActivity; +} diff --git a/lib/pusher-js/core/strategies/best_connected_ever_strategy.dart b/lib/pusher-js/core/strategies/best_connected_ever_strategy.dart deleted file mode 100644 index 5803c37..0000000 --- a/lib/pusher-js/core/strategies/best_connected_ever_strategy.dart +++ /dev/null @@ -1,32 +0,0 @@ -@JS() -library core.strategies.best_connected_ever_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; - -/// Launches all substrategies and emits prioritized connected transports. -@JS() -class BestConnectedEverStrategy implements Strategy { - // @Ignore - BestConnectedEverStrategy.fakeConstructor$(); - external List get strategies; - external set strategies(List v); - external factory BestConnectedEverStrategy(List strategies); - @override - external bool isSupported(); - @override - external connect(num minPriority, Function callback); -} - -/// Connects to all strategies in parallel. -/// Callback builder should be a function that takes two arguments: index -/// and a list of runners. It should return another function that will be -/// passed to the substrategy with given index. Runners can be aborted using -/// abortRunner(s) functions from this class. -@JS() -external connect( - List strategies, num minPriority, Function callbackBuilder); -@JS() -external bool allRunnersFailed(runners); -@JS() -external abortRunner(runner); diff --git a/lib/pusher-js/core/strategies/cached_strategy.dart b/lib/pusher-js/core/strategies/cached_strategy.dart deleted file mode 100644 index e52a4f1..0000000 --- a/lib/pusher-js/core/strategies/cached_strategy.dart +++ /dev/null @@ -1,47 +0,0 @@ -@JS() -library core.strategies.cached_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; -import "../timeline/timeline.dart" show Timeline; -import "strategy_options.dart" show StrategyOptions; -import "transport_strategy.dart" show TransportStrategy; - -@anonymous -@JS() -abstract class TransportStrategyDictionary { - /* Index signature is not yet supported by JavaScript interop. */ -} - -/// Caches last successful transport and uses it for following attempts. -@JS() -class CachedStrategy implements Strategy { - // @Ignore - CachedStrategy.fakeConstructor$(); - external Strategy get strategy; - external set strategy(Strategy v); - external TransportStrategyDictionary get transports; - external set transports(TransportStrategyDictionary v); - external num get ttl; - external set ttl(num v); - external bool get usingTLS; - external set usingTLS(bool v); - external Timeline get timeline; - external set timeline(Timeline v); - external factory CachedStrategy(Strategy strategy, - TransportStrategyDictionary transports, StrategyOptions options); - @override - external bool isSupported(); - @override - external connect(num minPriority, Function callback); -} - -@JS() -external String getTransportCacheKey(bool usingTLS); -@JS() -external dynamic fetchTransportCache(bool usingTLS); -@JS() -external storeTransportCache( - bool usingTLS, TransportStrategy transport, num latency); -@JS() -external flushTransportCache(bool usingTLS); diff --git a/lib/pusher-js/core/strategies/delayed_strategy.dart b/lib/pusher-js/core/strategies/delayed_strategy.dart deleted file mode 100644 index b74eebd..0000000 --- a/lib/pusher-js/core/strategies/delayed_strategy.dart +++ /dev/null @@ -1,24 +0,0 @@ -@JS() -library core.strategies.delayed_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; - -/// Runs substrategy after specified delay. -/// Options: -/// - delay - time in miliseconds to delay the substrategy attempt -@JS() -class DelayedStrategy implements Strategy { - // @Ignore - DelayedStrategy.fakeConstructor$(); - external Strategy get strategy; - external set strategy(Strategy v); - external dynamic /*{ delay: number }*/ get options; - external set options(dynamic /*{ delay: number }*/ v); - external factory DelayedStrategy( - Strategy strategy, Object number /*{ delay: number }*/); - @override - external bool isSupported(); - @override - external connect(num minPriority, Function callback); -} diff --git a/lib/pusher-js/core/strategies/first_connected_strategy.dart b/lib/pusher-js/core/strategies/first_connected_strategy.dart deleted file mode 100644 index e797e6a..0000000 --- a/lib/pusher-js/core/strategies/first_connected_strategy.dart +++ /dev/null @@ -1,20 +0,0 @@ -@JS() -library core.strategies.first_connected_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; -import "strategy_runner.dart" show StrategyRunner; - -/// Launches the substrategy and terminates on the first open connection. -@JS() -class FirstConnectedStrategy implements Strategy { - // @Ignore - FirstConnectedStrategy.fakeConstructor$(); - external Strategy get strategy; - external set strategy(Strategy v); - external factory FirstConnectedStrategy(Strategy strategy); - @override - external bool isSupported(); - @override - external StrategyRunner connect(num minPriority, Function callback); -} diff --git a/lib/pusher-js/core/strategies/if_strategy.dart b/lib/pusher-js/core/strategies/if_strategy.dart deleted file mode 100644 index 30f5dbd..0000000 --- a/lib/pusher-js/core/strategies/if_strategy.dart +++ /dev/null @@ -1,25 +0,0 @@ -@JS() -library core.strategies.if_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; -import "strategy_runner.dart" show StrategyRunner; - -/// Proxies method calls to one of substrategies basing on the test function. -@JS() -class IfStrategy implements Strategy { - // @Ignore - IfStrategy.fakeConstructor$(); - external bool Function() get test; - external set test(bool Function() v); - external Strategy get trueBranch; - external set trueBranch(Strategy v); - external Strategy get falseBranch; - external set falseBranch(Strategy v); - external factory IfStrategy( - bool Function() test, Strategy trueBranch, Strategy falseBranch); - @override - external bool isSupported(); - @override - external StrategyRunner connect(num minPriority, Function callback); -} diff --git a/lib/pusher-js/core/strategies/sequential_strategy.dart b/lib/pusher-js/core/strategies/sequential_strategy.dart deleted file mode 100644 index 46e9adf..0000000 --- a/lib/pusher-js/core/strategies/sequential_strategy.dart +++ /dev/null @@ -1,35 +0,0 @@ -@JS() -library core.strategies.sequential_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; -import "strategy_options.dart" show StrategyOptions; - -/// Loops through strategies with optional timeouts. -/// Options: -/// - loop - whether it should loop through the substrategy list -/// - timeout - initial timeout for a single substrategy -/// - timeoutLimit - maximum timeout -@JS() -class SequentialStrategy implements Strategy { - // @Ignore - SequentialStrategy.fakeConstructor$(); - external List get strategies; - external set strategies(List v); - external bool get loop; - external set loop(bool v); - external bool get failFast; - external set failFast(bool v); - external num get timeout; - external set timeout(num v); - external num get timeoutLimit; - external set timeoutLimit(num v); - external factory SequentialStrategy( - List strategies, StrategyOptions options); - @override - external bool isSupported(); - @override - external connect(num minPriority, Function callback); - external tryStrategy(Strategy strategy, num minPriority, - StrategyOptions options, Function callback); -} diff --git a/lib/pusher-js/core/strategies/strategy.dart b/lib/pusher-js/core/strategies/strategy.dart index 5b25086..7b52e9d 100644 --- a/lib/pusher-js/core/strategies/strategy.dart +++ b/lib/pusher-js/core/strategies/strategy.dart @@ -1,14 +1,9 @@ -@JS() -library core.strategies.strategy; +import 'dart:js_interop'; -import "package:js/js.dart"; -import "strategy_runner.dart" show StrategyRunner; +import 'strategy_runner.dart'; -@anonymous -@JS() -abstract class Strategy { +extension type Strategy._(JSObject _) implements JSObject { external bool isSupported(); - external StrategyRunner connect(num minPriority, Function callback); -} -/* WARNING: export assignment not yet supported. */ + external StrategyRunner connect(num minPriority, JSFunction callback); +} diff --git a/lib/pusher-js/core/strategies/strategy_options.dart b/lib/pusher-js/core/strategies/strategy_options.dart deleted file mode 100644 index 493c7e6..0000000 --- a/lib/pusher-js/core/strategies/strategy_options.dart +++ /dev/null @@ -1,49 +0,0 @@ -@JS() -library core.strategies.strategy_options; - -import "package:js/js.dart"; -import "../timeline/timeline.dart" show Timeline; - -@anonymous -@JS() -abstract class StrategyOptions { - external bool get failFast; - external set failFast(bool v); - external String get hostNonTLS; - external set hostNonTLS(String v); - external String get hostTLS; - external set hostTLS(String v); - external String get httpPath; - external set httpPath(String v); - external bool get ignoreNullOrigin; - external set ignoreNullOrigin(bool v); - external String get key; - external set key(String v); - external bool get loop; - external set loop(bool v); - external Timeline get timeline; - external set timeline(Timeline v); - external num get timeout; - external set timeout(num v); - external num get timeoutLimit; - external set timeoutLimit(num v); - external num get ttl; - external set ttl(num v); - external bool get useTLS; - external set useTLS(bool v); - external factory StrategyOptions( - {bool failFast, - String hostNonTLS, - String hostTLS, - String httpPath, - bool ignoreNullOrigin, - String key, - bool loop, - Timeline timeline, - num timeout, - num timeoutLimit, - num ttl, - bool useTLS}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/strategies/strategy_runner.dart b/lib/pusher-js/core/strategies/strategy_runner.dart index b19b098..d769aec 100644 --- a/lib/pusher-js/core/strategies/strategy_runner.dart +++ b/lib/pusher-js/core/strategies/strategy_runner.dart @@ -1,17 +1,17 @@ -@JS() -library core.strategies.strategy_runner; +import 'dart:js_interop'; -import "package:js/js.dart"; +extension type StrategyRunnerForceMinPriorityFunction._(JSFunction _) + implements JSFunction { + void call(JSAny? number) => callAsFunction(null, number); +} -@anonymous -@JS() -abstract class StrategyRunner { - external void Function(dynamic) get forceMinPriority; - external set forceMinPriority(void Function(dynamic) v); - external void Function() get abort; - external set abort(void Function() v); - external factory StrategyRunner( - {void Function(dynamic) forceMinPriority, void Function() abort}); +extension type StrategyRunnerAbortFunction._(JSFunction _) + implements JSFunction { + void call() => callAsFunction(null); } -/* WARNING: export assignment not yet supported. */ +extension type StrategyRunner._(JSObject _) implements JSObject { + external StrategyRunnerForceMinPriorityFunction forceMinPriority; + + external StrategyRunnerAbortFunction abort; +} diff --git a/lib/pusher-js/core/strategies/transport_strategy.dart b/lib/pusher-js/core/strategies/transport_strategy.dart deleted file mode 100644 index 7d00491..0000000 --- a/lib/pusher-js/core/strategies/transport_strategy.dart +++ /dev/null @@ -1,35 +0,0 @@ -@JS() -library core.strategies.transport_strategy; - -import "package:js/js.dart"; -import "strategy.dart" show Strategy; -import "../transports/transport.dart" show Transport; -import "strategy_options.dart" show StrategyOptions; - -/// Provides a strategy interface for transports. -@JS() -class TransportStrategy implements Strategy { - // @Ignore - TransportStrategy.fakeConstructor$(); - external String get name; - external set name(String v); - external num get priority; - external set priority(num v); - external Transport get transport; - external set transport(Transport v); - external StrategyOptions get options; - external set options(StrategyOptions v); - external factory TransportStrategy( - String name, num priority, Transport transport, StrategyOptions options); - - /// Returns whether the transport is supported in the browser. - @override - external bool isSupported(); - - /// Launches a connection attempt and returns a strategy runner. - @override - external connect(num minPriority, Function callback); -} - -@JS() -external failAttempt(Error error, Function callback); diff --git a/lib/pusher-js/core/timeline/level.dart b/lib/pusher-js/core/timeline/level.dart index aed40e2..70da50b 100644 --- a/lib/pusher-js/core/timeline/level.dart +++ b/lib/pusher-js/core/timeline/level.dart @@ -1,13 +1,9 @@ -// ignore_for_file: non_constant_identifier_names +enum TimelineLevel { + error(3), + info(6), + debug(7); -@JS() -library core.timeline.level; + const TimelineLevel(this.value); -import "package:js/js.dart"; - -@JS() -class TimelineLevel { - external static num get ERROR; - external static num get INFO; - external static num get DEBUG; -} /* WARNING: export assignment not yet supported. */ + final int value; +} diff --git a/lib/pusher-js/core/timeline/timeline.dart b/lib/pusher-js/core/timeline/timeline.dart index 98a3b86..1736728 100644 --- a/lib/pusher-js/core/timeline/timeline.dart +++ b/lib/pusher-js/core/timeline/timeline.dart @@ -1,61 +1,60 @@ -// ignore_for_file: non_constant_identifier_names +import 'dart:js_interop'; -@JS() -library core.timeline.timeline; +extension type TimelineOptions._(JSObject _) implements JSObject { + external TimelineOptions({ + num? level, + num? limit, + String? version, + String? cluster, + JSArray? features, + JSAny? params, + }); -import "package:js/js.dart"; + external num? level; -@JS() -class Level { - external static num get ERROR; - external static num get INFO; - external static num get DEBUG; -} + external num? limit; + + external String? version; + + external String? cluster; -@anonymous -@JS() -abstract class TimelineOptions { - external Level get level; - external set level(Level v); - external num get limit; - external set limit(num v); - external String get version; - external set version(String v); - external String get cluster; - external set cluster(String v); - external List get features; - external set features(List v); - external dynamic get params; - external set params(dynamic v); - external factory TimelineOptions( - {Level level, - num limit, - String version, - String cluster, - List features, - dynamic params}); + external JSArray? features; + + external JSAny? params; } -@JS() -class Timeline { - external String get key; - external set key(String v); - external num get session; - external set session(num v); - external List get events; - external set events(List v); - external TimelineOptions get options; - external set options(TimelineOptions v); - external num get sent; - external set sent(num v); - external num get uniqueID; - external set uniqueID(num v); - external factory Timeline(String key, num session, TimelineOptions options); - external log(level, event); - external error(event); - external info(event); - external debug(event); - external isEmpty(); - external send(sendfn, callback); - external num generateUniqueID(); +extension type Timeline._(JSObject _) implements JSObject { + external Timeline( + String key, + num session, + TimelineOptions options, + ); + + external String key; + + external num session; + + external JSArray events; + + external TimelineOptions options; + + external num sent; + + @JS('uniqueID') + external num uniqueId; + + external void log(JSAny? level, JSAny? event); + + external void error(JSAny? event); + + external void info(JSAny? event); + + external void debug(JSAny? event); + + external bool isEmpty(); + + external bool send(JSAny? sendfn, JSAny? callback); + + @JS('generateUniqueID') + external num generationUniqueId(); } diff --git a/lib/pusher-js/core/timeline/timeline_sender.dart b/lib/pusher-js/core/timeline/timeline_sender.dart index da4eda5..27c43d0 100644 --- a/lib/pusher-js/core/timeline/timeline_sender.dart +++ b/lib/pusher-js/core/timeline/timeline_sender.dart @@ -1,30 +1,32 @@ -@JS() -library core.timeline.timeline_sender; - -import "package:js/js.dart"; -import "timeline.dart" show Timeline; - -@anonymous -@JS() -abstract class TimelineSenderOptions { - external String get host; - external set host(String v); - external num get port; - external set port(num v); - external String get path; - external set path(String v); - external factory TimelineSenderOptions({String host, num port, String path}); +import 'dart:js_interop'; + +import 'timeline.dart'; + +extension type TimelineSenderOptions._(JSObject _) implements JSObject { + external TimelineSenderOptions({ + String? host, + num? port, + String? path, + }); + + external String? host; + + external num? port; + + external String? path; } -@JS() -class TimelineSender { - external Timeline get timeline; - external set timeline(Timeline v); - external TimelineSenderOptions get options; - external set options(TimelineSenderOptions v); - external String get host; - external set host(String v); - external factory TimelineSender( - Timeline timeline, TimelineSenderOptions options); - external send(bool useTLS, [Function callback]); +extension type TimelineSender._(JSObject _) implements JSObject { + external TimelineSender({ + Timeline timeline, + TimelineSenderOptions options, + }); + + external Timeline timeline; + + external TimelineSenderOptions options; + + external String host; + + external void send(bool useTls, [JSFunction? callback]); } diff --git a/lib/pusher-js/core/timeline/timeline_transport.dart b/lib/pusher-js/core/timeline/timeline_transport.dart deleted file mode 100644 index f325493..0000000 --- a/lib/pusher-js/core/timeline/timeline_transport.dart +++ /dev/null @@ -1,22 +0,0 @@ -@JS() -library core.timeline.timeline_transport; - -import "package:js/js.dart"; -import "timeline_sender.dart" show TimelineSender; - -@anonymous -@JS() -abstract class TimelineTransport { - external String get name; - external set name(String v); - external void Function(dynamic, Function) Function(TimelineSender, bool) - get getAgent; - external set getAgent( - void Function(dynamic, Function) Function(TimelineSender, bool) v); - external factory TimelineTransport( - {String name, - void Function(dynamic, Function) Function(TimelineSender, bool) - getAgent}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/assistant_to_the_transport_manager.dart b/lib/pusher-js/core/transports/assistant_to_the_transport_manager.dart deleted file mode 100644 index 99c4712..0000000 --- a/lib/pusher-js/core/transports/assistant_to_the_transport_manager.dart +++ /dev/null @@ -1,43 +0,0 @@ -@JS() -library core.transports.assistant_to_the_transport_manager; - -import "package:js/js.dart"; -import "transport_manager.dart" show TransportManager; -import "transport.dart" show Transport; -import "ping_delay_options.dart" show PingDelayOptions; -import "transport_connection.dart" show TransportConnection; - -/// Creates transport connections monitored by a transport manager. -/// When a transport is closed, it might mean the environment does not support -/// it. It's possible that messages get stuck in an intermediate buffer or -/// proxies terminate inactive connections. To combat these problems, -/// assistants monitor the connection lifetime, report unclean exits and -/// adjust ping timeouts to keep the connection active. The decision to disable -/// a transport is the manager's responsibility. -@JS() -class AssistantToTheTransportManager { - // @Ignore - AssistantToTheTransportManager.fakeConstructor$(); - external TransportManager get manager; - external set manager(TransportManager v); - external Transport get transport; - external set transport(Transport v); - external num get minPingDelay; - external set minPingDelay(num v); - external num get maxPingDelay; - external set maxPingDelay(num v); - external num get pingDelay; - external set pingDelay(num v); - external factory AssistantToTheTransportManager( - TransportManager manager, Transport transport, PingDelayOptions options); - - /// Creates a transport connection. - /// This function has the same API as Transport#createConnection. - external TransportConnection createConnection( - String name, num priority, String key, Object options); - - /// Returns whether the transport is supported in the environment. - /// This function has the same API as Transport#isSupported. Might return false - /// when the manager decides to kill the transport. - external bool isSupported(String environment); -} diff --git a/lib/pusher-js/core/transports/ping_delay_options.dart b/lib/pusher-js/core/transports/ping_delay_options.dart deleted file mode 100644 index fc63fdb..0000000 --- a/lib/pusher-js/core/transports/ping_delay_options.dart +++ /dev/null @@ -1,19 +0,0 @@ -@JS() -library core.transports.ping_delay_options; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class PingDelayOptions { - external num get minPingDelay; - external set minPingDelay(num v); - external num get maxPingDelay; - external set maxPingDelay(num v); - external num get pingDelay; - external set pingDelay(num v); - external factory PingDelayOptions( - {num minPingDelay, num maxPingDelay, num pingDelay}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/transport.dart b/lib/pusher-js/core/transports/transport.dart deleted file mode 100644 index 7e45e55..0000000 --- a/lib/pusher-js/core/transports/transport.dart +++ /dev/null @@ -1,30 +0,0 @@ -@JS() -library core.transports.transport; - -import "package:js/js.dart"; -import "transport_hooks.dart" show TransportHooks; -import "transport_connection.dart" show TransportConnection; - -/// Provides interface for transport connection instantiation. -/// Takes transport-specific hooks as the only argument, which allow checking -/// for transport support and creating its connections. -/// Supported hooks: * - file - the name of the file to be fetched during initialization -/// - urls - URL scheme to be used by transport -/// - handlesActivityCheck - true when the transport handles activity checks -/// - supportsPing - true when the transport has a ping/activity API -/// - isSupported - tells whether the transport is supported in the environment -/// - getSocket - creates a WebSocket-compatible transport socket -/// See transports.js for specific implementations. -@JS() -class Transport { - external TransportHooks get hooks; - external set hooks(TransportHooks v); - external factory Transport(TransportHooks hooks); - - /// Returns whether the transport is supported in the environment. - external bool isSupported(dynamic environment); - - /// Creates a transport connection. - external TransportConnection createConnection( - String name, num priority, String key, dynamic options); -} diff --git a/lib/pusher-js/core/transports/transport_connection.dart b/lib/pusher-js/core/transports/transport_connection.dart deleted file mode 100644 index 8ea111c..0000000 --- a/lib/pusher-js/core/transports/transport_connection.dart +++ /dev/null @@ -1,85 +0,0 @@ -@JS() -library core.transports.transport_connection; - -import "package:js/js.dart"; -import "../events/dispatcher.dart" show Dispatcher; -import "transport_hooks.dart" show TransportHooks; -import "transport_connection_options.dart" show TransportConnectionOptions; -import "../timeline/timeline.dart" show Timeline; -import "../socket.dart" show Socket; - -/// Provides universal API for transport connections. -/// Transport connection is a low-level object that wraps a connection method -/// and exposes a simple evented interface for the connection state and -/// messaging. It does not implement Pusher-specific WebSocket protocol. -/// Additionally, it fetches resources needed for transport to work and exposes -/// an interface for querying transport features. -/// States: -/// - new - initial state after constructing the object -/// - initializing - during initialization phase, usually fetching resources -/// - intialized - ready to establish a connection -/// - connection - when connection is being established -/// - open - when connection ready to be used -/// - closed - after connection was closed be either side -/// Emits: -/// - error - after the connection raised an error -/// Options: -/// - useTLS - whether connection should be over TLS -/// - hostTLS - host to connect to when connection is over TLS -/// - hostNonTLS - host to connect to when connection is over TLS -@JS() -class TransportConnection extends Dispatcher { - external TransportHooks get hooks; - external set hooks(TransportHooks v); - external String get name; - external set name(String v); - external num get priority; - external set priority(num v); - external String get key; - external set key(String v); - external TransportConnectionOptions get options; - external set options(TransportConnectionOptions v); - external String get state; - external set state(String v); - external Timeline get timeline; - external set timeline(Timeline v); - external num get activityTimeout; - external set activityTimeout(num v); - external num get id; - external set id(num v); - external Socket get socket; - external set socket(Socket v); - external Function get beforeOpen; - external set beforeOpen(Function v); - external Function get initialize; - external set initialize(Function v); - external factory TransportConnection(TransportHooks hooks, String name, - num priority, String key, TransportConnectionOptions options); - - /// Checks whether the transport handles activity checks by itself. - external bool handlesActivityChecks(); - - /// Checks whether the transport supports the ping/pong API. - external bool supportsPing(); - - /// Tries to establish a connection. - external bool connect(); - - /// Closes the connection. - external bool close(); - - /// Sends data over the open connection. - external bool send(dynamic data); - - /// Sends a ping if the connection is open and transport supports it. - external ping(); - external onOpen(); - external onError(error); - external onClose([dynamic closeEvent]); - external onMessage(message); - external onActivity(); - external bindListeners(); - external unbindListeners(); - external changeState(String state, [dynamic params]); - external dynamic buildTimelineMessage(message); -} diff --git a/lib/pusher-js/core/transports/transport_connection_options.dart b/lib/pusher-js/core/transports/transport_connection_options.dart deleted file mode 100644 index 9e751d8..0000000 --- a/lib/pusher-js/core/transports/transport_connection_options.dart +++ /dev/null @@ -1,18 +0,0 @@ -@JS() -library core.transports.transport_connection_options; - -import "package:js/js.dart"; -import "../timeline/timeline.dart" show Timeline; - -@anonymous -@JS() -abstract class TransportConnectionOptions { - external Timeline get timeline; - external set timeline(Timeline v); - external num get activityTimeout; - external set activityTimeout(num v); - external factory TransportConnectionOptions( - {Timeline timeline, num activityTimeout}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/transport_hooks.dart b/lib/pusher-js/core/transports/transport_hooks.dart deleted file mode 100644 index 9981064..0000000 --- a/lib/pusher-js/core/transports/transport_hooks.dart +++ /dev/null @@ -1,26 +0,0 @@ -@JS() -library core.transports.transport_hooks; - -import "package:js/js.dart"; -import "url_scheme.dart" show URLScheme; -import "../socket.dart" show Socket; - -@anonymous -@JS() -abstract class TransportHooks { - external String get file; - external set file(String v); - external URLScheme get urls; - external set urls(URLScheme v); - external bool get handlesActivityChecks; - external set handlesActivityChecks(bool v); - external bool get supportsPing; - external set supportsPing(bool v); - external bool isInitialized(); - external bool isSupported([dynamic environment]); - external Socket getSocket(String url, [dynamic options]); - external Function get beforeOpen; - external set beforeOpen(Function v); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/transport_manager.dart b/lib/pusher-js/core/transports/transport_manager.dart deleted file mode 100644 index 7f99476..0000000 --- a/lib/pusher-js/core/transports/transport_manager.dart +++ /dev/null @@ -1,42 +0,0 @@ -@JS() -library core.transports.transport_manager; - -import "package:js/js.dart"; -import "ping_delay_options.dart" show PingDelayOptions; -import "assistant_to_the_transport_manager.dart" - show AssistantToTheTransportManager; -import "transport.dart" show Transport; - -@anonymous -@JS() -abstract class TransportManagerOptions implements PingDelayOptions { - external num get lives; - external set lives(num v); - external factory TransportManagerOptions( - {num lives, num minPingDelay, num maxPingDelay, num pingDelay}); -} - -/// Keeps track of the number of lives left for a transport. -/// In the beginning of a session, transports may be assigned a number of -/// lives. When an AssistantToTheTransportManager instance reports a transport -/// connection closed uncleanly, the transport loses a life. When the number -/// of lives drops to zero, the transport gets disabled by its manager. -@JS() -class TransportManager { - // @Ignore - TransportManager.fakeConstructor$(); - external TransportManagerOptions get options; - external set options(TransportManagerOptions v); - external num get livesLeft; - external set livesLeft(num v); - external factory TransportManager(TransportManagerOptions options); - - /// Creates a assistant for the transport. - external AssistantToTheTransportManager getAssistant(Transport transport); - - /// Returns whether the transport has any lives left. - external bool isAlive(); - - /// Takes one life from the transport. - external reportDeath(); -} diff --git a/lib/pusher-js/core/transports/transports_table.dart b/lib/pusher-js/core/transports/transports_table.dart deleted file mode 100644 index cb79b1b..0000000 --- a/lib/pusher-js/core/transports/transports_table.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.transports.transports_table; - -import "package:js/js.dart"; -import "transport.dart" show Transport; - -@anonymous -@JS() -abstract class TransportsTable { - external Transport get ws; - external set ws(Transport v); - external Transport get xhr_streaming; - external set xhr_streaming(Transport v); - external Transport get xdr_streaming; - external set xdr_streaming(Transport v); - external Transport get xhr_polling; - external set xhr_polling(Transport v); - external Transport get xdr_polling; - external set xdr_polling(Transport v); - external Transport get sockjs; - external set sockjs(Transport v); - external factory TransportsTable( - {Transport ws, - Transport xhr_streaming, - Transport xdr_streaming, - Transport xhr_polling, - Transport xdr_polling, - Transport sockjs}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/url_scheme.dart b/lib/pusher-js/core/transports/url_scheme.dart deleted file mode 100644 index 95a9e55..0000000 --- a/lib/pusher-js/core/transports/url_scheme.dart +++ /dev/null @@ -1,28 +0,0 @@ -@JS() -library core.transports.url_scheme; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class URLSchemeParams { - external bool get useTLS; - external set useTLS(bool v); - external String get hostTLS; - external set hostTLS(String v); - external String get hostNonTLS; - external set hostNonTLS(String v); - external String get httpPath; - external set httpPath(String v); - external factory URLSchemeParams( - {bool useTLS, String hostTLS, String hostNonTLS, String httpPath}); -} - -@anonymous -@JS() -abstract class URLScheme { - external String getInitial(String key, dynamic params); - external String getPath(String key, dynamic options); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/transports/url_schemes.dart b/lib/pusher-js/core/transports/url_schemes.dart deleted file mode 100644 index 2fa7b46..0000000 --- a/lib/pusher-js/core/transports/url_schemes.dart +++ /dev/null @@ -1,23 +0,0 @@ -@JS() -library core.transports.url_schemes; - -import "package:js/js.dart"; -import "url_scheme.dart" show URLSchemeParams, URLScheme; - -@JS() -external String getGenericURL( - String baseScheme, URLSchemeParams params, String path); -@JS() -external String getGenericPath(String key, [String queryString]); -@JS() -external URLScheme get ws; -@JS() -external set ws(URLScheme v); -@JS() -external URLScheme get http; -@JS() -external set http(URLScheme v); -@JS() -external URLScheme get sockjs; -@JS() -external set sockjs(URLScheme v); diff --git a/lib/wasm-pusher-js/core/user.dart b/lib/pusher-js/core/user.dart similarity index 100% rename from lib/wasm-pusher-js/core/user.dart rename to lib/pusher-js/core/user.dart diff --git a/lib/pusher-js/core/util.dart b/lib/pusher-js/core/util.dart deleted file mode 100644 index e9156a7..0000000 --- a/lib/pusher-js/core/util.dart +++ /dev/null @@ -1,11 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.util; - -import "package:js/js.dart"; - -@JS() -external get Util; -@JS() -external set Util(v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/utils/collections.dart b/lib/pusher-js/core/utils/collections.dart deleted file mode 100644 index df5e33d..0000000 --- a/lib/pusher-js/core/utils/collections.dart +++ /dev/null @@ -1,119 +0,0 @@ -@JS() -library core.utils.collections; - -import "package:js/js.dart"; - -/// Merges multiple objects into the target argument. -/// For properties that are plain Objects, performs a deep-merge. For the -/// rest it just copies the value of the property. -/// To extend prototypes use it as following: -/// Pusher.Util.extend(Target.prototype, Base.prototype) -/// You can also use it to merge objects without altering them: -/// Pusher.Util.extend({}, object1, object2) -@JS() -external dynamic /*T*/ extend/**/(dynamic target, - [dynamic sources1, - dynamic sources2, - dynamic sources3, - dynamic sources4, - dynamic sources5]); -@JS() -external String stringify(); -@JS() -external num arrayIndexOf(List array, dynamic item); - -/// Applies a function f to all properties of an object. -/// Function f gets 3 arguments passed: -/// - element from the object -/// - key of the element -/// - reference to the object -@JS() -external objectApply(dynamic object, Function f); - -/// Return a list of objects own proerty keys -@JS() -external List keys(dynamic object); - -/// Return a list of object's own property values -@JS() -external List values(dynamic object); - -/// Applies a function f to all elements of an array. -/// Function f gets 3 arguments passed: -/// - element from the array -/// - index of the element -/// - reference to the array -@JS() -external apply(List array, Function f, [dynamic context]); - -/// Maps all elements of the array and returns the result. -/// Function f gets 4 arguments passed: -/// - element from the array -/// - index of the element -/// - reference to the source array -/// - reference to the destination array -@JS() -external List map(List array, Function f); - -/// Maps all elements of the object and returns the result. -/// Function f gets 4 arguments passed: -/// - element from the object -/// - key of the element -/// - reference to the source object -/// - reference to the destination object -@JS() -external dynamic mapObject(dynamic object, Function f); - -/// Filters elements of the array using a test function. -/// Function test gets 4 arguments passed: -/// - element from the array -/// - index of the element -/// - reference to the source array -/// - reference to the destination array -@JS() -external List filter(List array, Function test); - -/// Filters properties of the object using a test function. -/// Function test gets 4 arguments passed: -/// - element from the object -/// - key of the element -/// - reference to the source object -/// - reference to the destination object -@JS() -external filterObject(Object object, Function test); - -/// Flattens an object into a two-dimensional array. -@JS() -external List flatten(Object object); - -/// Checks whether any element of the array passes the test. -/// Function test gets 3 arguments passed: -/// - element from the array -/// - index of the element -/// - reference to the source array -@JS() -external bool any(List array, Function test); - -/// Checks whether all elements of the array pass the test. -/// Function test gets 3 arguments passed: -/// - element from the array -/// - index of the element -/// - reference to the source array -@JS() -external bool all(List array, Function test); -@JS() -external String encodeParamsObject(data); -@JS() -external String buildQueryString(dynamic data); - -/// See https://github.com/douglascrockford/JSON-js/blob/master/cycle.js -/// Remove circular references from an object. Required for JSON.stringify in -/// React Native, which tends to blow up a lot. -@JS() -external dynamic decycleObject(dynamic object); - -/// Provides a cross-browser and cross-platform way to safely stringify objects -/// into JSON. This is particularly necessary for ReactNative, where circular JSON -/// structures throw an exception. -@JS() -external String safeJSONStringify(dynamic source); diff --git a/lib/pusher-js/core/utils/factory.dart b/lib/pusher-js/core/utils/factory.dart deleted file mode 100644 index a636401..0000000 --- a/lib/pusher-js/core/utils/factory.dart +++ /dev/null @@ -1,11 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.utils.factory; - -import "package:js/js.dart"; - -@JS() -external get Factory; -@JS() -external set Factory(v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/utils/timers.dart b/lib/pusher-js/core/utils/timers.dart deleted file mode 100644 index 1f018c7..0000000 --- a/lib/pusher-js/core/utils/timers.dart +++ /dev/null @@ -1,24 +0,0 @@ -@JS() -library core.utils.timers; - -import "package:js/js.dart"; -import "timers/abstract_timer.dart" show Timer; -import "timers/timed_callback.dart" show TimedCallback; - -/// We need to bind clear functions this way to avoid exceptions on IE8 -@JS() -external clearTimeout(timer); -@JS() -external clearInterval(timer); - -/// Cross-browser compatible one-off timer abstraction. -@JS() -class OneOffTimer extends Timer { - external factory OneOffTimer(num delay, TimedCallback callback); -} - -/// Cross-browser compatible periodic timer abstraction. -@JS() -class PeriodicTimer extends Timer { - external factory PeriodicTimer(num delay, TimedCallback callback); -} diff --git a/lib/pusher-js/core/utils/timers/abstract_timer.dart b/lib/pusher-js/core/utils/timers/abstract_timer.dart deleted file mode 100644 index e3a87ac..0000000 --- a/lib/pusher-js/core/utils/timers/abstract_timer.dart +++ /dev/null @@ -1,24 +0,0 @@ -@JS() -library core.utils.timers.abstract_timer; - -import "package:js/js.dart"; -import "scheduling.dart" show Canceller, Scheduler; -import "timed_callback.dart" show TimedCallback; - -@JS() -abstract class Timer { - external Canceller get clear; - external set clear(Canceller v); - external dynamic /*num|void*/ get timer; - external set timer(dynamic /*num|void*/ v); - external factory Timer( - Scheduler set, Canceller clear, num delay, TimedCallback callback); - - /// Returns whether the timer is still running. - external bool isRunning(); - - /// Aborts a timer when it's running. - external ensureAborted(); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/utils/timers/scheduling.dart b/lib/pusher-js/core/utils/timers/scheduling.dart deleted file mode 100644 index 3b52efd..0000000 --- a/lib/pusher-js/core/utils/timers/scheduling.dart +++ /dev/null @@ -1,9 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library core.utils.timers.scheduling; - -import "package:js/js.dart"; - -typedef num Scheduler(TimedCallback, number); -typedef void Canceller(number); /*export type Delay = number;*/ diff --git a/lib/pusher-js/core/utils/timers/timed_callback.dart b/lib/pusher-js/core/utils/timers/timed_callback.dart deleted file mode 100644 index 5c798b2..0000000 --- a/lib/pusher-js/core/utils/timers/timed_callback.dart +++ /dev/null @@ -1,7 +0,0 @@ -@JS() -library core.utils.timers.timed_callback; - -import "package:js/js.dart"; - -typedef dynamic /*num|void*/ TimedCallback( - [number]); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/core/utils/url_store.dart b/lib/pusher-js/core/utils/url_store.dart deleted file mode 100644 index 3f6ad54..0000000 --- a/lib/pusher-js/core/utils/url_store.dart +++ /dev/null @@ -1,12 +0,0 @@ -@JS() -library core.utils.url_store; - -import "package:js/js.dart"; - -/// A place to store help URLs for error messages etc -@JS() -external get urlStore; - -/// Builds a consistent string with links to pusher documentation -@JS() -external get buildLogSuffix; /* WARNING: export assignment not yet supported. */ diff --git a/lib/wasm-pusher-js/error.dart b/lib/pusher-js/error.dart similarity index 100% rename from lib/wasm-pusher-js/error.dart rename to lib/pusher-js/error.dart diff --git a/lib/pusher-js/runtimes/interface.dart b/lib/pusher-js/runtimes/interface.dart deleted file mode 100644 index aed990c..0000000 --- a/lib/pusher-js/runtimes/interface.dart +++ /dev/null @@ -1,70 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library interface; - -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 AuthTransport; -import "../core/timeline/timeline_transport.dart" show TimelineTransport; -import "../core/http/ajax.dart" show Ajax; -import "../core/socket.dart" show Socket; -import "../core/reachability.dart" show Reachability; -import "../core/strategies/strategy.dart" show Strategy; -import "../core/config.dart" show Config; -import "../core/strategies/strategy_options.dart" show StrategyOptions; -import "../core/transports/transports_table.dart" show TransportsTable; -import "../core/http/http_factory.dart" show HTTPFactory; -import "../core/http/http_request.dart" show HTTPRequest; -import "web/dom/jsonp_request.dart" show JSONPRequest; - -/// This interface is implemented in web/runtime, node/runtime, react-native/runtime -/// and worker/runtime. Its job is to be the only point of contact to platform-specific -/// code for the core library. When the core library imports "runtime", Webpack will -/// look for src/runtimes//runtime.ts. This is how PusherJS keeps -/// core and platform-specific code separate. -@anonymous -@JS() -abstract class Runtime { - external void setup( - dynamic - /*{ - new (key: string, options: any): Pusher; - ready(): void; - }*/ - PusherClass); - external String getProtocol(); - external Map getAuthorizers(); - external dynamic getLocalStorage(); - external TimelineTransport timelineTransport; - //external set TimelineTransport(TimelineTransport v); - external Ajax createXHR(); - external Socket createWebSocket(String url); - external Reachability getNetwork(); - external Strategy getDefaultStrategy( - Config config, StrategyOptions options, Function defineTransport); - external TransportsTable get Transports; - external set Transports(TransportsTable v); - external Socket getWebSocketAPI(); - external Ajax getXHRAPI(); - external void addUnloadListener(Function listener); - external void removeUnloadListener(Function listener); - external Function get transportConnectionInitializer; - external set transportConnectionInitializer(Function v); - external HTTPFactory httpFactory; - external bool isXHRSupported(); - external HTTPRequest createSocketRequest(String method, String url); - - /// these methods/types are only implemented in the web Runtime, so they're - /// optional but must be included in the interface - external Document getDocument(); - external dynamic createScriptRequest(String url); - external JSONPRequest createJSONPRequest(String url, dynamic data); - external ScriptReceiverFactory get ScriptReceivers; - external set ScriptReceivers(ScriptReceiverFactory v); - external bool isXDRSupported([bool useTLS]); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/auth/xhr_auth.dart b/lib/pusher-js/runtimes/isomorphic/auth/xhr_auth.dart deleted file mode 100644 index 5a415e0..0000000 --- a/lib/pusher-js/runtimes/isomorphic/auth/xhr_auth.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library runtimes.isomorphic.auth.xhr_auth; - -import "package:js/js.dart"; -import "../../../core/auth/auth_transports.dart" show AuthTransport; - -@JS() -external AuthTransport get ajax; -@JS() -external set ajax( - AuthTransport v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/default_strategy.dart b/lib/pusher-js/runtimes/isomorphic/default_strategy.dart deleted file mode 100644 index 5c08646..0000000 --- a/lib/pusher-js/runtimes/isomorphic/default_strategy.dart +++ /dev/null @@ -1,13 +0,0 @@ -@JS() -library runtimes.isomorphic.default_strategy; - -import "package:js/js.dart"; -import "../../core/strategies/strategy.dart" show Strategy; - -@JS() -external testSupportsStrategy(Strategy strategy); -@JS() -external get getDefaultStrategy; -@JS() -external set getDefaultStrategy( - v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/http/http.dart b/lib/pusher-js/runtimes/isomorphic/http/http.dart deleted file mode 100644 index 32241b8..0000000 --- a/lib/pusher-js/runtimes/isomorphic/http/http.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.isomorphic.http.http; - -import "package:js/js.dart"; -import "../../../core/http/http_factory.dart" show HTTPFactory; - -@JS() -external HTTPFactory get HTTP; -@JS() -external set HTTP( - HTTPFactory v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/http/http_xhr_request.dart b/lib/pusher-js/runtimes/isomorphic/http/http_xhr_request.dart deleted file mode 100644 index 1de0023..0000000 --- a/lib/pusher-js/runtimes/isomorphic/http/http_xhr_request.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library runtimes.isomorphic.http.http_xhr_request; - -import "package:js/js.dart"; -import "../../../core/http/request_hooks.dart" show RequestHooks; - -@JS() -external RequestHooks get hooks; -@JS() -external set hooks( - RequestHooks v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/runtime.dart b/lib/pusher-js/runtimes/isomorphic/runtime.dart deleted file mode 100644 index 9b5bf34..0000000 --- a/lib/pusher-js/runtimes/isomorphic/runtime.dart +++ /dev/null @@ -1,12 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.isomorphic.runtime; - -import "package:js/js.dart"; - -@JS() -external dynamic get Isomorphic; -@JS() -external set Isomorphic( - dynamic v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/timeline/xhr_timeline.dart b/lib/pusher-js/runtimes/isomorphic/timeline/xhr_timeline.dart deleted file mode 100644 index ceab003..0000000 --- a/lib/pusher-js/runtimes/isomorphic/timeline/xhr_timeline.dart +++ /dev/null @@ -1,13 +0,0 @@ -@JS() -library runtimes.isomorphic.timeline.xhr_timeline; - -import "package:js/js.dart"; - -@JS() -external get getAgent; -@JS() -external set getAgent(v); -@JS() -external get xhr; -@JS() -external set xhr(v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/isomorphic/transports/transports.dart b/lib/pusher-js/runtimes/isomorphic/transports/transports.dart deleted file mode 100644 index acd7b5a..0000000 --- a/lib/pusher-js/runtimes/isomorphic/transports/transports.dart +++ /dev/null @@ -1,48 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.isomorphic.transports.transports; - -import "package:js/js.dart"; -import "../../../core/transports/transports_table.dart" show TransportsTable; - -/// WebSocket transport. -/// Uses native WebSocket implementation, including MozWebSocket supported by -/// earlier Firefox versions. -@JS() -external get WSTransport; -@JS() -external set WSTransport(v); -@JS() -external get httpConfiguration; -@JS() -external set httpConfiguration(v); -@JS() -external get streamingConfiguration; -@JS() -external set streamingConfiguration(v); -@JS() -external get pollingConfiguration; -@JS() -external set pollingConfiguration(v); -@JS() -external get xhrConfiguration; -@JS() -external set xhrConfiguration(v); - -/// HTTP streaming transport using CORS-enabled XMLHttpRequest. -@JS() -external get XHRStreamingTransport; -@JS() -external set XHRStreamingTransport(v); - -/// HTTP long-polling transport using CORS-enabled XMLHttpRequest. -@JS() -external get XHRPollingTransport; -@JS() -external set XHRPollingTransport(v); -@JS() -external TransportsTable get Transports; -@JS() -external set Transports( - TransportsTable v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/node/net_info.dart b/lib/pusher-js/runtimes/node/net_info.dart deleted file mode 100644 index 53e2495..0000000 --- a/lib/pusher-js/runtimes/node/net_info.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: non_constant_identifier_names, annotate_overrides - -@JS() -library runtimes.node.net_info; - -import "package:js/js.dart"; -import "../../core/events/dispatcher.dart" show Dispatcher; -import "../../core/reachability.dart" show Reachability; - -@JS() -class NetInfo extends Dispatcher implements Reachability { - external factory NetInfo([Function failThrough]); - external bool isOnline(); -} - -@JS() -external get Network; -@JS() -external set Network(v); diff --git a/lib/pusher-js/runtimes/react-native/net_info.dart b/lib/pusher-js/runtimes/react-native/net_info.dart deleted file mode 100644 index c6e1218..0000000 --- a/lib/pusher-js/runtimes/react-native/net_info.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.react_native.net_info; - -import "package:js/js.dart"; -import "../../core/events/dispatcher.dart" show Dispatcher; -import "../../core/reachability.dart" show Reachability; - -@JS() -external bool hasOnlineConnectionState(connectionState); - -@JS() -class NetInfo extends Dispatcher implements Reachability { - external bool get online; - external set online(bool v); - external factory NetInfo(); - @override - external bool isOnline(); -} - -@JS() -external get Network; -@JS() -external set Network(v); diff --git a/lib/pusher-js/runtimes/web/auth/jsonp_auth.dart b/lib/pusher-js/runtimes/web/auth/jsonp_auth.dart deleted file mode 100644 index b31a5da..0000000 --- a/lib/pusher-js/runtimes/web/auth/jsonp_auth.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library runtimes.web.auth.jsonp_auth; - -import "package:js/js.dart"; -import "../../../core/auth/auth_transports.dart" show AuthTransport; - -@JS() -external AuthTransport get jsonp; -@JS() -external set jsonp( - AuthTransport v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/browser.dart b/lib/pusher-js/runtimes/web/browser.dart deleted file mode 100644 index f8b951a..0000000 --- a/lib/pusher-js/runtimes/web/browser.dart +++ /dev/null @@ -1,42 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.browser; - -import 'dart:html'; - -import "package:js/js.dart"; -import "../interface.dart" show Runtime; -import "dom/script_receiver_factory.dart" show ScriptReceiverFactory; -import "dom/jsonp_request.dart" show JSONPRequest; -import "dom/script_request.dart" show ScriptRequest; -import "../../core/http/ajax.dart" show Ajax; - -@anonymous -@JS() -abstract class Browser implements Runtime { - /// for jsonp auth - external num get nextAuthCallbackID; - external set nextAuthCallbackID(num v); - external dynamic get auth_callbacks; - external set auth_callbacks(dynamic v); - @override - external ScriptReceiverFactory get ScriptReceivers; - @override - external set ScriptReceivers(ScriptReceiverFactory v); - external ScriptReceiverFactory get DependenciesReceivers; - external set DependenciesReceivers(ScriptReceiverFactory v); - external onDocumentBody(Function callback); - @override - external Document getDocument(); - @override - external JSONPRequest createJSONPRequest(String url, dynamic data); - @override - external ScriptRequest createScriptRequest(String src); - @override - external bool isXDRSupported([bool useTLS]); - external Ajax createXMLHttpRequest(); - external Ajax createMicrosoftXHR(); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/default_strategy.dart b/lib/pusher-js/runtimes/web/default_strategy.dart deleted file mode 100644 index 382192b..0000000 --- a/lib/pusher-js/runtimes/web/default_strategy.dart +++ /dev/null @@ -1,13 +0,0 @@ -@JS() -library runtimes.web.default_strategy; - -import "package:js/js.dart"; -import "../../core/strategies/strategy.dart" show Strategy; - -@JS() -external testSupportsStrategy(Strategy strategy); -@JS() -external get getDefaultStrategy; -@JS() -external set getDefaultStrategy( - v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/dom/dependencies.dart b/lib/pusher-js/runtimes/web/dom/dependencies.dart deleted file mode 100644 index 4c18e8f..0000000 --- a/lib/pusher-js/runtimes/web/dom/dependencies.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.dom.dependencies; - -import "package:js/js.dart"; - -@JS() -external get DependenciesReceivers; -@JS() -external set DependenciesReceivers(v); -@JS() -external get Dependencies; -@JS() -external set Dependencies(v); diff --git a/lib/pusher-js/runtimes/web/dom/dependency_loader.dart b/lib/pusher-js/runtimes/web/dom/dependency_loader.dart deleted file mode 100644 index be08403..0000000 --- a/lib/pusher-js/runtimes/web/dom/dependency_loader.dart +++ /dev/null @@ -1,35 +0,0 @@ -@JS() -library runtimes.web.dom.dependency_loader; - -import "package:js/js.dart"; -import "script_receiver_factory.dart" show ScriptReceiverFactory; - -/// Handles loading dependency files. -/// Dependency loaders don't remember whether a resource has been loaded or -/// not. It is caller's responsibility to make sure the resource is not loaded -/// twice. This is because it's impossible to detect resource loading status -/// without knowing its content. -/// Options: -/// - cdn_http - url to HTTP CND -/// - cdn_https - url to HTTPS CDN -/// - version - version of pusher-js -/// - suffix - suffix appended to all names of dependency files -@JS() -class DependencyLoader { - external dynamic get options; - external set options(dynamic v); - external ScriptReceiverFactory get receivers; - external set receivers(ScriptReceiverFactory v); - external dynamic get loading; - external set loading(dynamic v); - external factory DependencyLoader(dynamic options); - - /// Loads the dependency from CDN. - external load(String name, dynamic options, Function callback); - - /// Returns a root URL for pusher-js CDN. - external String getRoot(dynamic options); - - /// Returns a full path to a dependency file. - external String getPath(String name, dynamic options); -} diff --git a/lib/pusher-js/runtimes/web/dom/jsonp_request.dart b/lib/pusher-js/runtimes/web/dom/jsonp_request.dart deleted file mode 100644 index b04e7d3..0000000 --- a/lib/pusher-js/runtimes/web/dom/jsonp_request.dart +++ /dev/null @@ -1,31 +0,0 @@ -@JS() -library runtimes.web.dom.jsonp_request; - -import "package:js/js.dart"; -import "script_request.dart" show ScriptRequest; -import "script_receiver.dart" show ScriptReceiver; - -/// Sends data via JSONP. -/// Data is a key-value map. Its values are JSON-encoded and then passed -/// through base64. Finally, keys and encoded values are appended to the query -/// string. -/// The class itself does not guarantee raising errors on failures, as it's not -/// possible to support such feature on all browsers. Instead, JSONP endpoint -/// should call back in a way that's easy to distinguish from browser calls, -/// for example by passing a second argument to the receiver. -@JS() -class JSONPRequest { - external String get url; - external set url(String v); - external dynamic get data; - external set data(dynamic v); - external ScriptRequest get request; - external set request(ScriptRequest v); - external factory JSONPRequest(String url, dynamic data); - - /// Sends the actual JSONP request. - external send(ScriptReceiver receiver); - - /// Cleans up the DOM remains of the JSONP request. - external cleanup(); -} diff --git a/lib/pusher-js/runtimes/web/dom/script_receiver.dart b/lib/pusher-js/runtimes/web/dom/script_receiver.dart deleted file mode 100644 index b942bd3..0000000 --- a/lib/pusher-js/runtimes/web/dom/script_receiver.dart +++ /dev/null @@ -1,21 +0,0 @@ -@JS() -library runtimes.web.dom.script_receiver; - -import "package:js/js.dart"; - -@anonymous -@JS() -abstract class ScriptReceiver { - external num get number; - external set number(num v); - external String get id; - external set id(String v); - external String get name; - external set name(String v); - external Function get callback; - external set callback(Function v); - external factory ScriptReceiver( - {num number, String id, String name, Function callback}); -} - -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/dom/script_receiver_factory.dart b/lib/pusher-js/runtimes/web/dom/script_receiver_factory.dart deleted file mode 100644 index bb7f36e..0000000 --- a/lib/pusher-js/runtimes/web/dom/script_receiver_factory.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.dom.script_receiver_factory; - -import "package:js/js.dart"; -import "script_receiver.dart" show ScriptReceiver; - -/// Builds receivers for JSONP and Script requests. -/// Each receiver is an object with following fields: -/// - number - unique (for the factory instance), numerical id of the receiver -/// - id - a string ID that can be used in DOM attributes -/// - name - name of the function triggering the receiver -/// - callback - callback function -/// Receivers are triggered only once, on the first callback call. -/// Receivers can be called by their name or by accessing factory object -/// by the number key. -@JS() -class ScriptReceiverFactory { - external num get lastId; - external set lastId(num v); - external String get prefix; - external set prefix(String v); - external String get name; - external set name(String v); - external factory ScriptReceiverFactory(String prefix, String name); - external ScriptReceiver create(Function callback); - external remove(ScriptReceiver receiver); -} - -@JS() -external get ScriptReceivers; -@JS() -external set ScriptReceivers(v); diff --git a/lib/pusher-js/runtimes/web/dom/script_request.dart b/lib/pusher-js/runtimes/web/dom/script_request.dart deleted file mode 100644 index 35f1e0b..0000000 --- a/lib/pusher-js/runtimes/web/dom/script_request.dart +++ /dev/null @@ -1,25 +0,0 @@ -@JS() -library runtimes.web.dom.script_request; - -import "package:js/js.dart"; -import "script_receiver.dart" show ScriptReceiver; - -/// Sends a generic HTTP GET request using a script tag. -/// By constructing URL in a specific way, it can be used for loading -/// JavaScript resources or JSONP requests. It can notify about errors, but -/// only in certain environments. Please take care of monitoring the state of -/// the request yourself. -@JS() -class ScriptRequest { - external String get src; - external set src(String v); - external dynamic get script; - external set script(dynamic v); - external dynamic get errorScript; - external set errorScript(dynamic v); - external factory ScriptRequest(String src); - external send(ScriptReceiver receiver); - - /// Cleans up the DOM remains of the script request. - external cleanup(); -} diff --git a/lib/pusher-js/runtimes/web/http/http.dart b/lib/pusher-js/runtimes/web/http/http.dart deleted file mode 100644 index 57465b2..0000000 --- a/lib/pusher-js/runtimes/web/http/http.dart +++ /dev/null @@ -1,5 +0,0 @@ -@JS() -library runtimes.web.http.http; - -import "package:js/js.dart"; -/* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/http/http_xdomain_request.dart b/lib/pusher-js/runtimes/web/http/http_xdomain_request.dart deleted file mode 100644 index 59bceb8..0000000 --- a/lib/pusher-js/runtimes/web/http/http_xdomain_request.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library runtimes.web.http.http_xdomain_request; - -import "package:js/js.dart"; -import "../../../core/http/request_hooks.dart" show RequestHooks; - -@JS() -external RequestHooks get hooks; -@JS() -external set hooks( - RequestHooks v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/net_info.dart b/lib/pusher-js/runtimes/web/net_info.dart deleted file mode 100644 index 95e3247..0000000 --- a/lib/pusher-js/runtimes/web/net_info.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.net_info; - -import "package:js/js.dart"; -import "../../core/events/dispatcher.dart" show Dispatcher; -import "../../core/reachability.dart" show Reachability; - -/// Really basic interface providing network availability info. -/// Emits: -/// - online - when browser goes online -/// - offline - when browser goes offline -@JS() -class NetInfo extends Dispatcher implements Reachability { - external factory NetInfo(); - - /// Returns whether browser is online or not - /// Offline means definitely offline (no connection to router). - /// Inverse does NOT mean definitely online (only currently supported in Safari - /// and even there only means the device has a connection to the router). - @override - external bool isOnline(); -} - -@JS() -external get Network; -@JS() -external set Network(v); diff --git a/lib/pusher-js/runtimes/web/runtime.dart b/lib/pusher-js/runtimes/web/runtime.dart deleted file mode 100644 index 94d177e..0000000 --- a/lib/pusher-js/runtimes/web/runtime.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.runtime; - -import "package:js/js.dart"; -import "browser.dart" show Browser; - -@JS() -external Browser get Runtime; -@JS() -external set Runtime( - Browser v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/timeline/jsonp_timeline.dart b/lib/pusher-js/runtimes/web/timeline/jsonp_timeline.dart deleted file mode 100644 index 5595101..0000000 --- a/lib/pusher-js/runtimes/web/timeline/jsonp_timeline.dart +++ /dev/null @@ -1,13 +0,0 @@ -@JS() -library runtimes.web.timeline.jsonp_timeline; - -import "package:js/js.dart"; - -@JS() -external get getAgent; -@JS() -external set getAgent(v); -@JS() -external get jsonp; -@JS() -external set jsonp(v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/web/transports/transports.dart b/lib/pusher-js/runtimes/web/transports/transports.dart deleted file mode 100644 index ba882ed..0000000 --- a/lib/pusher-js/runtimes/web/transports/transports.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.web.transports.transports; - -import "package:js/js.dart"; - -@JS() -external get SockJSTransport; -@JS() -external set SockJSTransport(v); -@JS() -external get xdrConfiguration; -@JS() -external set xdrConfiguration(v); - -/// HTTP streaming transport using XDomainRequest (IE 8,9). -@JS() -external get XDRStreamingTransport; -@JS() -external set XDRStreamingTransport(v); - -/// HTTP long-polling transport using XDomainRequest (IE 8,9). -@JS() -external get XDRPollingTransport; -@JS() -external set XDRPollingTransport( - v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/worker/auth/fetch_auth.dart b/lib/pusher-js/runtimes/worker/auth/fetch_auth.dart deleted file mode 100644 index f2b4eb4..0000000 --- a/lib/pusher-js/runtimes/worker/auth/fetch_auth.dart +++ /dev/null @@ -1,11 +0,0 @@ -@JS() -library runtimes.worker.auth.fetch_auth; - -import "package:js/js.dart"; -import "../../../core/auth/auth_transports.dart" show AuthTransport; - -@JS() -external AuthTransport get fetchAuth; -@JS() -external set fetchAuth( - AuthTransport v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher-js/runtimes/worker/net_info.dart b/lib/pusher-js/runtimes/worker/net_info.dart deleted file mode 100644 index b07e251..0000000 --- a/lib/pusher-js/runtimes/worker/net_info.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: non_constant_identifier_names - -@JS() -library runtimes.worker.net_info; - -import "package:js/js.dart"; -import "../../core/events/dispatcher.dart" show Dispatcher; -import "../../core/reachability.dart" show Reachability; - -@JS() -class NetInfo extends Dispatcher implements Reachability { - external factory NetInfo([Function failThrough]); - @override - external bool isOnline(); -} - -@JS() -external get Network; -@JS() -external set Network(v); diff --git a/lib/pusher-js/runtimes/worker/timeline/fetch_timeline.dart b/lib/pusher-js/runtimes/worker/timeline/fetch_timeline.dart deleted file mode 100644 index 7cdf9d2..0000000 --- a/lib/pusher-js/runtimes/worker/timeline/fetch_timeline.dart +++ /dev/null @@ -1,14 +0,0 @@ -@JS() -library runtimes.worker.timeline.fetch_timeline; - -import "package:js/js.dart"; - -@JS() -external get getAgent; -@JS() -external set getAgent(v); -@JS() -external get fetchTimeline; -@JS() -external set fetchTimeline( - v); /* WARNING: export assignment not yet supported. */ diff --git a/lib/pusher_channels_flutter_wasm.dart b/lib/pusher_channels_flutter_wasm.dart deleted file mode 100644 index 403a5c8..0000000 --- a/lib/pusher_channels_flutter_wasm.dart +++ /dev/null @@ -1,306 +0,0 @@ -import 'dart:async'; -import 'dart:js_interop'; - -// In order to *not* need this ignore, consider extracting the 'web' version -// of your plugin as a separate package, instead of inlining it in the same -// package as the core of your plugin. -// ignore: avoid_web_libraries_in_flutter -import 'package:flutter/services.dart'; -import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:js/js_util.dart' as js_util; -import 'package:pusher_channels_flutter/wasm-pusher-js/core/auth/options.dart'; - -import 'wasm-pusher-js/core/auth/deprecated_channel_authorizer.dart'; -import 'wasm-pusher-js/core/channels/channel.dart'; -import 'wasm-pusher-js/core/channels/presence_channel.dart'; -import 'wasm-pusher-js/core/options.dart'; -import 'wasm-pusher-js/core/pusher.dart'; -import 'wasm-pusher-js/error.dart'; - -@JS('JSON.stringify') -external String stringify(JSObject obj); - -@JS('Object.keys') -external JSArray objectKeys(JSObject object); - -bool _isBasicType(value) { - if (value == null || value is num || value is bool || value is String) { - return true; - } - return false; -} - -T dartify(dynamic jsObject) { - if (_isBasicType(jsObject)) { - return jsObject as T; - } - if (jsObject is List) { - return jsObject.map(dartify).toList() as T; - } - var keys = objectKeys(jsObject); - var result = {}; - for (var key in keys.toDart.map((e) => e.toDart)) { - result[key] = dartify(js_util.getProperty(jsObject, key)); - } - return result as T; -} - -/// A web implementation of the PusherChannelsFlutter plugin. -class PusherChannelsFlutterWasm { - Pusher? pusher; - MethodChannel? methodChannel; - - static void registerWith(Registrar registrar) { - final pluginInstance = PusherChannelsFlutterWasm(); - pluginInstance.methodChannel = MethodChannel( - 'pusher_channels_flutter', - const StandardMethodCodec(), - registrar, - ); - pluginInstance.methodChannel! - .setMethodCallHandler(pluginInstance.handleMethodCall); - } - - Future handleMethodCall(MethodCall call) async { - switch (call.method) { - case 'init': - init(call); - break; - case 'connect': - assertPusher(); - pusher!.connect(); - break; - case 'disconnect': - assertPusher(); - pusher!.disconnect(); - break; - case 'subscribe': - subscribe(call); - break; - case 'unsubscribe': - unsubscribe(call); - break; - case 'trigger': - trigger(call); - break; - case 'getSocketId': - return pusher!.connection.socketId; - default: - throw PlatformException( - code: 'Unimplemented', - details: - 'pusher_channels for web doesn\'t implement \'${call.method}\'', - ); - } - } - - void assertPusher() { - if (pusher == null) { - throw ArgumentError.notNull('Pusher not initialized'); - } - } - - void assertChannel(String channelName) { - if (pusher!.channel(channelName) == null) { - throw ArgumentError.notNull('Not subscribed to channel: $channelName'); - } - } - - void onError(JSAny jsError) { - final Map error = dartify>(jsError); - - print('onError, error: $error'); - - if (error['type'] == 'PusherError') { - methodChannel!.invokeMethod('onError', { - 'message': error['data']?['message'], - 'code': error['data']?['code'], - 'error': error, - }); - } - } - - void onMessage(JSAny jsMessage) { - final Map msg = dartify>(jsMessage); - final String event = msg['event'] ?? ''; - final String channel = msg['channel'] ?? ''; - final Map data = msg['data'] ?? {}; - String? userId = data['user_id']; - final Map? userInfo = data['user_info']; - - print('onMessage, event: $event, channel: $channel, data: $data'); - - if (event == 'pusher_internal:subscription_error') { - methodChannel!.invokeMethod( - 'onSubscriptionError', {'message': msg['error'], 'error': data}); - } else if (event == 'pusher_internal:member_added') { - methodChannel!.invokeMethod('onMemberAdded', { - 'channelName': channel, - 'user': { - 'userId': userId, - 'userInfo': userInfo, - } - }); - } else if (event == 'pusher_internal:member_removed') { - methodChannel!.invokeMethod('onMemberRemoved', { - 'channelName': channel, - 'user': { - 'userId': userId, - 'userInfo': userInfo, - } - }); - } else { - if (event == 'pusher_internal:subscription_succeeded') { - if (channel.startsWith('presence-')) { - final presenceChannel = pusher!.channel(channel) as PresenceChannel; - final id = presenceChannel.members.myId; - if (id.isA()) { - userId = (id as JSString).toDart; - } - } - } - methodChannel!.invokeMethod('onEvent', { - 'channelName': channel, - 'eventName': event, - 'data': data, - 'userId': userId, - }); - } - } - - void onStateChange(JSAny? jsState) { - final Map state = - dartify>(jsState ?? {}); - final String current = state['current'] ?? ''; - final String previous = state['previous'] ?? ''; - methodChannel!.invokeMethod('onConnectionStateChange', { - 'currentState': current, - 'previousState': previous, - }); - } - - void onConnected(JSAny jsMessage) {} - - void onDisconnected() {} - - DeprecatedChannelAuthorizer onAuthorizer( - Channel channel, - DeprecatedAuthorizerOptions options, - ) => - DeprecatedChannelAuthorizer.create( - FlutterDartDeprecatedChannelAuthorizer( - methodChannel: methodChannel!, - channel: channel, - options: options, - ), - ); - - void subscribe(MethodCall call) { - assertPusher(); - var channelName = call.arguments['channelName']; - pusher!.subscribe(channelName); - } - - void unsubscribe(MethodCall call) { - var channelName = call.arguments['channelName']; - var channel = pusher!.channel(channelName); - pusher!.unsubscribe(channelName); - channel?.unbindAll(); - } - - void trigger(MethodCall call) { - var channelName = call.arguments['channelName']; - var channel = pusher!.channel(channelName); - channel?.trigger(call.arguments['eventName'], call.arguments['data']); - } - - void init(MethodCall call) { - if (pusher != null) { - pusher!.unbindAll(); - pusher!.disconnect(); - } - var options = Options(); - if (call.arguments['cluster'] != null) { - options.cluster = call.arguments['cluster']; - } - if (call.arguments['forceTLS'] != null) { - options.forceTLS = call.arguments['forceTLS']; - } - if (call.arguments['pongTimeout'] != null) { - options.pongTimeout = call.arguments['pongTimeout']; - } - if (call.arguments['enableStats'] != null) { - options.enableStats = call.arguments['enableStats']; - } - if (call.arguments['disabledTransports'] != null) { - options.disabledTransports = call.arguments['disabledTransports']; - } - if (call.arguments['enabledTransports'] != null) { - options.enabledTransports = call.arguments['enabledTransports']; - } - if (call.arguments['ignoreNullOrigin'] != null) { - options.ignoreNullOrigin = call.arguments['ignoreNullOrigin']; - } - if (call.arguments['authTransport'] != null) { - options.authTransport = call.arguments['authTransport']; - } - if (call.arguments['authEndpoint'] != null) { - options.authEndpoint = call.arguments['authEndpoint']; - } - if (call.arguments['authParams'] != null) { - options.auth = call.arguments['authParams']; - } - if (call.arguments['logToConsole'] != null) { - Pusher.logToConsole = call.arguments['logToConsole']; - } - if (call.arguments['authorizer'] != null) { - options.authorizer = ChannelAuthorizerGenerator.create(onAuthorizer); - } - pusher = Pusher(call.arguments['apiKey'], options); - pusher!.connection.bind('error', onError.toJS); - pusher!.connection.bind('message', onMessage.toJS); - pusher!.connection.bind('state_change', onStateChange.toJS); - pusher!.connection.bind('connected', onConnected.toJS); - pusher!.connection.bind('disconnected', onDisconnected.toJS); - } -} - -final class FlutterDartDeprecatedChannelAuthorizer - implements DartDeprecatedChannelAuthorizer { - const FlutterDartDeprecatedChannelAuthorizer({ - required this.methodChannel, - required this.channel, - required this.options, - }); - - final MethodChannel methodChannel; - final Channel channel; - final DeprecatedAuthorizerOptions options; - - @override - void authorize(String socketId, ChannelAuthorizationCallback callback) async { - try { - var authData = await methodChannel.invokeMethod('onAuthorizer', { - 'socketId': socketId, - 'channelName': channel.name, - 'options': options.toMap(), - }); - callback.call( - null, - ChannelAuthorizationData.create( - auth: authData['auth'], - channelData: authData['channel_data'], - sharedSecret: authData['shared_secret'], - ), - ); - } catch (e, stackTrace) { - callback.call( - JSError.create( - message: '$e', - stackTrace: stackTrace, - ), - null, - ); - } - } -} diff --git a/lib/pusher_channels_flutter_web.dart b/lib/pusher_channels_flutter_web.dart index 2721ec1..a3d3d0d 100644 --- a/lib/pusher_channels_flutter_web.dart +++ b/lib/pusher_channels_flutter_web.dart @@ -1,32 +1,27 @@ -@JS() -library pusher_channels_flutter; - import 'dart:async'; -import 'package:js/js.dart'; -import 'package:js/js_util.dart' as js_util; +import 'dart:js_interop'; +import 'dart:js_util' as js_util; + // In order to *not* need this ignore, consider extracting the 'web' version // of your plugin as a separate package, instead of inlining it in the same // package as the core of your plugin. // ignore: avoid_web_libraries_in_flutter import 'package:flutter/services.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:pusher_channels_flutter/pusher-js/core/auth/options.dart'; -import 'package:pusher_channels_flutter/pusher-js/core/channels/channel.dart'; -import 'package:pusher_channels_flutter/pusher-js/core/channels/presence_channel.dart'; -import 'package:pusher_channels_flutter/pusher-js/core/options.dart'; -import 'package:pusher_channels_flutter/pusher-js/core/pusher.dart'; -class PusherError extends Error { - String message; - int code; - PusherError(this.message, this.code); -} +import 'pusher-js/core/auth/deprecated_channel_authorizer.dart'; +import 'pusher-js/core/auth/options.dart'; +import 'pusher-js/core/channels/channel.dart'; +import 'pusher-js/core/channels/presence_channel.dart'; +import 'pusher-js/core/options.dart'; +import 'pusher-js/core/pusher.dart'; +import 'pusher-js/error.dart'; @JS('JSON.stringify') -external String stringify(Object obj); +external String stringify(JSObject obj); @JS('Object.keys') -external List objectKeys(object); +external JSArray objectKeys(JSObject object); bool _isBasicType(value) { if (value == null || value is num || value is bool || value is String) { @@ -44,7 +39,7 @@ T dartify(dynamic jsObject) { } var keys = objectKeys(jsObject); var result = {}; - for (var key in keys) { + for (var key in keys.toDart.map((e) => e.toDart)) { result[key] = dartify(js_util.getProperty(jsObject, key)); } return result as T; @@ -89,7 +84,7 @@ class PusherChannelsFlutterWeb { trigger(call); break; case 'getSocketId': - return pusher!.connection.socket_id; + return pusher!.connection.socketId; default: throw PlatformException( code: 'Unimplemented', @@ -111,7 +106,7 @@ class PusherChannelsFlutterWeb { } } - void onError(dynamic jsError) { + void onError(JSAny? jsError) { final Map error = dartify>(jsError); if (error['type'] == 'PusherError') { @@ -123,7 +118,7 @@ class PusherChannelsFlutterWeb { } } - void onMessage(dynamic jsMessage) { + void onMessage(JSAny? jsMessage) { final Map msg = dartify>(jsMessage); final String event = msg['event'] ?? ''; final String channel = msg['channel'] ?? ''; @@ -154,7 +149,10 @@ class PusherChannelsFlutterWeb { if (event == 'pusher_internal:subscription_succeeded') { if (channel.startsWith('presence-')) { final presenceChannel = pusher!.channel(channel) as PresenceChannel; - userId = presenceChannel.members.myID; + final id = presenceChannel.members.myId; + if (id.isA()) { + userId = (id as JSString).toDart; + } } } methodChannel!.invokeMethod('onEvent', { @@ -166,7 +164,7 @@ class PusherChannelsFlutterWeb { } } - void onStateChange(dynamic jsState) { + void onStateChange(JSAny? jsState) { final Map state = dartify>(jsState ?? {}); final String current = state['current'] ?? ''; @@ -177,31 +175,21 @@ class PusherChannelsFlutterWeb { }); } - void onConnected(dynamic jsMessage) {} + void onConnected(JSAny? jsMessage) {} void onDisconnected() {} - Authorizer onAuthorizer(Channel channel, AuthorizerOptions options) { - return Authorizer( - authorize: allowInterop((socketId, callback) async { - try { - var authData = await methodChannel!.invokeMethod('onAuthorizer', { - 'socketId': socketId, - 'channelName': channel.name, - 'options': options.toMap(), - }); - callback( - null, - AuthData( - auth: authData['auth'], - channel_data: authData['channel_data'], - shared_secret: authData['shared_secret'])); - } catch (e) { - callback(PusherError(e.toString(), -1), AuthData(auth: '')); - } - }), - ); - } + DeprecatedChannelAuthorizer onAuthorizer( + Channel channel, + DeprecatedAuthorizerOptions options, + ) => + DeprecatedChannelAuthorizer.create( + FlutterDartDeprecatedChannelAuthorizer( + methodChannel: methodChannel!, + channel: channel, + options: options, + ), + ); void subscribe(MethodCall call) { assertPusher(); @@ -213,7 +201,7 @@ class PusherChannelsFlutterWeb { var channelName = call.arguments['channelName']; var channel = pusher!.channel(channelName); pusher!.unsubscribe(channelName); - channel?.unbind_all(); + channel?.unbindAll(); } void trigger(MethodCall call) { @@ -224,7 +212,7 @@ class PusherChannelsFlutterWeb { void init(MethodCall call) { if (pusher != null) { - pusher!.unbind_all(); + pusher!.unbindAll(); pusher!.disconnect(); } var options = Options(); @@ -262,13 +250,53 @@ class PusherChannelsFlutterWeb { Pusher.logToConsole = call.arguments['logToConsole']; } if (call.arguments['authorizer'] != null) { - options.authorizer = allowInterop(onAuthorizer); + options.authorizer = ChannelAuthorizerGenerator.create(onAuthorizer); } pusher = Pusher(call.arguments['apiKey'], options); - pusher!.connection.bind('error', allowInterop(onError)); - pusher!.connection.bind('message', allowInterop(onMessage)); - pusher!.connection.bind('state_change', allowInterop(onStateChange)); - pusher!.connection.bind('connected', allowInterop(onConnected)); - pusher!.connection.bind('disconnected', allowInterop(onDisconnected)); + pusher!.connection.bind('error', onError.toJS); + pusher!.connection.bind('message', onMessage.toJS); + pusher!.connection.bind('state_change', onStateChange.toJS); + pusher!.connection.bind('connected', onConnected.toJS); + pusher!.connection.bind('disconnected', onDisconnected.toJS); + } +} + +final class FlutterDartDeprecatedChannelAuthorizer + implements DartDeprecatedChannelAuthorizer { + const FlutterDartDeprecatedChannelAuthorizer({ + required this.methodChannel, + required this.channel, + required this.options, + }); + + final MethodChannel methodChannel; + final Channel channel; + final DeprecatedAuthorizerOptions options; + + @override + void authorize(String socketId, ChannelAuthorizationCallback callback) async { + try { + var authData = await methodChannel.invokeMethod('onAuthorizer', { + 'socketId': socketId, + 'channelName': channel.name, + 'options': options.toMap(), + }); + callback.call( + null, + ChannelAuthorizationData.create( + auth: authData['auth'], + channelData: authData['channel_data'], + sharedSecret: authData['shared_secret'], + ), + ); + } catch (e, stackTrace) { + callback.call( + JSError.create( + message: '$e', + stackTrace: stackTrace, + ), + null, + ); + } } } diff --git a/lib/wasm-pusher-js/core/auth/options.dart b/lib/wasm-pusher-js/core/auth/options.dart deleted file mode 100644 index 40d3e58..0000000 --- a/lib/wasm-pusher-js/core/auth/options.dart +++ /dev/null @@ -1,122 +0,0 @@ -import 'dart:js_interop'; - -import '../../error.dart'; - -extension type ChannelAuthorizationData._(JSObject _) implements JSObject { - static ChannelAuthorizationData create({ - required String auth, - String? channelData, - String? sharedSecret, - }) { - return (JSObject() as ChannelAuthorizationData) - ..auth = auth - ..channelData = channelData - ..sharedSecret = sharedSecret; - } - - external String auth; - - @JS('channel_data') - external String? channelData; - - @JS('shared_secret') - external String? sharedSecret; -} - -extension type ChannelAuthorizationCallback._(JSFunction _) - implements JSFunction { - void call( - JSError? error, - ChannelAuthorizationData? authData, - ) => - callAsFunction(null, error, authData); -} - -extension type ChannelAuthorizationRequestParams._(JSObject _) - implements JSObject { - external ChannelAuthorizationRequestParams({ - String socketId, - String channelName, - }); - - external String socketId; - - external String channelName; -} - -typedef DartChannelAuthorizationHandler = void Function( - ChannelAuthorizationRequestParams params, - ChannelAuthorizationCallback callback, -); - -extension type ChannelAuthorizationHandler._(JSFunction _) - implements JSFunction { - static ChannelAuthorizationHandler create( - DartChannelAuthorizationHandler handler, - ) => - handler.toJS as ChannelAuthorizationHandler; -} - -extension type UserAuthenticationData._(JSObject _) implements JSObject { - static UserAuthenticationData create({ - required String auth, - required String userData, - }) { - return (JSObject() as UserAuthenticationData) - ..auth = auth - ..userData = userData; - } - - external String auth; - - @JS('user_data') - external String userData; -} - -extension type UserAuthenticationCallback._(JSFunction _) - implements JSFunction { - void call( - JSError? error, - UserAuthenticationData? authData, - ) => - callAsFunction(null, error, authData); -} - -extension type UserAuthenticationRequestParams._(JSObject _) - implements JSObject { - external String socketId; -} - -typedef DartUserAuthenticationHandler = void Function( - UserAuthenticationRequestParams params, - UserAuthenticationCallback callback, -); - -extension type UserAuthenticationHandler._(JSFunction _) implements JSFunction { - static UserAuthenticationHandler create( - DartUserAuthenticationHandler handler, - ) => - handler.toJS as UserAuthenticationHandler; -} - -typedef UserAuthenticationOptions = AuthOptionsT; - -typedef ChannelAuthorizationOptions = AuthOptionsT; - -extension type AuthOptionsT._(JSObject _) - implements JSObject { - // Allow 'ajax' | 'jsonp' - external String transport; - - external String endpoint; - - external JSAny params; - - external JSAny headers; - - external JSFunction? paramsProvider; - - external JSFunction? headersProvider; - - external AuthHandler? customHandler; -} diff --git a/lib/wasm-pusher-js/core/channels/channel.dart b/lib/wasm-pusher-js/core/channels/channel.dart deleted file mode 100644 index 3c17bd1..0000000 --- a/lib/wasm-pusher-js/core/channels/channel.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'dart:js_interop'; - -import '../auth/options.dart'; -import '../connection/protocol/message_types.dart'; -import '../events/dispatcher.dart'; -import '../pusher.dart'; - -extension type Channel._(Dispatcher _) implements Dispatcher { - external Channel(String name, Pusher pusher); - - external String name; - - external Pusher pusher; - - external bool subscribed; - - external bool subscriptionPending; - - external bool subscriptionCancelled; - - external void authorize( - String socketId, - ChannelAuthorizationCallback callback, - ); - - external bool trigger(String event, [JSAny data]); - - external void disconnect(); - - external void handleEvent(PusherEvent event); - - external void handleSubscriptionSucceededEvent(PusherEvent event); - - external void handleSubscriptionCountEvent(PusherEvent event); - - external void subscribe(); - - external void unsubscribe(); - - external void cancelSubscription(); - - external void reinstateSubscription(); -} diff --git a/lib/wasm-pusher-js/core/channels/channel_table.dart b/lib/wasm-pusher-js/core/channels/channel_table.dart deleted file mode 100644 index df67cf5..0000000 --- a/lib/wasm-pusher-js/core/channels/channel_table.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'dart:js_interop'; - -import 'channel.dart'; - -extension type ChannelTable._(JSObject _) implements JSObject { - external Channel? operator [](String index); - - external void operator []=(String index, Channel value); -} diff --git a/lib/wasm-pusher-js/core/channels/members.dart b/lib/wasm-pusher-js/core/channels/members.dart deleted file mode 100644 index 7b9dfcb..0000000 --- a/lib/wasm-pusher-js/core/channels/members.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:js_interop'; - -extension type Members._(JSObject _) implements JSObject { - external Members(); - - external JSAny members; - - external num count; - - @JS('myID') - external JSAny myId; - - external JSAny get(String id); - - external void each(JSFunction callback); - - external void onSubscription(JSAny subscriptionData); - - external JSAny addMember(JSAny memberData); - - external JSAny removeMember(JSAny memberData); - - external void reset(); -} diff --git a/lib/wasm-pusher-js/core/channels/metadata.dart b/lib/wasm-pusher-js/core/channels/metadata.dart deleted file mode 100644 index a261dec..0000000 --- a/lib/wasm-pusher-js/core/channels/metadata.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'dart:js_interop'; - -extension type Metadata._(JSObject _) implements JSObject { - @JS('user_id') - external String? userId; -} diff --git a/lib/wasm-pusher-js/core/channels/presence_channel.dart b/lib/wasm-pusher-js/core/channels/presence_channel.dart deleted file mode 100644 index 8a34e3d..0000000 --- a/lib/wasm-pusher-js/core/channels/presence_channel.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'dart:js_interop'; - -import '../connection/protocol/message_types.dart'; -import '../pusher.dart'; -import 'members.dart'; -import 'private_channel.dart'; - -extension type PresenceChannel._(PrivateChannel _) implements PrivateChannel { - external PresenceChannel({ - String name, - Pusher pusher, - }); - - external Members members; - - external void authorize(String socketId, JSFunction callback); - - external void handleEvent(PusherEvent event); - - external void handleInternalEvent(PusherEvent event); - - external void handleSubscriptionSucceededEvent(PusherEvent event); - - external void disconnect(); -} diff --git a/lib/wasm-pusher-js/core/channels/private_channel.dart b/lib/wasm-pusher-js/core/channels/private_channel.dart deleted file mode 100644 index 12bf822..0000000 --- a/lib/wasm-pusher-js/core/channels/private_channel.dart +++ /dev/null @@ -1,13 +0,0 @@ -// export default class PrivateChannel extends Channel { -// authorize(socketId: string, callback: ChannelAuthorizationCallback): void; -// } - -import '../auth/options.dart'; -import 'channel.dart'; - -extension type PrivateChannel._(Channel _) implements Channel { - external void authorize( - String socketId, - ChannelAuthorizationCallback callback, - ); -} diff --git a/lib/wasm-pusher-js/core/config.dart b/lib/wasm-pusher-js/core/config.dart deleted file mode 100644 index 6338628..0000000 --- a/lib/wasm-pusher-js/core/config.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'dart:js_interop'; - -/// Allow 'ajax' | 'jsonp' -typedef AuthTransport = JSString; - -/// Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' -typedef Transport = JSString; - -extension type Config._(JSObject _) implements JSObject { - external num activityTimeout; - - external bool enableStats; - - external String httpHost; - - external String httpPath; - - external num httpPort; - - external num httpsPort; - - external num pongTimeout; - - external String statsHost; - - external num unavailableTimeout; - - @JS('useTLS') - external bool useTls; - - external String wsHost; - - external String wsPath; - - external num wsPort; - - external num wssPort; - - external JSFunction userAuthenticator; - - external JSFunction channelAuthorizer; - - @JS('forceTLS') - external bool? forceTls; - - external String? cluster; - - external JSArray? disabledTransports; - - external JSArray? enabledTransports; - - external bool? ignoreNullOrigin; - - // external Nacl? nacl; - - external JSAny timelineParams; -} diff --git a/lib/wasm-pusher-js/core/connection/connection.dart b/lib/wasm-pusher-js/core/connection/connection.dart deleted file mode 100644 index 344644b..0000000 --- a/lib/wasm-pusher-js/core/connection/connection.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'dart:js_interop'; - -import '../events/dispatcher.dart'; - -extension type Connection._(Dispatcher _) implements Dispatcher { - external Connection( - String id, - // TransportConnection transport, - ); - - external String id; - - // external TransportConnection transport; - - external num activityTimeout; - - external bool handlesActivityChecks(); - - external bool send(JSAny? data); - - @JS('send_event') - external bool sendEvent( - String name, - JSAny? data, [ - String? channel, - ]); - - external void ping(); - - external void close(); -} diff --git a/lib/wasm-pusher-js/core/connection/connection_manager.dart b/lib/wasm-pusher-js/core/connection/connection_manager.dart deleted file mode 100644 index 09ba714..0000000 --- a/lib/wasm-pusher-js/core/connection/connection_manager.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:js_interop'; - -import '../events/dispatcher.dart'; -import '../strategies/strategy.dart'; -import '../strategies/strategy_runner.dart'; -import '../timeline/timeline.dart'; -import 'connection.dart'; -import 'connection_manager_options.dart'; - -extension type ConnectionManager._(Dispatcher _) implements Dispatcher { - external ConnectionManager({ - String key, - ConnectionManagerOptions options, - }); - - external String key; - - external ConnectionManagerOptions options; - - external String state; - - external Connection connection; - - @JS('usingTLS') - external bool usingTls; - - external Timeline timeline; - - @JS('socket_id') - external String socketId; - - // external Timer unavailableTimer; - - // external Timer activityTimer; - - // external Timer retryTimer; - - external num activityTimeout; - - external Strategy strategy; - - external StrategyRunner runner; - - // external ErrorCallbacks errorCallbacks; - - // external HandshakeCallbacks handshakeCallbacks; - - // external ConnectionCallbacks connectionCallbacks; - - external void connect(); - - external bool send(JSAny? data); - - @JS('send_event') - external bool sendEvent( - String name, - JSAny? data, [ - String? channel, - ]); - - external void disconnect(); - - @JS('isUsingTLS') - external bool isUsingTls(); -} diff --git a/lib/wasm-pusher-js/core/connection/connection_manager_options.dart b/lib/wasm-pusher-js/core/connection/connection_manager_options.dart deleted file mode 100644 index eea8f19..0000000 --- a/lib/wasm-pusher-js/core/connection/connection_manager_options.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'dart:js_interop'; - -import '../timeline/timeline.dart'; - -extension type ConnectionManagerOptions._(JSObject _) implements JSObject { - external Timeline timeline; - - external JSFunction getStrategy; - - external num unavailableTimeout; - - external num pongTimeout; - - external num activityTimeout; - - @JS('useTLS') - external bool useTls; -} - diff --git a/lib/wasm-pusher-js/core/events/callback.dart b/lib/wasm-pusher-js/core/events/callback.dart deleted file mode 100644 index 91cede0..0000000 --- a/lib/wasm-pusher-js/core/events/callback.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'dart:js_interop'; - -extension type Callback._(JSObject _) implements JSObject { - external JSFunction fn; - - external JSAny? context; -} diff --git a/lib/wasm-pusher-js/core/events/callback_registry.dart b/lib/wasm-pusher-js/core/events/callback_registry.dart deleted file mode 100644 index 78a31e0..0000000 --- a/lib/wasm-pusher-js/core/events/callback_registry.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'dart:js_interop'; - -import 'callback.dart'; -import 'callback_table.dart'; - -extension type CallbackRegistry._(JSObject _) implements JSObject { - external CallbackRegistry(); - - @JS('_callbacks') - external CallbackTable callbacks; - - external JSArray get(JSString name); - - external void add(String name, JSFunction callback, JSAny? context); - - external void remove([String? name, JSFunction? callback, JSAny? context]); -} diff --git a/lib/wasm-pusher-js/core/events/callback_table.dart b/lib/wasm-pusher-js/core/events/callback_table.dart deleted file mode 100644 index 28f1c18..0000000 --- a/lib/wasm-pusher-js/core/events/callback_table.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'dart:js_interop'; - -import 'callback.dart'; - -extension type CallbackTable._(JSObject _) implements JSObject { - external Callback? operator [](String index); - - external void operator []=(String index, Callback value); -} diff --git a/lib/wasm-pusher-js/core/events/dispatcher.dart b/lib/wasm-pusher-js/core/events/dispatcher.dart deleted file mode 100644 index ee1429c..0000000 --- a/lib/wasm-pusher-js/core/events/dispatcher.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'dart:js_interop'; - -import '../channels/metadata.dart'; -import 'callback_registry.dart'; - -extension type Dispatcher._(JSObject _) implements JSObject { - external Dispatcher([JSFunction? failThrough]); - - external CallbackRegistry callbacks; - - @JS('global_callbacks') - external JSArray globalCallbacks; - - external JSFunction failThrough; - - external Dispatcher bind(String eventName, JSFunction callback, - [JSAny? context]); - - @JS('bind_global') - external Dispatcher bindGlobal(JSFunction callback); - - external Dispatcher unbind( - [String? eventName, JSFunction? callback, JSAny? context]); - - @JS('unbind_global') - external Dispatcher unbindGlobal([JSFunction? callback]); - - @JS('unbind_all') - external Dispatcher unbindAll(); - - external Dispatcher emit(String eventName, [JSAny? data, Metadata? metadata]); -} diff --git a/lib/wasm-pusher-js/core/options.dart b/lib/wasm-pusher-js/core/options.dart deleted file mode 100644 index 26135d5..0000000 --- a/lib/wasm-pusher-js/core/options.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'dart:js_interop'; - -import 'auth/deprecated_channel_authorizer.dart'; -import 'auth/options.dart'; - -extension type Options._(JSObject _) implements JSObject { - external Options({ - num? activityTimeout, - DeprecatedAuthOptions? auth, - String? authEndpoint, - String? authTransport, - ChannelAuthorizerGenerator? authorizer, - ChannelAuthorizationOptions? channelAuthorization, - UserAuthenticationOptions? userAuthentication, - String? cluster, - bool? enableStats, - bool? disableStats, - JSArray? disabledTransports, - JSArray? enabledTransports, - bool? forceTLS, - String? httpHost, - String? httpPath, - num? httpPort, - bool? ignoreNullOrigin, - // Nacl? nacl; - num? pongTimeout, - String? statsHost, - JSAny timelineParams, - num? unavailableTimeout, - String? wsHost, - String? wsPath, - num? wsPort, - num? wssPort, - }); - - external num? activityTimeout; - - @Deprecated('Use channelAuthorization instead') - external DeprecatedAuthOptions? auth; - - @Deprecated('Use channelAuthorization instead') - external String? authEndpoint; - - /// Allow 'ajax' | 'jsonp' - @Deprecated('Use channelAuthorization instead') - external String? authTransport; - - @Deprecated('Use channelAuthorization instead') - external ChannelAuthorizerGenerator? authorizer; - - external ChannelAuthorizationOptions? channelAuthorization; - - external UserAuthenticationOptions? userAuthentication; - - external String? cluster; - - external bool? enableStats; - - external bool? disableStats; - - // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' - external JSArray? disabledTransports; - - // Allow 'ws' | 'wss' | 'xhr_streaming' | 'xhr_polling' | 'sockjs' - external JSArray? enabledTransports; - - external bool? forceTLS; - - external String? httpHost; - - external String? httpPath; - - external num? httpPort; - - external bool? ignoreNullOrigin; - - // external Nacl? nacl; - - external num? pongTimeout; - - external String? statsHost; - - external JSAny? timelineParams; - - external num? unavailableTimeout; - - external String? wsHost; - - external String? wsPath; - - external num? wsPort; - - external num? wssPort; -} diff --git a/lib/wasm-pusher-js/core/pusher.dart b/lib/wasm-pusher-js/core/pusher.dart deleted file mode 100644 index aaba4da..0000000 --- a/lib/wasm-pusher-js/core/pusher.dart +++ /dev/null @@ -1,100 +0,0 @@ -import 'dart:js_interop'; - -import 'channels.dart'; -import 'channels/channel.dart'; -import 'config.dart'; -import 'connection/connection_manager.dart'; -import 'events/dispatcher.dart'; -import 'options.dart'; -import 'timeline/timeline.dart'; -import 'timeline/timeline_sender.dart'; -import 'user.dart'; - -extension type Pusher._(JSObject _) implements JSObject { - external Pusher(String appKey, Options options); - - /// STATIC PROPERTIES - external static JSArray instances; - - external static bool isRead; - - external static bool logToConsole; - - // static Runtime: AbstractRuntime; - // static ScriptReceivers: any; - // static DependenciesReceivers: any; - // static auth_callbacks: any; - - external static void ready(); - - external static void log(JSAny? message); - - external static JSAny? get getClientFeatures; - - external String key; - - external Config config; - - external Channels channels; - - @JS('global_emitter') - external Dispatcher globalEmitter; - - @JS('sessionID') - external num sessionId; - - external Timeline timeline; - - external TimelineSender timelineSender; - - external ConnectionManager connection; - - external UserFacade user; - - external Channel? channel(String name); - - external JSArray allChannels(); - - external void connect(); - - external void disconnect(); - - external Pusher bind( - String eventName, - JSFunction callback, [ - JSAny? context, - ]); - - external Pusher unbind([ - String? eventName, - JSFunction? callback, - JSAny? context, - ]); - - @JS('bind_global') - external Pusher bindGlobal(JSFunction callback); - - @JS('unbind_global') - external Pusher unbindGlobal([JSFunction? callback]); - - @JS('unbind_all') - external void unbindAll([JSFunction? callback]); - - external void subscribeAll(); - - external Channel subscribe(String channelName); - - external void unsubscribe(String channelName); - - @JS('send_event') - external bool sendEvent( - String eventName, - JSAny? data, [ - String? channel, - ]); - - @JS('shouldUseTLS') - external bool shouldUseTls(); - - external void signin(); -} diff --git a/lib/wasm-pusher-js/core/socket.dart b/lib/wasm-pusher-js/core/socket.dart deleted file mode 100644 index e3672f0..0000000 --- a/lib/wasm-pusher-js/core/socket.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:js_interop'; - -abstract class Socket { - external void send(dynamic payload); - - external void Function()? ping; - - external dynamic close([dynamic code, dynamic reason]); - - external bool Function(dynamic payload)? sendRaw; - - @JS('onopen') - external void Function([dynamic evt])? onOpen; - - @JS('onerror') - external void Function(dynamic error)? onerror; - - @JS('onclose') - external void Function(dynamic closeEvent)? onclose; - - @JS('onmessage') - external void Function(dynamic message)? onMessage; - - @JS('onactivity') - external void Function()? onActivity; -} diff --git a/lib/wasm-pusher-js/core/strategies/strategy.dart b/lib/wasm-pusher-js/core/strategies/strategy.dart deleted file mode 100644 index 7b52e9d..0000000 --- a/lib/wasm-pusher-js/core/strategies/strategy.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'dart:js_interop'; - -import 'strategy_runner.dart'; - -extension type Strategy._(JSObject _) implements JSObject { - external bool isSupported(); - - external StrategyRunner connect(num minPriority, JSFunction callback); -} diff --git a/lib/wasm-pusher-js/core/strategies/strategy_runner.dart b/lib/wasm-pusher-js/core/strategies/strategy_runner.dart deleted file mode 100644 index d769aec..0000000 --- a/lib/wasm-pusher-js/core/strategies/strategy_runner.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'dart:js_interop'; - -extension type StrategyRunnerForceMinPriorityFunction._(JSFunction _) - implements JSFunction { - void call(JSAny? number) => callAsFunction(null, number); -} - -extension type StrategyRunnerAbortFunction._(JSFunction _) - implements JSFunction { - void call() => callAsFunction(null); -} - -extension type StrategyRunner._(JSObject _) implements JSObject { - external StrategyRunnerForceMinPriorityFunction forceMinPriority; - - external StrategyRunnerAbortFunction abort; -} diff --git a/lib/wasm-pusher-js/core/timeline/level.dart b/lib/wasm-pusher-js/core/timeline/level.dart deleted file mode 100644 index 70da50b..0000000 --- a/lib/wasm-pusher-js/core/timeline/level.dart +++ /dev/null @@ -1,9 +0,0 @@ -enum TimelineLevel { - error(3), - info(6), - debug(7); - - const TimelineLevel(this.value); - - final int value; -} diff --git a/lib/wasm-pusher-js/core/timeline/timeline.dart b/lib/wasm-pusher-js/core/timeline/timeline.dart deleted file mode 100644 index 1736728..0000000 --- a/lib/wasm-pusher-js/core/timeline/timeline.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'dart:js_interop'; - -extension type TimelineOptions._(JSObject _) implements JSObject { - external TimelineOptions({ - num? level, - num? limit, - String? version, - String? cluster, - JSArray? features, - JSAny? params, - }); - - external num? level; - - external num? limit; - - external String? version; - - external String? cluster; - - external JSArray? features; - - external JSAny? params; -} - -extension type Timeline._(JSObject _) implements JSObject { - external Timeline( - String key, - num session, - TimelineOptions options, - ); - - external String key; - - external num session; - - external JSArray events; - - external TimelineOptions options; - - external num sent; - - @JS('uniqueID') - external num uniqueId; - - external void log(JSAny? level, JSAny? event); - - external void error(JSAny? event); - - external void info(JSAny? event); - - external void debug(JSAny? event); - - external bool isEmpty(); - - external bool send(JSAny? sendfn, JSAny? callback); - - @JS('generateUniqueID') - external num generationUniqueId(); -} diff --git a/lib/wasm-pusher-js/core/timeline/timeline_sender.dart b/lib/wasm-pusher-js/core/timeline/timeline_sender.dart deleted file mode 100644 index 27c43d0..0000000 --- a/lib/wasm-pusher-js/core/timeline/timeline_sender.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'dart:js_interop'; - -import 'timeline.dart'; - -extension type TimelineSenderOptions._(JSObject _) implements JSObject { - external TimelineSenderOptions({ - String? host, - num? port, - String? path, - }); - - external String? host; - - external num? port; - - external String? path; -} - -extension type TimelineSender._(JSObject _) implements JSObject { - external TimelineSender({ - Timeline timeline, - TimelineSenderOptions options, - }); - - external Timeline timeline; - - external TimelineSenderOptions options; - - external String host; - - external void send(bool useTls, [JSFunction? callback]); -} diff --git a/pubspec.lock b/pubspec.lock index b324a55..435158b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -72,14 +72,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: "direct main" - description: - name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf - url: "https://pub.dev" - source: hosted - version: "0.7.1" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7ead5b3..1e31ff1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - js: ^0.7.1 + dev_dependencies: flutter_test: sdk: flutter