An unofficial Flutter plugin that wraps pusher-websocket-java on Android and pusher-websocket-swift on iOS

Overview

Pusher Flutter Client

An unofficial Flutter plugin that wraps pusher-websocket-java on Android and pusher-websocket-swift on iOS.

Get it from pub.

How to install

  • Add to your pubspec.yaml
dependencies:
  pusher_websocket_flutter: ^0.2.0
  • In /ios/Podfile, set global platform to at least 9.0 platform :ios, '9.0'

For iOS Objective-C based Flutter apps

It is currently a bit difficult to get some Swift based Flutter plugins working in an Objective-C based Flutter app. See here for info and here for a way to fix.

This set of steps should work to fix this for your project.

  • Add use_frameworks! to the end of the Runner section in /ios/Podfile
  • Set Swift version in your iOS Runner project.
    • Open the project with Xcode.
    • In Runner, File -> New -> File -> Swift File. Name it anything.
    • Xcode will ask you if you wish to create Bridging Header, click yes.
    • Go to Runner Build Settings and set SWIFT_VERSION to either 4.2 or 5.0
    • Delete the Swift file created in step 2
    • Delete the Bridging Header created in step 3
  • flutter clean
  • In /ios pod install --repo-update

If you have trouble, try checking out the example_objc Flutter project.

How to use

Pusher.init( ... )

Parameter Type Description
appKey String Required - The application key is a string which is globally unique to your application. It can be found in the API Access section of your application within the Channels user dashboard.
options PusherOptions Required - The options provided to pusher, more information in the PusherOptions section.
enableLogging bool Optional - Enabling this will activate the logging of important events to the console.

Pusher.connect( ... )

Parameter Type Description
onConnectionStateChange Function(ConnectionStateChange) Optional - Callback when the state of the connection changes (eg. CONNECTING, CONNECTED, DISCONNECTED, ... ).
onError Function(ConnectionError) Optional - Callback when the connection fires an error (eg. UnauthorizedException).

Pusher.subscribe( ... )

Parameter Type Description
channelName String Required - provide the channel name to subscribe to (eg. mychannel, private-mychannel or presence-mychannel).

Pusher.getSocketId()

Returns the current socket ID, updated after a connection change

PusherOptions

Parameter Type Description
auth PusherAuth Optional - A mechanism for authenticating a user's access to a channel at the point of subscription.
cluster String Optional - The identifier of the cluster your application was created in. When not supplied, will connect to the mt1(us-east-1) cluster.
host String Optional - Provide your own (websocket) host instead of the default ws.pusherapp.com
port int Optional - Provide your own (websocket) port instead of the default 443 (when encryption is enabled) or port 80 (when encryption is disabled).
encrypted bool Optional - Tell pusher to only connect over TLS connections to ensure connection traffic is encrypted. This means using wss:// instead of ws://, encryption is enabled by default.
activityTimeout int Optional - After this time (in milliseconds) without any messages received from the server, a ping message will be sent to check if the connection is still working. Default value is supplied by the server, low values will result in unnecessary traffic. The default is set to 30000.

PusherAuth

