tazz_socket 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

socket_flutter_plugin #

socket_flutter_plugin on GitHub

tazz_socket #

Fork of socket_flutter_plugin with additional Options for Socket.IO clients.

Support both Android and iOS, custom Options only on Android

Definition: #

Future<String> socket(url, path, transport, sslAcceptAll, forceNew, debug) async
  • URL (String): protocol, server and port only, e.g.: 'http://10.2.2.22:9006'<br/>
  • Path (String): relative path for socket, or empty; e.g.: '/v2/socket.io'<br/>
  • Transport (String): transport to use, websocket OR polling<br/>
  • sslAcceptAll (boolean): accept all SSL certificates, including self-signed?<br/>
  • forceNew (boolean): force a new connection?<br/>
  • debug (boolean): print debug statements from native code<br/>

Usage: #

Pubspec: #

tazz_socket: ^1.0.0

Code: #

import 'package:tazz_socket/tazz_socket.dart';
// ...

IO.socket('http://10.2.2.22:9006', '/v2/socket.io', 'websocket', true, true, true);

Example #

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:tazz_socket/tazz_socket.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  String _platformVersion = 'Unknown';
  static const String socket_topic = 'response';
  SocketFlutterPlugin myIO = new SocketFlutterPlugin();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    initPlatformState();
  }

  @override
  void dispose() {
    myIO.unsubscribe(socket_topic);
    myIO.disconnect();
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.inactive:
        myIO.unsubscribe(socket_topic);
        myIO.disconnect();
        break;
      case AppLifecycleState.resumed:
        initPlatformState();
        break;
      default:
    }
  }


  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    try {
      myIO.socket('http://10.2.2.22:9006', '/v2/socket.io', 'websocket', true, true, true);
      myIO.connect();
      String jsonData = '{"hello":"hi"}';
      myIO.on(socket_topic,(data){
        debugPrint(data.toString());
      });
      myIO.emit('request',jsonEncode(jsonDecode(jsonData)));
    } on PlatformException {
      _platformVersion = 'Failed to get platform version.';
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: new Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}

Changelog #

1.0.1 #

  • Implemented custom Options for Socket connections on the native side

1.0.3 #

  • Added iOS compatibility and native code

1.0.4 #

  • Minor pubspec changes

example/README.md

socket_flutter_plugin_example #

Demonstrates how to use the tazz_socket plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  tazz_socket: ^1.0.4

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:tazz_socket/tazz_socket.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/tazz_socket.dart. (-1 points)

Analysis of lib/tazz_socket.dart reported 2 hints:

line 51 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

line 69 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8