java - Android socket io get online user -
i developing android private chat application. in application, want see online user or check whether user online or not. have got reference.
emit("login",userid);
is used online users. use
public class onlineactivity extends appcompatactivity { private socket msocket; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_online); chatapplication app = (chatapplication) getapplication(); msocket = app.getsocket(); jsonobject user = new jsonobject(); try { user.put("userid", "abc"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } msocket.emit("login",user); log.d("log", string.valueof(msocket.emit("login",user))); log.d("log", string.valueof(user)); } }
where abc user id, not show results. please me.
the answer shown in how check user online or not in socket io , android chat application
socket.on('isactive', function (user) { const userid = user.userid; const user = usernames[userid]; const socketid = socket.id; let response; if(user) { // user active response = {isactive: true}; } else { // user not active response = {isactive: false}; } const responsesocket = io.sockets.connected[socketid]; if(responsesocket) { responsesocket.emit('onisactive', response); } });
Comments
Post a Comment