Skip to content

Commit

Permalink
在线状态回调添加其他端的状态
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed Mar 23, 2024
1 parent 0a05503 commit 37f1772
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
23 changes: 22 additions & 1 deletion broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.moquette.spi.impl;

import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.OutputCheckUserOnline;
import cn.wildfirechat.pojos.UserOnlineStatus;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
Expand Down Expand Up @@ -266,7 +267,27 @@ public void forwardOnlineStatusEvent(String userId, String clientId, int platfor
if (!StringUtil.isNullOrEmpty(mUserOnlineStatusCallback)) {
mServer.getCallbackScheduler().execute(() -> {
try {
HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName)), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback);
int sessionstatus;
Collection<MemorySessionStore.Session> useSessions = m_sessionsStore.sessionForUser(userId);
UserOnlineStatus userOnlineStatus = new UserOnlineStatus(userId, clientId, platform, status, packageName);
userOnlineStatus.sessions = new ArrayList<>();

for (MemorySessionStore.Session session : useSessions) {
if (session.getDeleted() > 0) {
continue;
}

ConnectionDescriptor descriptor = connectionDescriptors.getConnection(session.getClientID());
if (descriptor == null) {
sessionstatus = 1;
} else {
sessionstatus = 0;
}

userOnlineStatus.sessions.add(new OutputCheckUserOnline.Session(userId, session.getClientID(), session.getPlatform(), sessionstatus, session.getLastActiveTime(), session.getAppName()));
}

HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(userOnlineStatus), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback);
} catch (Exception e) {
e.printStackTrace();
Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void checkUserOnlineHandler(byte[] payloadContent, RouteCallback callback) {
status = 0;
}

out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime());
out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime(), session.getAppName());
}

callback.onRouteHandled(GsonUtil.gson.toJson(out).getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ public static class Session {
public int platform;
public int status; //0 online, 1 have session offline
public long lastSeen;
public String packageName;

public Session(String clientId, String userId, int platform, int status, long lastSeen) {
public Session() {
}

public Session(String clientId, String userId, int platform, int status, long lastSeen, String packageName) {
this.clientId = clientId;
this.userId = userId;
this.platform = platform;
this.status = status;
this.lastSeen = lastSeen;
this.packageName = packageName;
}
}

public void addSession(String userId, String clientId, int platform, int status, long lastSeen) {
Session session = new Session(clientId, userId, platform, status, lastSeen);
public void addSession(String userId, String clientId, int platform, int status, long lastSeen, String packageName) {
Session session = new Session(clientId, userId, platform, status, lastSeen, packageName);
sessions.add(session);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cn.wildfirechat.pojos;

import java.util.List;

public class UserOnlineStatus {
public static final int ONLINE = 0;
public static final int OFFLINE = 1;
Expand All @@ -11,6 +13,9 @@ public class UserOnlineStatus {
public int status;
public long timestamp;
public String packageName;
public int customState;
public String customText;
public List<OutputCheckUserOnline.Session> sessions;

public UserOnlineStatus() {
}
Expand Down

0 comments on commit 37f1772

Please sign in to comment.