Search in sources :

Example 91 with JsonParser

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

the class UserLeftVoiceMessage method fromJson.

public static UserLeftVoiceMessage 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.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 UserLeftVoiceMessage(id, userMap, voiceConf);
                    }
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 92 with JsonParser

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

the class UserListeningOnlyMessage method fromJson.

public static UserListeningOnlyMessage 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_LISTENING_ONLY.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.LISTEN_ONLY)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    Boolean listenOnly = payload.get(Constants.LISTEN_ONLY).getAsBoolean();
                    return new UserListeningOnlyMessage(id, userid, listenOnly);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 93 with JsonParser

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

the class UserLockedMessage method fromJson.

public static UserLockedMessage 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_LOCKED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.LOCKED)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    Boolean locked = payload.get(Constants.LOCKED).getAsBoolean();
                    return new UserLockedMessage(id, userid, locked);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 94 with JsonParser

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

the class UserShareWebcamRequestMessage method fromJson.

public static UserShareWebcamRequestMessage 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_SHARE_WEBCAM_REQUEST.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.STREAM)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    String stream = payload.get(Constants.STREAM).getAsString();
                    return new UserShareWebcamRequestMessage(id, userid, stream);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 95 with JsonParser

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

the class UserStatusChangedMessage method fromJson.

public static UserStatusChangedMessage 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_STATUS_CHANGED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.USER_ID) && payload.has(Constants.STATUS) && payload.has(Constants.VALUE)) {
                    String id = payload.get(Constants.MEETING_ID).getAsString();
                    String userid = payload.get(Constants.USER_ID).getAsString();
                    String status = payload.get(Constants.STATUS).getAsString();
                    String value = payload.get(Constants.VALUE).getAsString();
                    return new UserStatusChangedMessage(id, userid, status, value);
                }
            }
        }
    }
    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