SHA256
CallDeliveryReport: универсальный формат type/value и расширенные отчёты по звонкам
This commit is contained in:
+6
-2
@@ -84,7 +84,9 @@ import server.logic.ws_protocol.JSON.handlers.system.Net_GetServerInfo_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_GetCallIceConfig_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_ClientErrorLog_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_ClientDebugLog_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_CallDeliveryReport_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_Ping_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_CallDeliveryReport_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_ClientErrorLog_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_ClientDebugLog_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_GetCallIceConfig_Request;
|
||||
@@ -152,7 +154,8 @@ public final class JsonHandlerRegistry {
|
||||
Map.entry("GetServerInfo", new Net_GetServerInfo_Handler()),
|
||||
Map.entry("GetCallIceConfig", new Net_GetCallIceConfig_Handler()),
|
||||
Map.entry("ClientErrorLog", new Net_ClientErrorLog_Handler()),
|
||||
Map.entry("ClientDebugLog", new Net_ClientDebugLog_Handler())
|
||||
Map.entry("ClientDebugLog", new Net_ClientDebugLog_Handler()),
|
||||
Map.entry("CallDeliveryReport", new Net_CallDeliveryReport_Handler())
|
||||
|
||||
// --- subscriptions ---
|
||||
// Map.entry("ListSubscribedChannels", new Net_GetSubscribedChannels_Handler())
|
||||
@@ -207,7 +210,8 @@ public final class JsonHandlerRegistry {
|
||||
Map.entry("GetServerInfo", Net_GetServerInfo_Request.class),
|
||||
Map.entry("GetCallIceConfig", Net_GetCallIceConfig_Request.class),
|
||||
Map.entry("ClientErrorLog", Net_ClientErrorLog_Request.class),
|
||||
Map.entry("ClientDebugLog", Net_ClientDebugLog_Request.class)
|
||||
Map.entry("ClientDebugLog", Net_ClientDebugLog_Request.class),
|
||||
Map.entry("CallDeliveryReport", Net_CallDeliveryReport_Request.class)
|
||||
);
|
||||
|
||||
private JsonHandlerRegistry() { }
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_CallDeliveryReport_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_CallDeliveryReport_Response;
|
||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||
import server.logic.ws_protocol.WireCodes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.time.Instant;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class Net_CallDeliveryReport_Handler implements JsonMessageHandler {
|
||||
private static final ReentrantLock FILE_LOCK = new ReentrantLock(true);
|
||||
private static final Path LOG_FILE = Path.of("logs", "call-delivery-events.log");
|
||||
|
||||
@Override
|
||||
public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) {
|
||||
Net_CallDeliveryReport_Request req = (Net_CallDeliveryReport_Request) baseRequest;
|
||||
if (safe(req.getType()).isEmpty()) {
|
||||
return NetExceptionResponseFactory.error(
|
||||
req, WireCodes.Status.BAD_REQUEST, "BAD_FIELDS", "Поле type обязательно"
|
||||
);
|
||||
}
|
||||
|
||||
long serverTs = System.currentTimeMillis();
|
||||
String line = String.format(
|
||||
Locale.ROOT,
|
||||
"%s | type=%s | login=%s | remote=%s | value=%s%n",
|
||||
Instant.ofEpochMilli(serverTs),
|
||||
clip(req.getType(), 80),
|
||||
clip(ctx != null ? ctx.getLogin() : "", 80),
|
||||
clip(remoteAddress(ctx), 200),
|
||||
clip(req.getValue(), 8000)
|
||||
);
|
||||
|
||||
appendLine(line);
|
||||
|
||||
Net_CallDeliveryReport_Response resp = new Net_CallDeliveryReport_Response();
|
||||
resp.setOp(req.getOp());
|
||||
resp.setRequestId(req.getRequestId());
|
||||
resp.setStatus(WireCodes.Status.OK);
|
||||
resp.setAccepted(true);
|
||||
resp.setServerTs(serverTs);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private static void appendLine(String line) {
|
||||
FILE_LOCK.lock();
|
||||
try {
|
||||
Path parent = LOG_FILE.getParent();
|
||||
if (parent != null) {
|
||||
Files.createDirectories(parent);
|
||||
}
|
||||
Files.writeString(
|
||||
LOG_FILE,
|
||||
line,
|
||||
StandardCharsets.UTF_8,
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.APPEND
|
||||
);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Не удалось записать call-delivery-report", e);
|
||||
} finally {
|
||||
FILE_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static String remoteAddress(ConnectionContext ctx) {
|
||||
if (ctx == null) return "";
|
||||
Session ws = ctx.getWsSession();
|
||||
if (ws == null) return "";
|
||||
SocketAddress remote = ws.getRemoteAddress();
|
||||
return remote != null ? remote.toString() : "";
|
||||
}
|
||||
|
||||
private static String safe(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private static String clip(String value, int maxLen) {
|
||||
String cleaned = safe(value).replace('\n', ' ').replace('\r', ' ');
|
||||
if (cleaned.length() <= maxLen) return cleaned;
|
||||
return cleaned.substring(0, Math.max(0, maxLen - 3)) + "...";
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system.entyties;
|
||||
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
|
||||
public class Net_CallDeliveryReport_Request extends Net_Request {
|
||||
private String type;
|
||||
private String value;
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
public String getValue() { return value; }
|
||||
public void setValue(String value) { this.value = value; }
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system.entyties;
|
||||
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
|
||||
public class Net_CallDeliveryReport_Response extends Net_Response {
|
||||
private long serverTs;
|
||||
private boolean accepted;
|
||||
|
||||
public long getServerTs() { return serverTs; }
|
||||
public void setServerTs(long serverTs) { this.serverTs = serverTs; }
|
||||
public boolean isAccepted() { return accepted; }
|
||||
public void setAccepted(boolean accepted) { this.accepted = accepted; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user