Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'br.com.engapp.websocket_manager'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version = '1.8.22'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"websocket_manager","dependencies":[]}]}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"websocket_manager","path":"D:\\\\dev\\\\mobile\\\\flutter_websocket_plugin\\\\","dependencies":[]}],"android":[{"name":"websocket_manager","path":"D:\\\\dev\\\\mobile\\\\flutter_websocket_plugin\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"websocket_manager","dependencies":[]}],"date_created":"2021-05-08 18:22:40.577526","version":"2.0.5"}
110 changes: 34 additions & 76 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,69 +1,62 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
charcode:
version: "2.1.0"
characters:
dependency: transitive
description:
name: charcode
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
collection:
version: "1.1.0"
charcode:
dependency: transitive
description:
name: collection
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
version: "1.2.0"
clock:
dependency: transitive
description:
name: convert
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.1.0"
collection:
dependency: transitive
description:
name: crypto
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -74,55 +67,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -134,69 +99,62 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0"
websocket_manager:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "0.2.1"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "0.2.2"
sdks:
dart: ">=2.4.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
26 changes: 13 additions & 13 deletions lib/websocket_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class WebsocketManager {
}

final String url;
final Map<String, String> header;
final Map<String, String>? header;

static const MethodChannel _channel = MethodChannel(_PLUGIN_NAME);
static const EventChannel _eventChannelMessage =
EventChannel(_EVENT_CHANNEL_MESSAGE);
static const EventChannel _eventChannelClose =
EventChannel(_EVENT_CHANNEL_DONE);
static StreamSubscription<dynamic> _onMessageSubscription;
static StreamSubscription<dynamic> _onCloseSubscription;
static Stream<dynamic> _eventsMessage;
static Stream<dynamic> _eventsClose;
static Function(dynamic) _messageCallback;
static Function(dynamic) _closeCallback;
static StreamSubscription<dynamic>? _onMessageSubscription;
static StreamSubscription<dynamic>? _onCloseSubscription;
static Stream<dynamic>? _eventsMessage;
static Stream<dynamic>? _eventsClose;
static Function(dynamic)? _messageCallback;
static Function(dynamic)? _closeCallback;

static Future<void> echoTest() async {
final dynamic result =
Expand All @@ -41,7 +41,7 @@ class WebsocketManager {
}

Future<void> _create() async {
_channel.setMethodCallHandler((MethodCall call) {
_channel.setMethodCallHandler((MethodCall call) async {
switch (call.method) {
case 'listen/message':
_onMessage();
Expand Down Expand Up @@ -78,7 +78,7 @@ class WebsocketManager {
await _channel.invokeMethod<String>(_METHOD_CHANNEL_DISCONNECT);
_eventsMessage = null;
if (_onMessageSubscription != null) {
_onMessageSubscription.cancel();
_onMessageSubscription!.cancel();
_onMessageSubscription = null;
}
// _eventsClose = null;
Expand Down Expand Up @@ -130,7 +130,7 @@ class WebsocketManager {
if (_eventsMessage == null) {
_eventsMessage =
_eventChannelMessage.receiveBroadcastStream().asBroadcastStream();
_onMessageSubscription = _eventsMessage.listen(_messageListener);
_onMessageSubscription = _eventsMessage!.listen(_messageListener);
}
}

Expand All @@ -142,21 +142,21 @@ class WebsocketManager {
void _onClose() {
if (_eventsClose == null) {
_eventsClose = _eventChannelClose.receiveBroadcastStream();
_onCloseSubscription = _eventsClose.listen(_closeListener);
_onCloseSubscription = _eventsClose!.listen(_closeListener);
}
}

void _messageListener(dynamic message) {
// print('Received message: $message');
if (_messageCallback != null) {
_messageCallback(message);
_messageCallback!(message);
}
}

void _closeListener(dynamic message) {
print(message);
if (_closeCallback != null) {
_closeCallback(message);
_closeCallback!(message);
}
}
}
Loading