Giter VIP home page Giter VIP logo

adonis-websocket-client-android's People

Contributors

utsavstha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bellalmohamed

adonis-websocket-client-android's Issues

Cannot send message in different event type

hi @utsavstha , thank you for your useful package. from your docs for sending a message we must use this:

JSONObject jsonObject = new JSONObject();
jsonObject.put("username", username);
socket.send("topic_name", jsonObject.toString()); //Yes this has to be json.

but send function just get topic name and payload data and cannot get custom event.
there is send function in adoniswebsocketclient/src/main/java/np/com/blackspring/adoniswebsocketclient/Socket.java file and event is hard coded to 'message'

/**
     * Send message in {event->data} format
     *
     * @param event event name that you want sent message to
     * @param data  message data in JSON format
     * @return true if the message send/on socket send quest; false otherwise
     */
    public boolean send(@NonNull String event, @NonNull String data) {
        try {
            JSONObject text = new JSONObject();
            JSONObject topic = new JSONObject();
            topic.put("topic", event);
            topic.put("event", "message");
            topic.put("data", new JSONObject(data));
            text.put("t", 7);
            text.put("d", topic);
            Log.v(TAG, "Try to send data " + text.toString());

            return realWebSocket.send(text.toString());
        } catch (JSONException e) {
            Log.e(TAG, "Try to send data with wrong JSON format, data: " + data);
        }
        return false;
    }

i think you must add topic name variable and set it to topic and set event to event key.

Can i listen for more than one event in the same topic?

socket.onEvent(Socket.EVENT_OPEN, new Socket.OnEventListener() {
@OverRide
public void onMessage(String event) {

        }
    });

    socket.onEventResponse("test:modify", new Socket.OnEventResponseListener() {
        @Override
        public void onMessage(String event, String data) {

        }
    });

    socket.onEventResponse("test:1", new Socket.OnEventResponseListener() {
        @Override
        public void onMessage(String event, String data) {

        }
    });

How to retrieve info from the Events?

From your docs I use this:

socket.onEventResponse("message", new Socket.OnEventResponseListener() {
    @Override
    public void onMessage(String event, String data) {
        System.out.println(data);
    }
});

And in this part I can not retrieve data from the websocket, I got the message from logcat, that I received new message and I can see the data but I can not use it.

In the server I have in controller

'use` strict'

class GeneralController {
  constructor ({ socket, request }) {
    this.socket = socket
    this.request = request
    console.log('user joined with %s socket id', socket.id)
  }

  onMessage() {
   this.socket.broadcastToAll('message','Hello Everyone')
 }
}

And in socket.js

const Ws = use('Ws')
Ws.channel('test','GeneralController')

And in android:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       Socket socket = Socket.Builder.with("ws://127.0.0.1:3333/adonis-ws").build();
       socket.connect();
}

Empty project with empty activity.

How to authenticate normal login

Hello, excuse the question, how can I secure the connection through Auth ?. For example for normal login email and password, where I place these parameters.

Thank you for your work

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.