Giter Club home page Giter Club logo

easysocketio's Introduction

EasySocketIO

EasySocketIo is a repository develop with annotation for a easy use of socket.io

Gradle

Compile my wrapper:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
  dependencies {
    implementation 'com.github.djamb.EasySocketIO:socketservicelibrary:1.0.6'
	}

Use example:

This code is a basic example. I recommend you go to Activities in app module and see all examples.

Instructions:

Permission

  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
  <uses-permission android:name="android.permission.WAKE_LOCK"/>

Step 1

Option 1

Baseapp extends BaseAppSocket and set your socket url, SocketGeneralEvents is not necessary, its a class for control general event in application enviorement.

AndroidManifest.xml

  <application
    android:usesCleartextTraffic="true"
    android:name=".BaseApp2"
  >

public class BaseApp extends BaseAppSocket {

  @Override
   public void onCreate() {
     super.onCreate();
     runService();
   }

  @Override
  public SocketParameterLibrary setSocketConfiguration() {
    return new SocketParameterLibrary("YOUR IP WITH PORT", "");
  }
}

Option 2

You can connect and disconnect socket server in any class of your project

AndroidManifest.xml

<application
  android:name="com.aminano.socketservicelibrary.BaseAppSocket"
  android:usesCleartextTraffic="true"
>

AnyClass

  application.runService();

     application.tryService(new BaseAppSocket.ServiceStatus() {
       @Override
       public void isRunning() {
         application.connect(new SocketParameterLibrary("http://192.168.1.108:3000",""));
         Log.i(TAG, "Send data to service?: " + application.sendData("message", "caca"));
       }
     });

Step 2

AnnotationWithBaseApp Need it for run service, warning, only need to use it in 1 activity

    public BaseApp application;
    application = (BaseApp) getApplicationContext();
    application.tryService(new BaseAppSocket.ServiceStatus() {
       @Override
       public void isRunning() {
         Log.i(TAG, "Send data to service?: " + application.sendData("message", "caca"));
       }
    });

Send data to socket server. Return true if its send it

 //Send data to event name
 application.sendData("message", "caca")

Need it for subscribe to event

    // Suscribe event from view
    StringChachi.bind2(this);

Method to recieve events from server

    @MethodValue(value = "messages")
      public void myMethod7(Object[] object) {
        Log.e("recive from server in event messages: ", "" + object[0]);
      }
 if you dont want receive more event in this view, its neccesary when it your are going to destroy your view
     // Unsuscribe event from view
        //StringChachi.unbind2(this);

#Custom option You can autorun service and run socket when android is rebooted //application.setAutoRunServiceWhenSystemOn(true); #PD. Gradle is buggy, not generated annotation files, use:

      classpath 'com.android.tools.build:gradle:3.5.0'
       ```

easysocketio's People

Contributors

djamb avatar

Stargazers

 avatar  avatar Pedro Sánchez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.