Skip to content

Commit 57402c5

Browse files
authored
ref: Use mediajson TranscriptionResultEvent (#2379)
1 parent d73cf53 commit 57402c5

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

jvb/src/main/java/org/jitsi/videobridge/Conference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package org.jitsi.videobridge;
1717

18-
import com.fasterxml.jackson.databind.JsonNode;
1918
import kotlin.*;
2019
import org.jetbrains.annotations.*;
20+
import org.jitsi.mediajson.*;
2121
import org.jitsi.nlj.*;
2222
import org.jitsi.rtp.Packet;
2323
import org.jitsi.rtp.rtcp.rtcpfb.RtcpFbPacket;
@@ -1433,7 +1433,7 @@ public boolean isInactive()
14331433
*
14341434
* @param transcriptionMessage the transcription message as JsonNode
14351435
*/
1436-
private void handleTranscriptionMessage(JsonNode transcriptionMessage)
1436+
private void handleTranscriptionMessage(TranscriptionResultEvent transcriptionMessage)
14371437
{
14381438
try
14391439
{

jvb/src/main/kotlin/org/jitsi/videobridge/export/Exporter.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
package org.jitsi.videobridge.export
1717

18-
import com.fasterxml.jackson.databind.JsonNode
19-
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
2018
import org.eclipse.jetty.websocket.api.Session
2119
import org.eclipse.jetty.websocket.api.WebSocketAdapter
2220
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest
2321
import org.eclipse.jetty.websocket.client.WebSocketClient
2422
import org.jitsi.config.JitsiConfig
23+
import org.jitsi.mediajson.Event
24+
import org.jitsi.mediajson.TranscriptionResultEvent
2525
import org.jitsi.metaconfig.config
2626
import org.jitsi.metaconfig.optionalconfig
2727
import org.jitsi.nlj.PacketInfo
@@ -46,7 +46,7 @@ internal class Exporter(
4646
private val url: URI,
4747
private val httpHeaders: Map<String, String>,
4848
val logger: Logger,
49-
private val handleTranscriptionResult: ((JsonNode) -> Unit)
49+
private val handleTranscriptionResult: ((TranscriptionResultEvent) -> Unit),
5050
) {
5151
private val isShuttingDown = AtomicBoolean(false)
5252
private val reconnectAttempts = AtomicInteger(0)
@@ -59,6 +59,7 @@ internal class Exporter(
5959
private val instanceStarts = AtomicLong(0)
6060
private val instanceTranscriptsReceived = AtomicLong(0)
6161
private val instanceOtherMessagesReceived = AtomicLong(0)
62+
private val instanceParseFailures = AtomicLong(0)
6263

6364
val queue: PacketInfoQueue by lazy {
6465
PacketInfoQueue(
@@ -119,19 +120,24 @@ internal class Exporter(
119120

120121
private fun handleIncomingMessage(message: String) {
121122
try {
122-
val jsonNode = objectMapper.readTree(message)
123-
logger.debug { "Received message from websocket: $jsonNode" }
124-
125-
if (jsonNode.get("type")?.asText() == "transcription-result") {
126-
transcriptsReceivedCount.inc()
127-
instanceTranscriptsReceived.incrementAndGet()
128-
handleTranscriptionResult(jsonNode)
129-
} else {
130-
otherMessagesReceivedCount.inc()
131-
instanceOtherMessagesReceived.incrementAndGet()
123+
val event = Event.parse(message)
124+
logger.debug { "Received message from websocket: ${event.toJson()}" }
125+
126+
when (event) {
127+
is TranscriptionResultEvent -> {
128+
transcriptsReceivedCount.inc()
129+
instanceTranscriptsReceived.incrementAndGet()
130+
handleTranscriptionResult(event)
131+
}
132+
else -> {
133+
otherMessagesReceivedCount.inc()
134+
instanceOtherMessagesReceived.incrementAndGet()
135+
}
132136
}
133137
} catch (e: Exception) {
134138
logger.warn("Failed to parse incoming websocket message: $message", e)
139+
parseFailuresCount.inc()
140+
instanceParseFailures.incrementAndGet()
135141
}
136142
}
137143

@@ -224,6 +230,7 @@ internal class Exporter(
224230
put("starts", instanceStarts.get())
225231
put("transcripts_received", instanceTranscriptsReceived.get())
226232
put("other_messages_received", instanceOtherMessagesReceived.get())
233+
put("parse_failures", instanceParseFailures.get())
227234
put("queue_size", queue.size())
228235
}
229236

@@ -263,7 +270,10 @@ internal class Exporter(
263270
"Number of non-transcription messages received by Exporter"
264271
)
265272

266-
private val objectMapper = jacksonObjectMapper()
273+
private val parseFailuresCount = VideobridgeMetricsContainer.instance.registerCounter(
274+
"exporter_parse_failures",
275+
"Number of messages that failed to parse"
276+
)
267277

268278
private val maxReconnectAttempts: Int? by optionalconfig {
269279
"videobridge.exporter.max-reconnect-attempts".from(JitsiConfig.newConfig)

jvb/src/main/kotlin/org/jitsi/videobridge/export/ExporterWrapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.jitsi.videobridge.export
1717

18-
import com.fasterxml.jackson.databind.JsonNode
18+
import org.jitsi.mediajson.TranscriptionResultEvent
1919
import org.jitsi.nlj.PacketInfo
2020
import org.jitsi.nlj.format.OpusPayloadType
2121
import org.jitsi.nlj.rtp.AudioRtpPacket
@@ -29,7 +29,7 @@ import org.json.simple.JSONObject
2929

3030
class ExporterWrapper(
3131
parentLogger: Logger,
32-
private val handleTranscriptionResult: ((JsonNode) -> Unit)
32+
private val handleTranscriptionResult: ((TranscriptionResultEvent) -> Unit)
3333
) : PotentialPacketHandler {
3434
val logger = createChildLogger(parentLogger)
3535
var started = false

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<junit.version>5.13.4</junit.version>
3030
<junit.platform.version>1.13.4</junit.platform.version>
3131
<jitsi.utils.version>1.0-146-g45b9f50</jitsi.utils.version>
32-
<jicoco.version>1.1-159-gf9c2712</jicoco.version>
32+
<jicoco.version>1.1-163-gc1ea8ca</jicoco.version>
3333
<mockk.version>1.14.5</mockk.version>
3434
<ktlint-maven-plugin.version>3.2.0</ktlint-maven-plugin.version>
3535
<build-helper-maven-plugin.version>3.6.1</build-helper-maven-plugin.version>

0 commit comments

Comments
 (0)