Parameter Type Description
endpoint String Required - The endpoint pusher should query to make the post request (eg. https://api.example.com/broadcating/auth).
headers Map<String,String> Optional - The headers that should be sent with the POST request to the above endpoint. 2 Different Content-Types are supported: application/x-www-form-urlencoded & application/json. Supplying any of the above types will result into the request body being sent in form-urlencoded format or JSON format. Defaults to {'Content-Type': 'application/x-www-form-urlencoded'}

Development

This project uses code generation. Run after changing models in the project.

flutter packages pub run build_runner build --delete-conflicting-outputs

Comments
  • Allow setting of host and port in PusherOptions

    Allow setting of host and port in PusherOptions

    Hey guys, first of all I'm glad for this package, using it for a month now.

    PusherOptions only takes cluster as a parameter but I need to set host and port.

    Can you guys help me to achieve that or add it to the package if you have time to do that?

    I've also do some work on it but It gives me connection exception, I'd appreciate some help. https://github.com/mirkancal/pusher-websocket-flutter

    enhancement 
    opened by mirkancal 6
  • An application doesn't receive data on iOS

    An application doesn't receive data on iOS

    pusher_websocket_flutter: ^0.1.1

    The code shown below is successfully initialized, connected and subscribed to pusher service but doesn't receive data from the channel.bind method. If I put logs in _initializePusherService and subscribe I can see them, but not from inside channel.bind.

    Tested and does not work:

    1. Real devices with iOS versions: 12.4.3 and 13.1.3 (iPhone 5s and iPhone X)
    2. On every iPhone available in Xcode simulator

    Note: This code works perfectly on any android version and device. (Receiving data)

    Reproducible code

    
    import 'dart:async';
    import 'package:pusher_websocket_flutter/pusher.dart';
    
    const channelName = "myChannelName";
    const eventName = "myEventName";
    const clusterName = "myClusterName";
    
    class PusherService {
      static final PusherService _instance = PusherService._privateConstructor();
    
      StreamController<List> _streamController = StreamController<List>.broadcast();
      Sink get _inEventData => _streamController.sink;
    
      factory PusherService() {
        return _instance;
      }
    
      PusherService._privateConstructor() {
        _initializePusherService();
      }
    
      void _initializePusherService() async {
        await Pusher.init("pusherUrl", PusherOptions(cluster: clusterName));
        Pusher.connect(
            onConnectionStateChange: (ConnectionStateChange connectionState) async {
          print('PusherService - connection status changed: ' +
              connectionState.currentState);
        }, onError: (ConnectionError error) {
          print('PusherService - error: ' + error.message);
        });
      }
    
      void subscribe() {
        Pusher.subscribe(channelName).then((Channel channel) {
          channel.bind(eventName, (Event last) {
            print("PusherService - Received new data");
            _inEventData.add(last.data);
          });
        });
      }
    
      void unsubscribe() {
        print("PusherService - Unsubscribing from this service.");
        Pusher.unsubscribe(channelName);
      }
    }
    
    

    I am importing this class in main.dart fail and calling it like this

      @override
      void initState() {
        PusherService().subscribe();
      }
    

    Here is my flutter doctor -v

    flutter-doctor

    opened by DorianSaboBM 4
  • Push Notifications

    Push Notifications

    Good night to who created this library.

    Today I come with a question to you, since I would like to implement push notifications through pusher in my flutter app, I look forward to your response

    opened by KuroBech 1
  • Support for getting pusher result when app is not in background

    Support for getting pusher result when app is not in background

    I am able to receive pusher events when the app is running in background or when the app is open . When i clear the app from background it does not receive events .

    opened by rt16 1
  • Importing package fails with error

    Importing package fails with error

    When trying to include version 0.0.7 to the project, I get an error first that SWIFT_VERSION is not specified in the Podfile, after which I open podfile and add version 4.1 as a dependency. Then another error appears, related to umbrella header, I have no idea how to fix:

    Error output from Xcode build: ↳ ** BUILD FAILED ** Xcode's output: ↳ === BUILD TARGET pusher_websocket_flutter OF PROJECT Pods WITH CONFIGURATION Debug === While building module 'pusher_websocket_flutter' imported from /Users/aleksandarlugonja/Desktop/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/pusher_websocket_flutter-0.0.7/ios/Classes/PusherPlugin.m:2: While building module 'PusherSwift' imported from /Users/aleksandarlugonja/Desktop/development/myApp/build/ios/Debug-iphonesimulator/pusher_websocket_flutter/pusher_websocket_flutter.framework/Headers/pusher_websocket_flutter-Swift.h:171: In file included from :2: /Users/aleksandarlugonja/Desktop/development/myApp/build/ios/Debug-iphonesimulator/PusherSwift/Swift Compatibility Header/PusherSwift-Swift.h:481:12: warning: parameter 'channelName' not found in the function declaration [-Wdocumentation] /// \param channelName The name of the channel ^~~~~~~~~~~ /Users/aleksandarlugonja/Desktop/development/myApp/build/ios/Debug-iphonesimulator/PusherSwift/Swift Compatibility Header/PusherSwift-Swift.h:481:12: note: did you mean 'channel'? /// \param channelName The name of the channel ^~~~~~~~~~~ channel While building module 'pusher_websocket_flutter' imported from /Users/aleksandarlugonja/Desktop/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/pusher_websocket_flutter-0.0.7/ios/Classes/PusherPlugin.m:2: While building module 'PusherSwift' imported from /Users/aleksandarlugonja/Desktop/development/myApp/build/ios/Debug-iphonesimulator/pusher_websocket_flutter/pusher_websocket_flutter.framework/Headers/pusher_websocket_flutter-Swift.h:171: :1:1: warning: umbrella header for module 'PusherSwift' does not include header '/PusherSwift.framework/Headers/PusherSwift-umbrella.h' [-Wincomplete-umbrella] #import "PusherSwift-umbrella.h" ^ :1:1: warning: umbrella header for module 'PusherSwift' does not include header '/PusherSwift.framework/Headers/PusherSwift-Swift.h' [-Wincomplete-umbrella] 3 warnings generated. 3 warnings generated. /Users/aleksandarlugonja/Desktop/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/pusher_websocket_flutter-0.0.7/ios/Classes/PusherPlugin.m:4:17: error: definition of 'PusherPlugin' must be imported from module 'pusher_websocket_flutter.PusherPlugin' before it is required @implementation PusherPlugin ^ In module 'pusher_websocket_flutter' imported from /Users/aleksandarlugonja/Desktop/FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/pusher_websocket_flutter-0.0.7/ios/Classes/PusherPlugin.m:2: /Users/aleksandarlugonja/Desktop/development/myApp/build/ios/Debug-iphonesimulator/pusher_websocket_flutter/pusher_websocket_flutter.framework/Headers/PusherPlugin.h:3:12: note: previous definition is here @interface PusherPlugin : NSObject ^ 3 warnings and 1 error generated.

    What am I missing here? Podfile has platform set to 9.0, and swift version set to 4.1. I've also tried with 4.0, 5.0, and no luck...

    opened by LugonjaAleksandar 0
  • ConnectionStateChange DISCONNECTED

    ConnectionStateChange DISCONNECTED

    I have a view with a bottomNavigationBar, when I move between each tab, the Pusher connection changes to: DISCONNECTED. I only execute the action of "pusher.connect" in the initState of the view

    opened by SANCHEZSJD 2
  • Unexpected error when starting pusher

    Unexpected error when starting pusher

    Unexpected error when starting pusher

    try { await Pusher.init(appKey, options); } catch (e) { print("Error in Pusher.init"); print(e.message); } ` D/PusherPlugin(32719): onCancel args: null

    E/MethodChannel#pusher(32719): Failed to handle method call E/MethodChannel#pusher(32719): java.util.ConcurrentModificationException E/MethodChannel#pusher(32719): at java.util.HashMap$HashIterator.nextNode(HashMap.java:1441) E/MethodChannel#pusher(32719): at java.util.HashMap$EntryIterator.next(HashMap.java:1475) E/MethodChannel#pusher(32719): at java.util.HashMap$EntryIterator.next(HashMap.java:1473) E/MethodChannel#pusher(32719): at com.pusherwebsocket.pusher.PusherPlugin.init(PusherPlugin.java:114) E/MethodChannel#pusher(32719): at com.pusherwebsocket.pusher.PusherPlugin.onMethodCall(PusherPlugin.java:83) E/MethodChannel#pusher(32719): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230) E/MethodChannel#pusher(32719): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#pusher(32719): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692) E/MethodChannel#pusher(32719): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#pusher(32719): at android.os.MessageQueue.next(MessageQueue.java:326) E/MethodChannel#pusher(32719): at android.os.Looper.loop(Looper.java:165) E/MethodChannel#pusher(32719): at android.app.ActivityThread.main(ActivityThread.java:6831) E/MethodChannel#pusher(32719): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#pusher(32719): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) E/MethodChannel#pusher(32719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927) `

    opened by SANCHEZSJD 1
  • pod install giving errors

    pod install giving errors

    Hi,

    After I run pod install, I get these errors:

    [!] A license was specified in podspec pusher_websocket_flutter but the file does not exist - .../ios/.symlinks/plugins/LICENSE

    [!] Unable to read the license file ../../LICENSE for the spec pusher_websocket_flutter (0.1.1)

    [!] Unable to read the license file ../../LICENSE for the spec pusher_websocket_flutter (0.1.1)

    I see the license file but it at .../ios/.symlinks/plugins/pusher_websocket_flutter/LICENSE

    Please help!

    Thanks, Shilpi

    bug 
    opened by shanaya-kanade 4
  • FileNotFoundException on subscribing to private channel

    FileNotFoundException on subscribing to private channel

    Hello, thank you very much for this package. I am successfully able to subscribe to the public channels and receive events that are sent from the pusher debug console. The exception is thrown when I am trying to subscribe to private channels. I have in the backend written in laravel. I'm not a back end developer so I could not debug if the problem is on the back end.

    I pass the required auth endpoint and also the request headers to PusherAuth. When I try to connect to the pusher cancel and subscribe to a private channel I get this file not found exception which points to the auth endpoint URL as below

    D/PusherPlugin( 8418): onCancel args: null
    D/PusherPlugin( 8418): init
    D/PusherPlugin( 8418): connect
    D/PusherPlugin( 8418): subscribe (private)
    D/PusherPlugin( 8418): bind (BroadcastNotificationCreated)
    I/flutter ( 8418): CONNECTING
    I/flutter ( 8418): CONNECTED
    D/PusherPlugin( 8418): onError : java.io.FileNotFoundException: https://<my-url>/broadcasting/auth
    W/System.err( 8418): com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: https://<my-url>/broadcasting/auth
    W/System.err( 8418): 	at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:146)
    W/System.err( 8418): 	at com.pusher.client.channel.impl.PrivateChannelImpl.getAuthResponse(PrivateChannelImpl.java:127)
    W/System.err( 8418): 	at com.pusher.client.channel.impl.PrivateChannelImpl.toSubscribeMessage(PrivateChannelImpl.java:90)
    W/System.err( 8418): 	at com.pusher.client.channel.impl.ChannelManager$1.run(ChannelManager.java:140)
    W/System.err( 8418): 	at com.pusher.client.util.Factory$1.run(Factory.java:109)
    W/System.err( 8418): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    W/System.err( 8418): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    W/System.err( 8418): 	at java.lang.Thread.run(Thread.java:764)
    W/System.err( 8418): Caused by: java.io.FileNotFoundException: https://<my-url>/broadcasting/auth
    W/System.err( 8418): 	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
    W/System.err( 8418): 	at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
    W/System.err( 8418): 	at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
    W/System.err( 8418): 	at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:128)
    W/System.err( 8418): 	... 7 more
    I/flutter ( 8418): java.io.FileNotFoundException: https://<my-url>/broadcasting/auth
    W/OkHttpClient( 8418): A connection to <my-url> was leaked. Did you forget to close a response body?
    
    

    I cannot add the real URL above in the logs so added . The laravel code does not have any auth endpoint set, so according to the laravel docs the default is /broadcasting/auth. Any help is appreciated.

    opened by rvamsikrishna 4
  • Support Flutter Web

    Support Flutter Web

    The following code is supposed to works for the initialization of pusher Works in Android and iOS

     await Pusher.init( "KEY", PusherOptions(cluster: "-",), enableLogging: true);
    

    With flutter web this initialization code is even unable to initiate, no errors apparently, just the line is never completed and the code gets stopped.

    enhancement 
    opened by josancamon19 2
  • Invalid signature: Expected HMAC SHA256 Error

    Invalid signature: Expected HMAC SHA256 Error

    I am trying to subscribe to a private room, but getting this invalid signature error.

    Invalid signature: Expected HMAC SHA256 hex digest of 8910.66062685:private-5eb108e1110adb4c7da27e34, but got 64ea520ef7a27ed2604d36768c514e2ba38fe78273edfba77878b77585bb90fd

    I've read this (https://support.pusher.com/hc/en-us/articles/360019306433-I-receive-Invalid-signature-Expected-HMAC-SHA256-error-what-is-that-) article and tried a few changes in the backend but it is not working.

    opened by KAIMonmoy 2
