Skip to content

Commit

Permalink
fix: Drops duplicate json dependency. (#569)
Browse files Browse the repository at this point in the history
* fix: Drops duplicate json dependency.

Drop org.json and use the one common in other dependencies.

* squash: Do not create multiple times the parser on hotter paths.
  • Loading branch information
damencho authored Oct 31, 2024
1 parent a72d0a4 commit 6b25725
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 30 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,6 @@
<version>5.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jitsi/jigasi/AudioModeration.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ private IQ handleMuteIq(MuteIq muteIq)
private class AVModerationListener
implements StanzaListener
{
private JSONParser parser = new JSONParser();

@Override
public void processStanza(Stanza packet)
{
Expand All @@ -627,7 +629,7 @@ public void processStanza(Stanza packet)

try
{
Object o = new JSONParser().parse(jsonMsg.getJson());
Object o = parser.parse(jsonMsg.getJson());

if (o instanceof JSONObject)
{
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jitsi/jigasi/TranscriptionGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.jitsi.jigasi.transcription.action.*;
import org.jitsi.jigasi.util.Util;
import org.jitsi.utils.logging.*;
import org.json.*;
import org.json.simple.*;
import org.json.simple.parser.*;
import org.osgi.framework.*;

import java.io.*;
Expand Down Expand Up @@ -218,8 +219,8 @@ private String getTranscriberFromRemote(String remoteTsConfigUrl, CallContext ct
responseBody.append(inputLine);
}
inputStream.close();
JSONObject obj = new JSONObject(responseBody.toString());
String transcriberType = obj.getString("transcriberType");
JSONObject obj = (JSONObject)new JSONParser().parse(responseBody.toString());
String transcriberType = (String)obj.get("transcriberType");
if (logger.isDebugEnabled())
{
logger.debug(ctx + " Retrieved transcriberType: " + transcriberType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.jitsi.jigasi.transcription;

import net.java.sip.communicator.service.protocol.*;
import org.json.*;
import org.json.simple.*;

import java.time.*;
import java.util.*;
Expand Down Expand Up @@ -369,7 +369,7 @@ private static void addAlternatives(JSONObject jsonObject, SpeechEvent e)
alternativeJSON.put(JSON_KEY_ALTERNATIVE_CONFIDENCE,
alternative.getConfidence());

alternativeJSONArray.put(alternativeJSON);
alternativeJSONArray.add(alternativeJSON);
}

jsonObject.put(JSON_KEY_EVENT_TRANSCRIPT, alternativeJSONArray);
Expand Down Expand Up @@ -476,7 +476,7 @@ private void addTranscriptDescription(JSONObject jsonObject,

addParticipantDescription(pJSON, participant);

participantArray.put(pJSON);
participantArray.add(pJSON);
}

jsonObject.put(JSON_KEY_FINAL_TRANSCRIPT_INITIAL_PARTICIPANTS,
Expand All @@ -486,7 +486,7 @@ private void addTranscriptDescription(JSONObject jsonObject,
{
JSONArray eventArray = new JSONArray();

events.forEach(eventArray::put);
eventArray.addAll(events);

jsonObject.put(JSON_KEY_FINAL_TRANSCRIPT_EVENTS, eventArray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.jitsi.jigasi.transcription;

import net.java.sip.communicator.service.protocol.*;
import org.json.*;
import org.json.simple.*;

import java.util.*;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jitsi/jigasi/transcription/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.jitsi.jigasi.transcription;

import org.jitsi.utils.logging.*;
import org.json.*;
import org.json.simple.*;

import java.io.*;
import java.net.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.eclipse.jetty.websocket.api.*;
import org.eclipse.jetty.websocket.api.annotations.*;
import org.eclipse.jetty.websocket.client.*;
import org.json.*;
import org.json.simple.*;
import org.json.simple.parser.*;
import org.jitsi.jigasi.*;
import org.jitsi.utils.logging.*;

Expand Down Expand Up @@ -75,6 +76,8 @@ public class VoskTranscriptionService
*/
private String websocketUrl;

private final JSONParser jsonParser = new JSONParser();

/**
* Assigns the websocketUrl to use to websocketUrl by reading websocketUrlConfig;
*/
Expand Down Expand Up @@ -260,19 +263,35 @@ public void onConnect(Session session)
@OnWebSocketMessage
public void onMessage(String msg)
{
try
{
this.onMessageInternal(msg);
}
catch (ParseException e)
{
logger.error("Error parsing message: " + msg, e);
}
}

private void onMessageInternal(String msg)
throws ParseException
{
if (logger.isDebugEnabled())
{
logger.debug(debugName + "Received response: " + msg);
}

boolean partial = true;
String result = "";
if (logger.isDebugEnabled())
logger.debug(debugName + "Recieved response: " + msg);
JSONObject obj = new JSONObject(msg);
if (obj.has("partial"))
JSONObject obj = (JSONObject)jsonParser.parse(msg);
if (obj.containsKey("partial"))
{
result = obj.getString("partial");
result = (String)obj.get("partial");
}
else
{
partial = false;
result = obj.getString("text");
result = (String)obj.get("text");
}

if (!result.isEmpty() && (!partial || !result.equals(lastResult)))
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/org/jitsi/jigasi/transcription/WhisperWebsocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.jitsi.jigasi.stats.*;
import org.jitsi.jigasi.util.Util;
import org.jitsi.utils.logging.*;
import org.json.*;
import org.json.simple.*;
import org.json.simple.parser.*;

import java.io.*;
import java.net.*;
Expand Down Expand Up @@ -152,6 +153,8 @@ public class WhisperWebsocket
*/
private static final ExecutorService threadPool = Util.createNewThreadPool("jigasi-whisper-ws");

private final JSONParser jsonParser = new JSONParser();

/**
* Creates a connection url by concatenating the websocket
* url with the Connection Id;
Expand Down Expand Up @@ -300,20 +303,34 @@ private void stopWebSocketClient()

@OnWebSocketMessage
public void onMessage(String msg)
{
try
{
this.onMessageInternal(msg);
}
catch (ParseException e)
{
logger.error("Error parsing message: " + msg, e);
}
}

private void onMessageInternal(String msg)
throws ParseException
{
boolean partial = true;
String result;
JSONObject obj = new JSONObject(msg);
String msgType = obj.getString("type");
String participantId = obj.getString("participant_id");

JSONObject obj = (JSONObject)jsonParser.parse(msg);
String msgType = (String)obj.get("type");
String participantId = (String)obj.get("participant_id");
Participant participant = participants.get(participantId);
if (msgType.equals("final"))
{
partial = false;
}

result = obj.getString("text");
float stability = obj.getFloat("variance");
result = (String)obj.get("text");
double stability = (double)obj.get("variance");
if (logger.isDebugEnabled())
{
logger.debug("Received result: " + result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jitsi.jigasi.transcription.*;
import org.jitsi.service.configuration.*;
import org.jitsi.utils.logging.Logger;
import org.json.*;
import org.json.simple.*;
import org.osgi.framework.*;

import java.util.*;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jitsi/jigasi/visitor/WebsocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class WebsocketClient
*/
private ScheduledFuture ponger;

private final JSONParser jsonParser = new JSONParser();

/**
* A timer which will be used to schedule connection to conference after going live.
*/
Expand Down Expand Up @@ -371,7 +373,7 @@ else if (command.equals("MESSAGE"))
{
try
{
Object o = new JSONParser().parse(body.replace(END, ""));
Object o = jsonParser.parse(body.replace(END, ""));

if (o instanceof JSONObject)
{
Expand Down

0 comments on commit 6b25725

Please sign in to comment.