Skip to content

Commit af8b7e8

Browse files
authored
Add PingEvent, PongEvent, TranscriptionResultEvent to MediaJson. (#225) (#228)
* feat: Add PingEvent and PongEvent. * Add TranscriptionResultEvent.
1 parent 4c67b0d commit af8b7e8

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

jicoco-mediajson/src/main/kotlin/org/jitsi/mediajson/MediaJson.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ private val objectMapper = jacksonObjectMapper().apply {
4141
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "event")
4242
@JsonSubTypes(
4343
JsonSubTypes.Type(value = MediaEvent::class, name = "media"),
44+
JsonSubTypes.Type(value = PingEvent::class, name = "ping"),
45+
JsonSubTypes.Type(value = PongEvent::class, name = "pong"),
4446
JsonSubTypes.Type(value = StartEvent::class, name = "start"),
4547
JsonSubTypes.Type(value = TranscriptionResultEvent::class, name = "transcription-result"),
4648
)
@@ -66,6 +68,14 @@ data class StartEvent(
6668
val start: Start
6769
) : Event("start")
6870

71+
data class PingEvent(
72+
val id: Int
73+
) : Event("ping")
74+
75+
data class PongEvent(
76+
val id: Int
77+
) : Event("pong")
78+
6979
@com.fasterxml.jackson.annotation.JsonIgnoreProperties(value = ["event"], allowGetters = false)
7080
class TranscriptionResultEvent : Event("transcription-result") {
7181
private val additionalProperties = mutableMapOf<String, Any?>()

jicoco-mediajson/src/test/kotlin/org/jitsi/mediajson/MediaJsonTest.kt

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ class MediaJsonTest : ShouldSpec() {
9292
(parsed === event) shouldBe false
9393
}
9494
}
95+
context("PingEvent") {
96+
val id = 42
97+
val event = PingEvent(id)
98+
99+
context("Serializing") {
100+
val parsed = parser.parse(event.toJson())
101+
parsed.shouldBeInstanceOf<JSONObject>()
102+
parsed["event"] shouldBe "ping"
103+
parsed["id"] shouldBe id
104+
}
105+
context("Parsing") {
106+
val parsed = Event.parse(event.toJson())
107+
(parsed == event) shouldBe true
108+
(parsed === event) shouldBe false
109+
}
110+
}
111+
context("PongEvent") {
112+
val id = 123
113+
val event = PongEvent(id)
114+
115+
context("Serializing") {
116+
val parsed = parser.parse(event.toJson())
117+
parsed.shouldBeInstanceOf<JSONObject>()
118+
parsed["event"] shouldBe "pong"
119+
parsed["id"] shouldBe id
120+
}
121+
context("Parsing") {
122+
val parsed = Event.parse(event.toJson())
123+
(parsed == event) shouldBe true
124+
(parsed === event) shouldBe false
125+
}
126+
}
95127
context("TranscriptionResultEvent") {
96128
val event = TranscriptionResultEvent()
97129

@@ -193,15 +225,15 @@ class MediaJsonTest : ShouldSpec() {
193225
context("Media with seq/chunk/timestamp as numbers") {
194226
val parsed = Event.parse(
195227
"""
196-
{
228+
{
197229
"event": "media",
198-
"sequenceNumber": 2,
199-
"media": {
200-
"tag": "incoming",
201-
"chunk": 1,
230+
"sequenceNumber": 2,
231+
"media": {
232+
"tag": "incoming",
233+
"chunk": 1,
202234
"timestamp": 5,
203235
"payload": "no+JhoaJjpzSHxAKBgYJ...=="
204-
}
236+
}
205237
}
206238
""".trimIndent()
207239
)
@@ -214,6 +246,34 @@ class MediaJsonTest : ShouldSpec() {
214246
parsed.media.timestamp shouldBe 5
215247
parsed.media.payload shouldBe "no+JhoaJjpzSHxAKBgYJ...=="
216248
}
249+
context("Ping") {
250+
val parsed = Event.parse(
251+
"""
252+
{
253+
"event": "ping",
254+
"id": 42
255+
}
256+
""".trimIndent()
257+
)
258+
259+
parsed.shouldBeInstanceOf<PingEvent>()
260+
parsed.event shouldBe "ping"
261+
parsed.id shouldBe 42
262+
}
263+
context("Pong") {
264+
val parsed = Event.parse(
265+
"""
266+
{
267+
"event": "pong",
268+
"id": 123
269+
}
270+
""".trimIndent()
271+
)
272+
273+
parsed.shouldBeInstanceOf<PongEvent>()
274+
parsed.event shouldBe "pong"
275+
parsed.id shouldBe 123
276+
}
217277
context("TranscriptionResult ") {
218278
val originalJson = """
219279
{

0 commit comments

Comments
 (0)