Plugin with native integration for WebSocket.

Overview

NOTE: This repository is no longer maintained by ENGAPP. It was moved to be maintained by Kunlatek on the following link: https://github.com/kunlatek/flutter_websocket_manager_plugin

Any issue regarding this plugin should be reported there.


Websocket Manager

A Flutter plugin for Android and iOS supports websockets. This plugin is based on two different native libraries Starscream for iOS and okHttp for Android.

This plugin was created due to our necessity to maintain a WebSocket connection active in background while Flutter's WebSocket from cookbook doesn't keep alive while screen is locked or the application was in background.

Introduction

Websocket Manager doesn't manipulate websockets in Dart codes directly, instead, the plugin uses Platform Channel to expose Dart APIs that Flutter application can use to communicate with two very powerful websocket native libraries. Because of that, all credits belong to these libraries.

How to install

Android

You only need this configuration if your server doesn't have SSL/TLS

Since Android P http is blocked by default and there are many ways to configure. One way to configure is explicitly saying that you accept clear text for some host.

  • Create res/xml/network_security_config.xml with content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">your_domain</domain>
    </domain-config>
</network-security-config>
  • Point to this file from your manifest (for bonus points add it only for the test manifest):
<application
    android:networkSecurityConfig="@xml/network_security_config"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity android:name=" (...)
</application>

iOS

Doesn't require any configuration

Example

int messageNum = 0;
// Configure WebSocket url
final socket = WebsocketManager('wss://echo.websocket.org');
// Listen to close message
socket.onClose((dynamic message) {
    print('close');
});
// Listen to server messages
socket.onMessage((dynamic message) {
    print('recv: $message');
    if messageNum == 10 {
        socket.close();
    } else {
        messageNum += 1;
        final String msg = '$messageNum: ${DateTime.now()}';
        print('send: $msg');
        socket.send(msg);
    }
});
// Connect to server
socket.connect();

Credits

Comments
  • Need null safety support

    Need null safety support

    from flutter v2.0.2, flutter is now null-safety mechanism. Most of the packages already upgrade to null safety and more are upgrading.

    Thanks for this great package!

    Do you plan to make a null safe version of the package?

    opened by Basher7 3
  • small issue

    small issue

    Hello, I'm glad to use the plugin you developed,This solved my big problem. Thank you very much for your selfless dedication. In use, I found a small problem. When using the client to send a heartbeat and the server to return a heartbeat, it always outputs a Received message on the command line: ******, I think this is unnecessary data, which will affect For other code debugging, you can consider whether to use print in the code I write.

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

    opened by byteslaves 1
  • Unhandled Exception: Stack Overflow

    Unhandled Exception: Stack Overflow

    Arruma essa merda, se vira

    [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: Stack Overflow #0 _rootRegisterCallback (dart:async/zone.dart:1154:1) #1 _CustomZone.registerCallback (dart:async/zone.dart:1045:19) #2 _CustomZone.bindCallbackGuarded (dart:async/zone.dart:962:22) #3 _rootScheduleMicrotask (dart:async/zone.dart:1178:16) #4 _CustomZone.scheduleMicrotask (dart:async/zone.dart:1080:19) #5 Future._asyncCompleteError (dart:async/future_impl.dart:577:11) #6 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:38:15) #7 WebSocketsHandler.initCommunication (package:bigu_passenger/src/screens/home/home_handlers/web_socket_handler/web_socket_handler.dart) #8 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) #9 WebSocketsHandler.initCommunication (package:bigu_passenger/src/screens/home/home_handlers/web_socket_handler/web_socket_handler.dart:27:33) #10 WebSocketsHandler.reconnectCommunication (package:bigu_passenger/src/screens/home/h<…>

    opened by fmmalta 0
  • Missing strategy to require service with or without background

    Missing strategy to require service with or without background

    It'd be interesting if we could invoke this service and saying if we want it to run in background or not.

    var url = "wss:'//DNS:PORT/endpoint";
    var nativeWebSockerService = NativeWebSocketService.Builder().withURL(url).asBackgroundService().build();
    

    Something like that.

    opened by ABuarque 0
  • onClose not working properly

    onClose not working properly

    We calling socket.onClose() and get success callback on "then" listener. but not work properly. and socket working stop another place. (when we use web & app same socket url)..

    opened by maulik-rain 0
  • java.io.EOFException in Android

    java.io.EOFException in Android

    I am getting this error when socket is on connection state.

    W/System.err(17899): java.io.EOFException W/System.err(17899): at okio.RealBufferedSource.require(RealBufferedSource.kt:201) W/System.err(17899): at okio.RealBufferedSource.readByte(RealBufferedSource.kt:210) W/System.err(17899): at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.kt:113) W/System.err(17899): at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:96) W/System.err(17899): at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:240) W/System.err(17899): at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:170) W/System.err(17899): at okhttp3.RealCall$AsyncCall.run(RealCall.kt:140) W/System.err(17899): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err(17899): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err(17899): at java.lang.Thread.run(Thread.java:919)

    please help me with thie error. Thanks.

    opened by ryz418 1
  • Plz provide `onOpen` and `onError` callback

    Plz provide `onOpen` and `onError` callback

    WebSocket should be a full-duplex technology. The current API only provides onMessage and onClose, which still lacks some events, such as onOpen and onError.

    opened by cangSDARM 1
  •  Socket disconnected automatically

    Socket disconnected automatically

    webSocketManager.connect(); webSocketManager.send( WebSocketConst.WEB_SOCKET_CONNECTION_SUBSCRIBE);

    after sometimes Socket disconnected automatically. please help

    opened by ghost 0
