Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transcriber settings precedence #518

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 48 additions & 39 deletions src/main/java/org/jitsi/jigasi/TranscriptionGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,57 +100,66 @@ public void stop()
*/
private String getCustomTranscriptionServiceClass(String tenant)
{
String transcriberClass = null;
String remoteTranscriptionConfigUrl
= JigasiBundleActivator.getConfigurationService()
.getString(
REMOTE_TRANSCRIPTION_CONFIG_URL,
null);

if (remoteTranscriptionConfigUrl != null)
if (remoteTranscriptionConfigUrl != null && tenant != null)
{
String transcriberClass = null;
try
String tsConfigUrl = remoteTranscriptionConfigUrl + "/" + tenant;
transcriberClass = getTranscriberFromRemote(tsConfigUrl);
}

if (transcriberClass == null)
{
transcriberClass
= JigasiBundleActivator.getConfigurationService()
.getString(
CUSTOM_TRANSCRIPTION_SERVICE_PROP,
null);
}
return transcriberClass;
}

private String getTranscriberFromRemote(String remoteTsConfigUrl)
{
String transcriberClass = null;
if (logger.isDebugEnabled())
{
logger.debug("Calling " + remoteTsConfigUrl + " to retrieve transcriber.");
}
try
{
URL url = new URL(remoteTsConfigUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setConnectTimeout(3000);
int responseCode = conn.getResponseCode();
if (responseCode == 200)
{
URL url = new URL(remoteTranscriptionConfigUrl + "/" + tenant);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
int responseCode = conn.getResponseCode();
if (responseCode == 200)
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder responseBody = new StringBuilder();
while ((inputLine = inputStream.readLine()) != null)
{
BufferedReader inputStream = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder responseBody = new StringBuilder();
while ((inputLine = inputStream.readLine()) != null)
{
responseBody.append(inputLine);
}
inputStream.close();
if (logger.isDebugEnabled())
{
logger.debug("Received body " + responseBody);
}
JSONObject obj = new JSONObject(responseBody.toString());
transcriberClass = obj.getString("transcriber");
if (logger.isDebugEnabled())
{
logger.debug("Using " + transcriberClass + " as the transcriber class.");
}
responseBody.append(inputLine);
}
conn.disconnect();
return transcriberClass;
}
catch (Exception ex)
{
logger.error("Could not retrieve transcriber from remote URL." + ex);
inputStream.close();
JSONObject obj = new JSONObject(responseBody.toString());
transcriberClass = obj.getString("transcriber");
}
conn.disconnect();
}

return JigasiBundleActivator.getConfigurationService()
.getString(
CUSTOM_TRANSCRIPTION_SERVICE_PROP,
null);
catch (Exception ex)
{
logger.error("Could not retrieve transcriber from remote URL." + ex);
}
return transcriberClass;
}

@Override
Expand Down
Loading