SHA256
Исправить подпись сигналов звонка и ширину чата
This commit is contained in:
+5
-61
@@ -36,7 +36,6 @@ public class Net_SendSignal_Handler implements JsonMessageHandler {
|
||||
private static final String TARGET_MODE_SINGLE = "single_session";
|
||||
private static final String TARGET_MODE_ALL = "all_sessions";
|
||||
private static final long ALLOWED_SKEW_MS = 30_000L;
|
||||
private static final long PUSH_CALL_TTL_MS = 10_000L;
|
||||
private static final String SIGNAL_CALL_INVITE = "call_invite";
|
||||
private static final String SIGNAL_CALL_ACCEPT = "call_accept";
|
||||
private static final String SIGNAL_CALL_DECLINE_BUSY = "call_decline_busy";
|
||||
@@ -120,13 +119,12 @@ public class Net_SendSignal_Handler implements JsonMessageHandler {
|
||||
}
|
||||
|
||||
List<ConnectionContext> targets = resolveTargets(targetMode, toLogin, targetSessionId);
|
||||
boolean isCallInviteAllSessions = TARGET_MODE_ALL.equals(targetMode) && SIGNAL_CALL_INVITE.equals(signalType);
|
||||
boolean isCallAcceptSingleSession = TARGET_MODE_SINGLE.equals(targetMode) && SIGNAL_CALL_ACCEPT.equals(signalType);
|
||||
boolean isCallTerminalSingleSession = TARGET_MODE_SINGLE.equals(targetMode)
|
||||
&& (SIGNAL_CALL_DECLINE_BUSY.equals(signalType)
|
||||
|| SIGNAL_CALL_TIMEOUT.equals(signalType)
|
||||
|| SIGNAL_CALL_HANGUP.equals(signalType));
|
||||
if (targets.isEmpty() && !isCallInviteAllSessions) {
|
||||
if (targets.isEmpty()) {
|
||||
String code = TARGET_MODE_SINGLE.equals(targetMode) ? "SESSION_NOT_FOUND" : "NO_TARGET_SESSIONS";
|
||||
String msg = TARGET_MODE_SINGLE.equals(targetMode) ? "Целевая сессия не найдена" : "Нет активных сессий для доставки сигнала";
|
||||
return NetExceptionResponseFactory.error(req, 404, code, msg);
|
||||
@@ -154,18 +152,7 @@ public class Net_SendSignal_Handler implements JsonMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
int webPushDelivered = 0;
|
||||
if (isCallInviteAllSessions) {
|
||||
webPushDelivered = sendIncomingCallPushToOfflineSessions(
|
||||
toLogin,
|
||||
fromLogin,
|
||||
fromSessionId,
|
||||
signalRequestId,
|
||||
deliveredSessionIds
|
||||
);
|
||||
}
|
||||
|
||||
if (deliveredSessionIds.isEmpty() && webPushDelivered <= 0) {
|
||||
if (deliveredSessionIds.isEmpty()) {
|
||||
return NetExceptionResponseFactory.error(req, 404, "DELIVERY_FAILED", "Не удалось доставить сигнал ни в одну целевую сессию");
|
||||
}
|
||||
|
||||
@@ -205,11 +192,11 @@ public class Net_SendSignal_Handler implements JsonMessageHandler {
|
||||
resp.setOp(req.getOp());
|
||||
resp.setRequestId(req.getRequestId());
|
||||
resp.setStatus(WireCodes.Status.OK);
|
||||
resp.setDeliveredCount(deliveredSessionIds.size() + webPushDelivered);
|
||||
resp.setDeliveredCount(deliveredSessionIds.size());
|
||||
resp.setDeliveredSessionIds(deliveredSessionIds);
|
||||
resp.setDeliveredWsSessions(deliveredSessionIds.size());
|
||||
resp.setDeliveredFcmSessions(webPushDelivered);
|
||||
resp.setDeliveredWebPushSessions(webPushDelivered);
|
||||
resp.setDeliveredFcmSessions(0);
|
||||
resp.setDeliveredWebPushSessions(0);
|
||||
return resp;
|
||||
}
|
||||
|
||||
@@ -292,49 +279,6 @@ public class Net_SendSignal_Handler implements JsonMessageHandler {
|
||||
return targets;
|
||||
}
|
||||
|
||||
private int sendIncomingCallPushToOfflineSessions(
|
||||
String toLogin,
|
||||
String fromLogin,
|
||||
String fromSessionId,
|
||||
String callId,
|
||||
List<String> deliveredOnlineSessionIds
|
||||
) throws Exception {
|
||||
List<ActiveSessionEntry> persistedSessions = ActiveSessionsDAO.getInstance().getByLogin(toLogin);
|
||||
long sentAtMs = System.currentTimeMillis();
|
||||
long expiresAtMs = sentAtMs + PUSH_CALL_TTL_MS;
|
||||
int delivered = 0;
|
||||
for (ActiveSessionEntry session : persistedSessions) {
|
||||
String sessionId = safe(session.getSessionId());
|
||||
if (!sessionId.isBlank() && deliveredOnlineSessionIds.contains(sessionId)) {
|
||||
continue;
|
||||
}
|
||||
if (isBlank(session.getPushEndpoint()) || isBlank(session.getPushP256dhKey()) || isBlank(session.getPushAuthKey())) {
|
||||
continue;
|
||||
}
|
||||
String payload = "{\"kind\":\"incoming_call\""
|
||||
+ ",\"title\":\"SHiNE: входящий звонок\""
|
||||
+ ",\"text\":\"Вам звонит " + jsonEscape(fromLogin) + "\""
|
||||
+ ",\"fromLogin\":\"" + jsonEscape(fromLogin) + "\""
|
||||
+ ",\"fromSessionId\":\"" + jsonEscape(fromSessionId) + "\""
|
||||
+ ",\"targetSessionId\":\"" + jsonEscape(sessionId) + "\""
|
||||
+ ",\"toLogin\":\"" + jsonEscape(toLogin) + "\""
|
||||
+ ",\"callId\":\"" + jsonEscape(callId) + "\""
|
||||
+ ",\"sentAtMs\":" + sentAtMs
|
||||
+ ",\"expiresAtMs\":" + expiresAtMs
|
||||
+ "}";
|
||||
boolean pushed = WebPushSender.sendBase64Payload(
|
||||
session.getPushEndpoint(),
|
||||
session.getPushP256dhKey(),
|
||||
session.getPushAuthKey(),
|
||||
payload
|
||||
);
|
||||
if (pushed) {
|
||||
delivered++;
|
||||
}
|
||||
}
|
||||
return delivered;
|
||||
}
|
||||
|
||||
private void notifyStopOnOtherSessions(
|
||||
String targetLogin,
|
||||
String excludeSessionId,
|
||||
|
||||
Reference in New Issue
Block a user