Search in sources :

Example 21 with JsonParser

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

the class MeetingCreatedMessage method fromJson.

public static MeetingCreatedMessage 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 (MEETING_CREATED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.RECORDED)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    Boolean record = payload.get(Constants.RECORDED).getAsBoolean();
                    return new MeetingCreatedMessage(meetingId, record);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 22 with JsonParser

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

the class MeetingEndedMessage method fromJson.

public static MeetingEndedMessage 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 (MEETING_ENDED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    return new MeetingEndedMessage(meetingId);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 23 with JsonParser

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

the class MeetingEndingMessage method fromJson.

public static MeetingEndingMessage 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 (MEETING_ENDING.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID)) {
                    String meetingId = payload.get(Constants.MEETING_ID).getAsString();
                    return new MeetingEndingMessage(meetingId);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 24 with JsonParser

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

the class MeetingMutedMessage method fromJson.

public static MeetingMutedMessage 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 (MEETING_MUTED.equals(messageName)) {
                if (payload.has(Constants.MEETING_ID) && payload.has(Constants.MEETING_MUTED)) {
                    String meetingID = payload.get(Constants.MEETING_ID).getAsString();
                    Boolean muted = payload.get(Constants.MEETING_MUTED).getAsBoolean();
                    return new MeetingMutedMessage(meetingID, muted);
                }
            }
        }
    }
    return null;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 25 with JsonParser

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

the class MessageFromJsonConverter method convert.

public static IBigBlueButtonMessage convert(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();
            switch(messageName) {
                case CreateMeetingMessage.CREATE_MEETING_REQUEST_EVENT:
                    return processCreateMeeting(payload);
                case DestroyMeetingMessage.DESTROY_MEETING_REQUEST_EVENT:
                    return processDestroyMeeting(payload);
                case EndMeetingMessage.END_MEETING_REQUEST_EVENT:
                    return processEndMeetingMessage(payload);
                case KeepAliveMessage.KEEP_ALIVE_REQUEST:
                    return processKeepAlive(payload);
                case RegisterUserMessage.REGISTER_USER:
                    return RegisterUserMessage.fromJson(message);
                case ValidateAuthTokenMessage.VALIDATE_AUTH_TOKEN:
                    return processValidateAuthTokenMessage(header, payload);
                // return ValidateAuthTokenMessage.fromJson(message);
                case UserConnectedToGlobalAudio.USER_CONNECTED_TO_GLOBAL_AUDIO:
                    return UserConnectedToGlobalAudio.fromJson(message);
                case UserDisconnectedFromGlobalAudio.USER_DISCONNECTED_FROM_GLOBAL_AUDIO:
                    return UserDisconnectedFromGlobalAudio.fromJson(message);
                case GetAllMeetingsRequest.GET_ALL_MEETINGS_REQUEST_EVENT:
                    return new GetAllMeetingsRequest("the_string_is_not_used_anywhere");
            }
        }
    }
    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