in my app I'm trying to communicate with a node server. I have setup the sockets using socket-io client library and done my initialization like this:
public io.socket.client.Socket mSocket;
try {
mSocket = IO.socket(Constants.PUBLIC_CHAT_ENDPOINT);
} catch (URISyntaxException e) {
e.printStackTrace();
}
The client i.e my app connects successfully to server and my first emit test was successful like this:
mSocket.emit("send-message", "Hello Server");
But when I try to emit my message like this
mSocket.on(Socket.EVENT_CONNECT, new io.socket.emitter.Emitter.Listener() {
@Override
public void call(Object... args) {
Snackbar.make(findViewById(android.R.id.content), "Connected", BaseTransientBottomBar.LENGTH_SHORT).show();
mSocket.emit(Constants.SOCKET_SEND_MESSAGE_EVENT, "Hello Server");
}
}). on("send-message", new io.socket.emitter.Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject messageObject = new JSONObject();
JSONObject metaMessageObject = new JSONObject();
JSONObject moreDetails = new JSONObject();
try {
moreDetails.put("roomId", chatRoomId);
moreDetails.put("userId", userId);
moreDetails.put("message", msg_body);
metaMessageObject.put("type", Constants.ChatCircle_Msg_Type);
metaMessageObject.put("content", moreDetails);
messageObject.put("data", metaMessageObject);
mSocket.emit("send-message", messageObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
}).on(Constants.SOCKET_GET_MESSAGE_EVENT, new io.socket.emitter.Emitter.Listener() {
@Override
public void call(Object... args) {
}
});
mSocket.connect();
, message is not registered. Pls am I doing this wrongly? Thanks everyone.