adhara_socket_io 0.3.3

adhara_socket_io #

socket.io for flutter by adhara

supports both Android and iOS

Usage:

See example/lib/main.dart for better example

    SocketIOManager manager = SocketIOManager();
    SocketIO socket = manager.createInstance('http://192.168.1.2:7000/');       //TODO change the port  accordingly
    socket.onConnect((data){
      print("connected...");
      print(data);
      socket.emit("message", ["Hello world!"]);
    });
    socket.on("news", (data){   //sample event
      print("news");
      print(data);
    });
    socket.connect();
    ///disconnect using
    ///manager.

To request callback on ack:

  socket.emitWithAck("message", ["Hello world!"]).then( (data) {
    // this callback runs when this specific message is acknowledged by the server
    print(data);
  });

Running example: #

  1. Open example/ios in XCode or example/android in android studio. Build the code once (cd example & flutter build apk | flutter build ios --no-codesign)

  2. cd example/socket.io.server

    1 run npm i

    2 run npm start

  3. open example/lib/main.dart and edit the URI in #7 to point to your hosted/local socket server instances as mentioned step 2

    For example:

     const String URI = "http://192.168.1.2:7000/";
    
     const String URI = "http://mysite.com/";
    
  4. run Android/iOS app

iOS support 📢📢 #

This project uses Swift for iOS support, please enable Swift support for your project for this plugin to work

Android support for SDK > 27 #

Configure android:usesCleartextTraffic="true" as a property of <application ...> tag in android/app/src/main/AndroidManifest.xml

For example:


<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="adhara_socket_io_example"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"...>...</activity>

Refer to discussion here

Other Packages: #

Feel free to checkout our Adhara package

0.3.3 - 14th August, 2019 #

  • Typo fix for nameSpace ( changed SocketOptions.namesapce to SocketOptions.nameSpace )

0.3.2 - 11th August, 2019 #

  • ACK Bug fixes for android 27+ | UIThread/EventThread issue resolved

0.3.1 - 11th August, 2019 #

  • Bug fixes from 0.3.0

0.3.0 - 11th August, 2019 #

Bulk update #

  • PR 18 - Update deployment target to 9.0 and allow for most recent version of Starscream
  • PR 27 - Android bug fix | Methods marked with @UiThread must be executed on the main thread
  • PR 35 - ACK Support
  • PR 44 - fix for duplicated listeners from platform channel
  • PR 45 - Bug Fix | Java class cast exception for timeout
  • PR 48 - Bug Fix | Swift version error on pod install
  • PR 52 - Namespace support for iOS | Any contributors can develop similarly for android

0.2.0 - 5th June, 2019 #

Breaking Change #

  • Convert all arguments for SocketIOManager to a single Options object

old config

socket = await manager.createInstance(
  URI,
  query: {"auth": "--SOME AUTH STRING---",},
  enableLogging: false
);

new config

socket = await manager.createInstance(SocketOptions(
    URI,
    query: {"auth": "--SOME AUTH STRING---",},
    enableLogging: false,
));
  • Introducing transports in SocketOptions

0.1.11 - 5th June, 2019 #

0.1.10 - 26th February, 2019 #

  • clearInstance BugFix on iOS

0.1.9 - 21st January, 2019 #

  • BugFix for iOS running on iPhone 6

0.1.8 - 17th January, 2019 #

  • Optimized serialization code for Android
  • Bug fix for Map representation characters/reserved characters for map representation as a string (= and /)

0.1.7 - 17th January, 2019 #

  • Disabling unnecessary logging of events in platform implementations in both Android and iOS, can enable if required by passing enableLogging: true to createInstance

0.1.6 - 28th November, 2018 #

  • Android and iOS data serialization handled properly to send objects and arrays

0.1.4 - 28th November, 2018 #

  • Android query bug: Extra ? is being sent. fixed

0.1.3 - 21st November, 2018 #

  • Added support for socket.io handshake query params for both iOS and Android

0.1.2 - 20th November, 2018 #

  • Fully working version of basic Socket.io connection for both Android and iOS

example/README.md

adhara_socket_io_example #

Usage:

See example/lib/main.dart for better example


    SocketIO socket = await SocketIOManager().createInstance('http://192.168.1.2:7000/');       //TODO change the port  accordingly
    socket.onConnect((data){
      print("connected...");
      print(data);
      socket.emit("message", ["Hello world!"]);
    });
    socket.on("news", (data){   //sample event
      print("news");
      print(data);
    });
    socket.connect();

Running example: #

  1. Open example/ios in XCode or example/android in android studio. Build the code once (cd example & flutter build apk | flutter build ios --no-codesign)

  2. cd example/socket.io.server

    1 run npm i

    2 run npm start

  3. open example/lib/main.dart and edit the URI in #7 to point to your hosted/local socket server instances as mentioned step 2

  4. run Android/iOS app

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  adhara_socket_io: ^0.3.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:adhara_socket_io/adhara_socket_io.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
96
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8