@Throws(SerializationException::class)
private fun parseStatusMessageForAuthenticationResult(message: JsonElement): Boolean {
if (message.isStatusMessage()) {
val status = serializer.decodeFromJsonElement(StatusMessage.serializer(), message)
if (status.message == "authenticated") {
activeConnection?.isAuthenticated = true
listener.onAuthenticated(this)
return true
}
}
return false
}
/**
* If the first byte in the message is an open square bracket, this frame is housing an array
*/
private fun JsonElement.isStatusMessage() =
this is JsonObject && JsonPrimitive(EVENT_TYPE_MESSAGE_KEY).contentOrNull == "status"
JsonPrimitive(EVENT_TYPE_MESSAGE_KEY).contentOrNull == "status"
will always false because instead of comparing incoming ev
, this creates a new JsonPrimitive EVENT_TYPE_MESSAGE_KEY as the content
.contentOrNull - This immediately extracts the content from that newly created JsonPrimitive