Search in sources :

Example 86 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class ValidateAuthTokenReplyMessage method fromJson.

public static ValidateAuthTokenReplyMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (VALIDATE_AUTH_TOKEN_REPLY.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.AUTH_TOKEN) && payload.has(Constants.VALID) && payload.has(Constants.REPLY_TO)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    String authToken = payload.get(Constants.AUTH_TOKEN).getAsString();
                    String replyTo = payload.get(Constants.REPLY_TO).getAsString();
                    Boolean valid = payload.get(Constants.VALID).getAsBoolean();
                    return new ValidateAuthTokenReplyMessage(id, userid, authToken, valid, replyTo);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 87 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class ValidateAuthTokenTimeoutMessage method fromJson.

public static ValidateAuthTokenTimeoutMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (VALIDATE_AUTH_TOKEN_TIMEOUT.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.AUTH_TOKEN) && payload.has(Constants.VALID) && payload.has(Constants.REPLY_TO)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    String authToken = payload.get(Constants.AUTH_TOKEN).getAsString();
                    String replyTo = payload.get(Constants.REPLY_TO).getAsString();
                    Boolean valid = payload.get(Constants.VALID).getAsBoolean();
                    return new ValidateAuthTokenTimeoutMessage(id, userid, authToken, valid, replyTo);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 88 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class VoiceConfRecordingStartedMessage method fromJson.

public static VoiceConfRecordingStartedMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (VOICE_CONF_RECORDING_STARTED.equals(messageName)) {
                if (payload.has(VOICE_CONF_ID) && payload.has(RECORD_STREAM) && payload.has(RECORDING) && payload.has(TIMESTAMP)) {
                    String voiceConfId = payload.get(VOICE_CONF_ID).getAsString();
                    String recordStream = payload.get(RECORD_STREAM).getAsString();
                    Boolean recording = payload.get(RECORDING).getAsBoolean();
                    String timestamp = payload.get(TIMESTAMP).getAsString();
                    return new VoiceConfRecordingStartedMessage(voiceConfId, recordStream, recording, timestamp);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 89 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class UserVoiceTalkingMessage method fromJson.

public static UserVoiceTalkingMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (USER_VOICE_TALKING.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String voiceConf = payload.get(Constants.VOICE_CONF).getAsString();
                    JsonObject user = (JsonObject) payload.get(Constants.USER);
                    Util util = new Util();
                    Map<String, Object> userMap = util.extractUser(user);
                    if (userMap != null) {
                        return new UserVoiceTalkingMessage(id, userMap, voiceConf);
                    }
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 90 with JsonParser

use of com.google.gson.JsonParser in project bigbluebutton by bigbluebutton.

the class UserLeftVoiceConfMessage method fromJson.

public static UserLeftVoiceConfMessage fromJson(String message) {
    JsonParser parser = new JsonParser();
    JsonObject obj = (JsonObject) parser.parse(message);
    if (obj.has("header") && obj.has("payload")) {
        JsonObject header = (JsonObject) obj.get("header");
        JsonObject payload = (JsonObject) obj.get("payload");
        if (header.has("name")) {
            String messageName = header.get("name").getAsString();
            if (USER_LEFT_VOICE_CONF.equals(messageName)) {
                if (payload.has(VOICE_CONF_ID) && payload.has(VOICE_USER_ID)) {
                    String voiceConfId = payload.get(VOICE_CONF_ID).getAsString();
                    String voiceUserId = payload.get(VOICE_USER_ID).getAsString();
                    return new UserLeftVoiceConfMessage(voiceConfId, voiceUserId);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonParser (com.google.gson.JsonParser)356 JsonObject (com.google.gson.JsonObject)285 JsonElement (com.google.gson.JsonElement)105 JsonArray (com.google.gson.JsonArray)57 IOException (java.io.IOException)43 Gson (com.google.gson.Gson)40 InputStreamReader (java.io.InputStreamReader)32 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 Map (java.util.Map)18 Type (java.lang.reflect.Type)15 JsonReader (com.google.gson.stream.JsonReader)12 Test (org.junit.Test)12 URL (java.net.URL)11 AssetManager (android.content.res.AssetManager)10 InputStream (java.io.InputStream)10 GsonBuilder (com.google.gson.GsonBuilder)9 UserType (com.glitchcog.fontificator.bot.UserType)8 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)8 JsonParseException (com.google.gson.JsonParseException)8