SHA256
Звонки: выбор одной callee-сессии и авто-закрытие входящего на других устройствах
This commit is contained in:
+34
@@ -20,6 +20,8 @@ import java.util.Set;
|
||||
|
||||
public class Net_CallSignalToSession_Handler implements JsonMessageHandler {
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final int TYPE_ACCEPT = 120;
|
||||
private static final int TYPE_HANGUP = 150;
|
||||
|
||||
@Override
|
||||
public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) throws Exception {
|
||||
@@ -69,6 +71,10 @@ public class Net_CallSignalToSession_Handler implements JsonMessageHandler {
|
||||
|
||||
boolean delivered = WsEventSender.sendEvent(targetCtx, "IncomingCallSignal", eventId, payload);
|
||||
|
||||
if (type == TYPE_ACCEPT) {
|
||||
notifyAcceptedOnOtherSessions(ctx, callId);
|
||||
}
|
||||
|
||||
Net_CallSignalToSession_Response resp = new Net_CallSignalToSession_Response();
|
||||
resp.setOp(req.getOp());
|
||||
resp.setRequestId(req.getRequestId());
|
||||
@@ -76,4 +82,32 @@ public class Net_CallSignalToSession_Handler implements JsonMessageHandler {
|
||||
resp.setDelivered(delivered);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private void notifyAcceptedOnOtherSessions(ConnectionContext accepterCtx, String callId) {
|
||||
if (accepterCtx == null) return;
|
||||
String login = accepterCtx.getLogin();
|
||||
String acceptedSessionId = accepterCtx.getSessionId();
|
||||
if (login == null || login.isBlank() || acceptedSessionId == null || acceptedSessionId.isBlank() || callId == null || callId.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<ConnectionContext> sameUserSessions = ActiveConnectionsRegistry.getInstance().getByLogin(login);
|
||||
for (ConnectionContext siblingCtx : sameUserSessions) {
|
||||
if (siblingCtx == null || siblingCtx.getWsSession() == null || !siblingCtx.getWsSession().isOpen()) continue;
|
||||
if (acceptedSessionId.equals(siblingCtx.getSessionId())) continue;
|
||||
|
||||
String siblingEventId = NetIdGenerator.eventId("evt");
|
||||
ObjectNode siblingPayload = MAPPER.createObjectNode();
|
||||
siblingPayload.put("eventId", siblingEventId);
|
||||
siblingPayload.put("fromLogin", login);
|
||||
siblingPayload.put("fromSessionId", acceptedSessionId);
|
||||
siblingPayload.put("toLogin", login);
|
||||
siblingPayload.put("callId", callId);
|
||||
siblingPayload.put("type", TYPE_HANGUP);
|
||||
siblingPayload.put("data", "accepted_on_other_device");
|
||||
siblingPayload.put("timeMs", System.currentTimeMillis());
|
||||
|
||||
WsEventSender.sendEvent(siblingCtx, "IncomingCallSignal", siblingEventId, siblingPayload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user