Owner
HomeX
HomeX
Wraps Flutter shared_preferences plugin, providing a iOS Suite Name support, it's helpful for sharing data from App to Widget.

shared_preferences_ios_sn Wraps Flutter shared_preferences plugin and provides an iOS Suite Name support, it's helpful for sharing data from App to iO

null 3 Sep 14, 2022
A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

Ably Flutter Plugin A Flutter plugin wrapping the ably-cocoa (iOS) and ably-java (Android) client library SDKs for Ably, the platform that powers sync

Ably Realtime - our client library SDKs and libraries 46 Dec 13, 2022
ESP-Touch Dart API for Flutter. Platform-specific implementation for Android (Java) and iOS (Objective-C).

esptouch_flutter Flutter plugin for ESP-Touch to configure network for ESP-8266 and ESP-32 devices. Runs on iOS and Android. esptouch_flutter is Flutt

SMAHO Engineering OSS 86 Dec 10, 2022
Unofficial conference app 2020 - The Unofficial Conference App for DroidKaigi 2020 Tokyo.

DroidKaigi 2020 Flutter App ?? The unofficial conference app for DroidKaigi 2020. DroidKaigi 2020 is a conference tailored for developers on 20th and

Kazuki YAMAGUCHI 95 Nov 4, 2022
Helper app to run code on Aliucord iOS via websocket.

