-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
ReceivedJsonMsgDeserializer.scala
executable file
·38 lines (31 loc) · 1.19 KB
/
ReceivedJsonMsgDeserializer.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.bigbluebutton.core.pubsub.senders
import com.fasterxml.jackson.databind.JsonNode
import org.bigbluebutton.SystemConfiguration
import org.bigbluebutton.common2.msgs._
import org.bigbluebutton.core.bus.BbbMsgEvent
import scala.reflect.runtime.universe._
trait ReceivedJsonMsgDeserializer extends SystemConfiguration {
this: ReceivedJsonMsgHandlerActor =>
object JsonDeserializer extends Deserializer
def deserialize[B <: BbbCoreMsg](jsonNode: JsonNode)(implicit tag: TypeTag[B]): Option[B] = {
val (result, error) = JsonDeserializer.toBbbCommonMsg[B](jsonNode)
result match {
case Some(msg) =>
Some(msg.asInstanceOf[B])
case None =>
log.error("Failed to deserialize message " + error)
None
}
}
def send(channel: String, envelope: BbbCoreEnvelope, msg: BbbCoreMsg): Unit = {
val event = BbbMsgEvent(channel, BbbCommonEnvCoreMsg(envelope, msg))
publish(event)
}
def routeGenericMsg[B <: StandardMsg](envelope: BbbCoreEnvelope, jsonNode: JsonNode)(implicit tag: TypeTag[B]): Unit = {
for {
m <- deserialize[B](jsonNode)
} yield {
send(m.header.meetingId, envelope, m)
}
}
}