Owner
EngApp
Ambiente para crescimento do desenvolvedor.
EngApp
Community WebView Plugin - Allows Flutter to communicate with a native WebView.

NOTICE We are working closely with the Flutter Team to integrate all the Community Plugin features in the Official WebView Plugin. We will try our bes

Flutter Community 1.4k Dec 22, 2022
This is a Yoga app made in Flutter. This is an integration of a model that i found on https://www.uistore.design.

Yoguha A Flutter project made with Firebase that helps you for your next Yoga sessions. It contains : An authentication system A timer Some relaxing p

Scythe 2 Feb 1, 2022
This is an example project for Firebase integration using flutter.

Flutter Firebase Integration Example Project In this video we have shown how to create #Firebase app from firebase console and integrate that into #Fl

Flutter Tutorial 5 Jul 28, 2022
A basic implementation of the robot testing pattern for integration/e2e tests

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

Samuel Abada 3 Dec 13, 2021
Full Feature Todos Flutter Mobile app with fireStore integration.

IONICFIREBASEAPP DOWNLOAD TODO APP Marketplace for Mobile app and Backend that developed on leading Enterprise Technologies with as well as with your

Ionicfirebaseapp 138 Nov 4, 2022
Sample app to demonstrate the integration and working of Dyte SDK for mobile, using Flutter.

Flutter Sample App by dyte Sample App to demonstrate Dyte SDK in flutter Explore the docs » View Demo · Report Bug · Request Feature Table of Contents

Dyte 12 Jan 1, 2023
Paytm integration with flutter

pe_paytm A new Flutter package project is created by Harsh Tyagi ([email protected]) and Harsh Agrawal([email protected]). #For Demo Gett

Harsh Tyagi 8 May 11, 2022
Zaincash payment gateway integration for flutter

zaincash_flutter A none offical Zaincash payment gateway integration for flutter INSTALL in your project terminal enter dart pub add zaincash USE F

Karrar S. Honi 1 May 20, 2022
Studying Flutter and Firebase integration

Eventsapp Generated by the Very Good CLI ?? A Very Good Project created by Very

Felipe Gonçalves dos Reis 0 Dec 17, 2021
Simple examples that help you get started with Appwrite + Dart (=❤️) as an Appwrite server-side integration.

Playground for Dart Simple examples that help you get started with Appwrite + Dart (= ❤️ ) This is Appwrite server side integration with Dart. For Flu

Appwrite 31 Nov 22, 2022
Plant Manager is an application that was developed on Rocketseat NLW5 with React Native but was rebuilt using Flutter.

Technologies | Project | Layout | License ?? Technologies This project was developed with the following technologies: Flutter ?? Project Plant Manager

Mayderson 7 Aug 11, 2021
This is the new version of my Task app "Tasko" which was done in Java. She is now in Flutter for the HotReload and the native Cross-Platform.

tasko_rem The Tasko App is now compatible on iOS, Android and others distribution, because it's made with Flutter ✨ You can now add task, check them o

Scythe 12 May 2, 2022
A new practical project made with Flutter and some native widgets, movie API, provider state and more.

Flutter Movie App This project was created with Flutter and some native Widgets like SingleChildScrollView, Hero Animation, SliverAppBar, StreamBuilde

Paúl 4 Jul 12, 2022
Decentralized SkyDB-based alternative to Twitter, YouTube and Instagram with a native iOS, Android and web app.

SkyFeed SkyFeed is a decentralized SkyDB-based alternative to Twitter, YouTube and Instagram with a native Android, web and (soon) iOS app. Use You ne

null 88 Oct 28, 2022
For flutter native plugins, send event to main thread.

native_main_thread A new Flutter plugin. Getting Started This project is a starting point for a Flutter plug-in package, a specialized package that in

null 0 Nov 26, 2021
🚀 Full-Stack Flutter application, encoded using Dart. Utilizes native device features 📷 and stores user data on a local SQFLite database. ✔

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

Soumyadeep Das 2 Jan 24, 2022
A simple Flutter project demonstrating tailored native experiences

Voice Voice is a Flutter application that aims to help spread the awareness of animal rights groups from around the globe. Whilst data is still being

Joe Birch 69 Jun 17, 2021
This app is a Flutter port of the native Android App Cinematic.

Flutter Cinematic This app is a Flutter port of the native Android App Cinematic. My intention in creating this app was understanding the intricacies

Shrey Shourya 0 Nov 19, 2021
Flutter Music Player - First Open Source Flutter based material design music player with audio plugin to play local music files.

Flutter Music Player First Open Source Flutter based Beautiful Material Design Music Player(Online Radio will be added soon.) Demo App Play Store BETA

Pawan Kumar 1.5k Jan 8, 2023