aliucordebug A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Zoey 2 Jan 25, 2022
Dart package that conveniently wraps an isolate, ports and state for easy isolates.

Isolate Agents Description Isolate Agents adds a new class, Agent, which is a proper implementation of the Actor model for Dart. Where Isolates have n

null 65 Jan 2, 2023
Unofficial KronoX app for Android and iOS

School Schedule Unofficial KronoX app for Android and iOS made using Flutter Supported Platforms The app is available on Google Play. It's not availab

kraxie 8 Oct 31, 2022
Dart API Client which wraps the QvaPay API

qvapay_api_client Dart API Client which wraps the QvaPay API The client needs Dio to perform the requests, you must inject an instance in the construc

QvaPay 7 Nov 2, 2022
Ensdart - A dart library that wraps the Ethereum Name Service

⚡️ ENS Dart A dart library that wraps the Ethereum Name Service. The Ethereum Na

Chiziaruhoma Ogbonda 22 Nov 29, 2022
Safe is an open source mobile platorm to discretely capture incidents with ease, powered by an SMCE written in native Swift and Kotlin.

Safe A powerful tool for personal and community safety. joinsafe.me » Available for iOS & Android ~ Links will be added once a release is available. ~

Safe 10 Oct 26, 2022
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

null 8.3k Dec 31, 2022
Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui.

