From 0e5cd9e4c12ad30b09a0e4c3d3a7729c0a00aa57 Mon Sep 17 00:00:00 2001 From: JagaranAG2022 Date: Fri, 8 Mar 2024 22:59:46 +0545 Subject: [PATCH 1/4] add authorization support, add support for host url, made wsport, wssport dynamic for android and ios platform --- example/android/app/build.gradle | 2 +- example/android/build.gradle | 2 +- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile.lock | 4 +- example/ios/Runner.xcodeproj/project.pbxproj | 9 ++- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 20 +++--- example/lib/main.dart | 34 +++++---- example/pubspec.lock | 72 +++++++++++++------ 9 files changed, 96 insertions(+), 51 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f8d430d..8a59d03 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -43,7 +43,7 @@ android { defaultConfig { applicationId "com.pusher.channels_flutter_example" - minSdkVersion 16 + minSdkVersion flutter.minSdkVersion targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/example/android/build.gradle b/example/android/build.gradle index 43e6ef3..a6df538 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -24,6 +24,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9625e10..7c56964 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 3c09607..5ad3f38 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -31,7 +31,7 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/shared_preferences_ios/ios" SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 NWWebSocket: 040d22f23438cc09aaeabf537beff67699c3c76d pusher_channels_flutter: 01297e6e420e0ad61a6e5901e27bb272a6f58ec2 PusherSwift: cad631bad86cfff4b8458dce1310a7774e469b1f @@ -40,4 +40,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b -COCOAPODS: 1.14.3 +COCOAPODS: 1.13.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 71ba08a..a627ab9 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -121,7 +121,6 @@ FDFE514985FF808219480A6A /* Pods-Runner.release.xcconfig */, 0BB366997DD8408ADB714ECE /* Pods-Runner.profile.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -156,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -217,10 +216,12 @@ }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -253,6 +254,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -357,6 +359,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -487,6 +490,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -509,6 +513,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c87d15a..5e31d3d 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - - LSApplicationCategoryType - + CADisableMinimumFrameDurationOnPhone + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -27,8 +22,17 @@ ???? CFBundleVersion $(FLUTTER_BUILD_NUMBER) + LSApplicationCategoryType + LSRequiresIPhoneOS + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + UIApplicationSupportsIndirectInputEvents + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -48,7 +52,5 @@ UIViewControllerBasedStatusBarAppearance - CADisableMinimumFrameDurationOnPhone - diff --git a/example/lib/main.dart b/example/lib/main.dart index 79962b0..528c3dc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -57,20 +57,26 @@ class _MyAppState extends State { try { await pusher.init( - apiKey: _apiKey.text, - cluster: _cluster.text, - onConnectionStateChange: onConnectionStateChange, - onError: onError, - onSubscriptionSucceeded: onSubscriptionSucceeded, - onEvent: onEvent, - onSubscriptionError: onSubscriptionError, - onDecryptionFailure: onDecryptionFailure, - onMemberAdded: onMemberAdded, - onMemberRemoved: onMemberRemoved, - onSubscriptionCount: onSubscriptionCount, - // authEndpoint: "", - // onAuthorizer: onAuthorizer - ); + apiKey: _apiKey.text, + cluster: _cluster.text, + onConnectionStateChange: onConnectionStateChange, + onError: onError, + onSubscriptionSucceeded: onSubscriptionSucceeded, + onEvent: onEvent, + onSubscriptionError: onSubscriptionError, + onDecryptionFailure: onDecryptionFailure, + onMemberAdded: onMemberAdded, + onMemberRemoved: onMemberRemoved, + onSubscriptionCount: onSubscriptionCount, + host: "", + authEndpoint: "", + useTLS: true, + wsPort: 80, + wssPort: 443, + authParams: { + "headers": {"Authorization": ""} + }, + onAuthorizer: onAuthorizer); await pusher.subscribe(channelName: _channelName.text); await pusher.connect(); } catch (e) { diff --git a/example/pubspec.lock b/example/pubspec.lock index 1ec4576..9eaebe9 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: @@ -104,6 +104,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -116,34 +140,34 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" path_provider_linux: dependency: transitive description: @@ -198,7 +222,7 @@ packages: path: ".." relative: true source: path - version: "2.2.0" + version: "2.2.1" shared_preferences: dependency: "direct main" description: @@ -272,26 +296,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -312,10 +336,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.1" vector_math: dependency: transitive description: @@ -324,6 +348,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" win32: dependency: transitive description: @@ -341,5 +373,5 @@ packages: source: hosted version: "0.2.0+2" sdks: - dart: ">=3.0.0-0 <4.0.0" + dart: ">=3.2.0-0 <4.0.0" flutter: ">=3.0.0" From c7537afede0cd141ce3e5276d5d375798996c594 Mon Sep 17 00:00:00 2001 From: JagaranAG2022 Date: Fri, 8 Mar 2024 23:02:04 +0545 Subject: [PATCH 2/4] add authorization support, add support for host url, made wsport, wssport dynamic for android and ios platform --- .../PusherChannelsFlutterPlugin.kt | 79 ++++++++++--------- .../SwiftPusherChannelsFlutterPlugin.swift | 35 +++++++- lib/pusher_channels_flutter.dart | 27 ++++++- pubspec.lock | 70 +++++++++++----- 4 files changed, 153 insertions(+), 58 deletions(-) diff --git a/android/src/main/kotlin/com/pusher/channels_flutter/PusherChannelsFlutterPlugin.kt b/android/src/main/kotlin/com/pusher/channels_flutter/PusherChannelsFlutterPlugin.kt index 34e2da5..6fa2ea5 100644 --- a/android/src/main/kotlin/com/pusher/channels_flutter/PusherChannelsFlutterPlugin.kt +++ b/android/src/main/kotlin/com/pusher/channels_flutter/PusherChannelsFlutterPlugin.kt @@ -32,11 +32,9 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw private val TAG = "PusherChannelsFlutter" override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { - methodChannel = - MethodChannel( - flutterPluginBinding.binaryMessenger, - "pusher_channels_flutter" - ) + methodChannel = MethodChannel( + flutterPluginBinding.binaryMessenger, "pusher_channels_flutter" + ) methodChannel.setMethodCallHandler(this) } @@ -66,19 +64,20 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw "connect" -> this.connect(result) "disconnect" -> this.disconnect(result) "subscribe" -> this.subscribe( - call.argument("channelName")!!, - result + call.argument("channelName")!!, result ) + "unsubscribe" -> this.unsubscribe( - call.argument("channelName")!!, - result + call.argument("channelName")!!, result ) + "trigger" -> this.trigger( call.argument("channelName")!!, call.argument("eventName")!!, call.argument("data")!!, result ) + "getSocketId" -> this.getSocketId(result) else -> { result.notImplemented() @@ -93,8 +92,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw } private fun init( - call: MethodCall, - result: Result + call: MethodCall, result: Result ) { try { if (pusher != null) { @@ -102,6 +100,9 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw } val options = PusherOptions() if (call.argument("cluster") != null) options.setCluster(call.argument("cluster")) + if (call.argument("host") != null) options.setHost(call.argument("host")) + if (call.argument("wsPort") != null) options.setWsPort(call.argument("wsPort")!!) + if (call.argument("wssPort") != null) options.setWssPort(call.argument("wssPort")!!) if (call.argument("useTLS") != null) options.isUseTLS = call.argument("useTLS")!! if (call.argument("activityTimeout") != null) options.activityTimeout = @@ -112,8 +113,19 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw call.argument("maxReconnectionAttempts")!! if (call.argument("maxReconnectGapInSeconds") != null) options.maxReconnectGapInSeconds = call.argument("maxReconnectGapInSeconds")!! - if (call.argument("authEndpoint") != null) options.channelAuthorizer = - HttpChannelAuthorizer(call.argument("authEndpoint")) + if (call.argument("authEndpoint") != null) { + val authorize = HttpChannelAuthorizer(call.argument("authEndpoint")) + if (call.argument>>("authParams") != null) { + val authParams = call.argument>>("authParams")!! + if (authParams.containsKey("headers")) { + val authHeaders = authParams["headers"] + if (authHeaders != null && authHeaders!!.isNotEmpty()) authorize.setHeaders( + authHeaders + ) + } + } + options.channelAuthorizer = authorize + } if (call.argument("authorizer") != null) options.channelAuthorizer = this if (call.argument("proxy") != null) { val (host, port) = call.argument("proxy")!!.split(':') @@ -142,10 +154,12 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw channelName.startsWith("private-encrypted-") -> pusher!!.subscribePrivateEncrypted( channelName, this ) + channelName.startsWith("private-") -> pusher!!.subscribePrivate(channelName, this) channelName.startsWith("presence-") -> pusher!!.subscribePresence( channelName, this ) + else -> pusher!!.subscribe(channelName, this) } channel.bindGlobal(this) @@ -162,8 +176,10 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw channelName.startsWith("private-encrypted-") -> throw Exception("It's not currently possible to send a message using private encrypted channels.") channelName.startsWith("private-") -> pusher!!.getPrivateChannel(channelName) .trigger(eventName, data) + channelName.startsWith("presence-") -> pusher!!.getPresenceChannel(channelName) .trigger(eventName, data) + else -> throw Exception("Messages can only be sent to private and presence channels.") } result.success(null) @@ -180,8 +196,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw try { activity!!.runOnUiThread { methodChannel.invokeMethod("onAuthorizer", mapOf( - "channelName" to channelName, - "socketId" to socketId + "channelName" to channelName, "socketId" to socketId ), object : Result { override fun success(o: Any?) { if (o != null) { @@ -192,11 +207,13 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw } mutex.release() } + override fun error(s: String, s1: String?, o: Any?) { Log.i(TAG, "Pusher authorize error: " + s) result = "{ }" mutex.release() } + override fun notImplemented() { result = "{ }" mutex.release() @@ -228,7 +245,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw "onEvent", mapOf( "channelName" to channelName, "eventName" to "pusher:subscription_succeeded", - "data" to emptyMap() + "data" to emptyMap() ) ) } @@ -248,12 +265,11 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw override fun onAuthenticationFailure(message: String, e: Exception) { callback( "onSubscriptionError", mapOf( - "message" to message, - "error" to e.toString() + "message" to message, "error" to e.toString() ) ) - } - + } + // Other ChannelEventListener methods override fun onUsersInformationReceived(channelName: String?, users: MutableSet?) { val gson = Gson() @@ -265,9 +281,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw } val data = mapOf( "presence" to mapOf( - "count" to users.size, - "ids" to users.map { it.id }, - "hash" to hash + "count" to users.size, "ids" to users.map { it.id }, "hash" to hash ) ) callback( @@ -283,8 +297,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw override fun onDecryptionFailure(event: String?, reason: String?) { callback( "onDecryptionFailure", mapOf( - "event" to event, - "reason" to reason + "event" to event, "reason" to reason ) ) } @@ -292,10 +305,8 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw override fun userSubscribed(channelName: String, user: User) { callback( "onMemberAdded", mapOf( - "channelName" to channelName, - "user" to mapOf( - "userId" to user.id, - "userInfo" to user.info + "channelName" to channelName, "user" to mapOf( + "userId" to user.id, "userInfo" to user.info ) ) ) @@ -304,10 +315,8 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw override fun userUnsubscribed(channelName: String, user: User) { callback( "onMemberRemoved", mapOf( - "channelName" to channelName, - "user" to mapOf( - "userId" to user.id, - "userInfo" to user.info + "channelName" to channelName, "user" to mapOf( + "userId" to user.id, "userInfo" to user.info ) ) ) @@ -316,9 +325,7 @@ class PusherChannelsFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAw override fun onError(message: String, code: String?, e: Exception?) { callback( "onError", mapOf( - "message" to message, - "code" to code, - "error" to e.toString() + "message" to message, "code" to code, "error" to e.toString() ) ) } diff --git a/ios/Classes/SwiftPusherChannelsFlutterPlugin.swift b/ios/Classes/SwiftPusherChannelsFlutterPlugin.swift index 7d8b4a6..cdda46e 100644 --- a/ios/Classes/SwiftPusherChannelsFlutterPlugin.swift +++ b/ios/Classes/SwiftPusherChannelsFlutterPlugin.swift @@ -41,8 +41,13 @@ public class SwiftPusherChannelsFlutterPlugin: NSObject, FlutterPlugin, PusherDe let args = call.arguments as! [String: Any] var authMethod: AuthMethod = .noMethod if args["authEndpoint"] is String { - authMethod = .endpoint(authEndpoint: args["authEndpoint"] as! String) - } else if args["authorizer"] is Bool { + authMethod = .endpoint(authEndpoint: args["authEndpoint"] as! String) + if let authParams = args["authParams"] as? [String: [String: String]], + let headers = authParams["headers"], !headers.isEmpty { + let pusherAuthRequestBuilder = PusherAuthRequestBuilder(baseURL: args["authEndpoint"] as! String, headers: headers) + authMethod = .authRequestBuilder(authRequestBuilder: pusherAuthRequestBuilder) + } + }else if args["authorizer"] is Bool { authMethod = .authorizer(authorizer: self) } var host: PusherHost = .defaultHost @@ -248,3 +253,29 @@ public class SwiftPusherChannelsFlutterPlugin: NSObject, FlutterPlugin, PusherDe } } } + + +class PusherAuthRequestBuilder: NSObject, AuthRequestBuilderProtocol { + let baseURL: String + let headers: [String: String] + init(baseURL: String, headers: [String: String]) { + self.baseURL = baseURL + self.headers = headers + } + + func requestFor(socketID: String, channelName: String) -> URLRequest? { + guard let url = URL(string: baseURL) else { + return nil + } + + var request = URLRequest(url: url) + request.httpMethod = "POST" + request.httpBody = "socket_id=\(socketID)&channel_name=\(channelName)".data(using: .utf8) + + for (key, value) in headers { + request.addValue(value, forHTTPHeaderField: key) + } + + return request + } +} diff --git a/lib/pusher_channels_flutter.dart b/lib/pusher_channels_flutter.dart index d01bd9f..7cb426d 100644 --- a/lib/pusher_channels_flutter.dart +++ b/lib/pusher_channels_flutter.dart @@ -1,6 +1,9 @@ import 'dart:async'; import 'dart:convert'; +// import 'dart:html'; +import 'dart:io'; + import 'package:flutter/services.dart'; class PusherEvent { @@ -8,6 +11,7 @@ class PusherEvent { String eventName; dynamic data; String? userId; + PusherEvent({ required this.channelName, required this.eventName, @@ -41,6 +45,7 @@ class PusherChannel { Function(PusherMember member)? onMemberAdded; Function(PusherMember member)? onMemberRemoved; Function(int subscriptionCount)? onSubscriptionCount; + PusherChannel({ required this.channelName, this.onSubscriptionSucceeded, @@ -88,7 +93,10 @@ class PusherChannelsFlutter { Future init({ required String apiKey, - required String cluster, + String? cluster, + String? host, + int? wsPort, // The port to which non TLS connections will be made. + int? wssPort, // The port to which encrypted connections will be made. bool? useTLS, int? activityTimeout, int? pongTimeout, @@ -127,10 +135,27 @@ class PusherChannelsFlutter { this.onMemberRemoved = onMemberRemoved; this.onAuthorizer = onAuthorizer; this.onSubscriptionCount = onSubscriptionCount; + if (Platform.isAndroid || Platform.isIOS) { + if (authParams != null && + authParams.isNotEmpty && + authParams.containsKey("headers")) { + Map headers = Map.of(authParams["headers"] ?? {}); + + assert( + !(headers.containsKey("Content-Type") || + headers.containsKey("content-type") || + (headers.containsValue("application/json") || + headers.containsValue("Application/json"))), + "::: Headers should not contain Content-Type key or Value as application/json :::"); + } + } await methodChannel.invokeMethod('init', { "apiKey": apiKey, "cluster": cluster, "useTLS": useTLS, + "wsPort": wsPort ?? 80, + "wssPort": wssPort ?? 443, + "host": host ?? "ws.pusherapp.com", "activityTimeout": activityTimeout, "pongTimeout": pongTimeout, "maxReconnectionAttempts": maxReconnectionAttempts, diff --git a/pubspec.lock b/pubspec.lock index 455fad6..c358d8d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.18.0" fake_async: dependency: transitive description: @@ -80,6 +80,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -92,34 +116,34 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -129,26 +153,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -169,10 +193,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.1" vector_math: dependency: transitive description: @@ -181,6 +205,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" sdks: - dart: ">=3.0.0-0 <4.0.0" + dart: ">=3.2.0-0 <4.0.0" flutter: ">=1.20.0" From 80c067f5545026b6dee25a4660e586bfcd2f6729 Mon Sep 17 00:00:00 2001 From: Laxman Adhikari <54370052+prolaxu@users.noreply.github.com> Date: Sat, 21 Sep 2024 16:15:10 +0545 Subject: [PATCH 3/4] enhc: gradel 8.0 compatiblity --- android/build.gradle | 11 ++++++++--- android/gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 868a18c..688dd5c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,14 +2,14 @@ group 'com.pusher' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.8.20' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:7.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -25,7 +25,12 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 30 + // Conditional for compatibility with AGP < 4.2 + if (project.android.hasProperty("namespace")) { + namespace "com.pusher.channels_flutter" + } + + compileSdk 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 3c9d085..7645e29 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -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-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip From 80bdb00de945148339f820cda4a79666d5190920 Mon Sep 17 00:00:00 2001 From: Jagaran Maharjan <60642304+JagaranMaharjan@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:01:13 +0545 Subject: [PATCH 4/4] update min sdk and compile sdk version --- android/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 688dd5c..6ea46ad 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -30,7 +30,7 @@ android { namespace "com.pusher.channels_flutter" } - compileSdk 33 + compileSdk 34 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -46,7 +46,7 @@ android { } defaultConfig { - minSdkVersion 16 + minSdkVersion 23 } }