tenon_mortise Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui. Getting Started Usage To use this plugin

JieLiu 4 Dec 15, 2022
a project-m36 websocket client written by flutter/dart

project_m36_websocket_client A Flutter web websocket client for Project-M36. It's also an attempt to bring algebraic datatypes into the Dart land. Pro

null 1 Jan 8, 2022
projeto de flutter com Websocket para aplicações com atualização em tempo real, demonstração com chat.

chat_socket A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Luanzera07 0 Jan 3, 2022
Integrating ChatMessaging via WebSocket (socket_io package) in Flutter Application

Chat Messaging via WebSocket Integrating ChatMessaging via WebSocket (socket_io_client package) in Flutter Application. The server is also built in Da

Saksham Gupta 2 Jul 26, 2022
The unofficial flutter plugin for Freshchat

?? Flutter Freshchat A Flutter plugin for integrating Freshchat in your mobile app. Setup Android Add this to your AndroidManifest.xml <provider a

Fayeed Pawaskar 31 Jun 2, 2022
WooCommerce App template that uses Flutter. Integrated to work with WooCommerce stores, connect and create an IOS and Android app from Flutter for IOS and Android

WooCommerce App: Label StoreMax Label StoreMax - v5.3.1 Official WooSignal WooCommerce App About Label StoreMax Label StoreMax is an App Template for

WooSignal 314 Jan 9, 2023
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

Flutter permission_handler plugin The Flutter permission_handler plugin is build following the federated plugin architecture. A detailed explanation o

Baseflow 1.7k Dec 31, 2022
Klutter plugin makes it possible to write a Flutter plugin for both Android and iOS using Kotlin only.

The Klutter Framework makes it possible to write a Flutter plugin for both Android and iOS using Kotlin Multiplatform. Instead of writing platform spe

Gillian 33 Dec 18, 2022