Java Code Examples for com.github.openjson.JSONObject#getString()

The following examples show how to use com.github.openjson.JSONObject#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KurentoHandler.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public void onMessage(IWsClient inClient, JSONObject msg) {
	if (!isConnected()) {
		sendError(inClient, "Multimedia server is inaccessible");
		return;
	}
	final String cmdId = msg.getString("id");
	if (MODE_TEST.equals(msg.optString(TAG_MODE))) {
		testProcessor.onMessage(inClient, cmdId, msg);
	} else {
		final Client c = (Client)inClient;

		if (c == null || c.getRoomId() == null) {
			log.warn("Incoming message from invalid user");
			return;
		}
		streamProcessor.onMessage(c, cmdId, msg);
	}
}
 
Example 2
Source File: JsonUtil.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private static OArchitectOProperty convertOPropertyFromJson(JSONObject jsonObject) {
    String name = !jsonObject.isNull(NAME) ? jsonObject.getString(NAME) : null;
    OType type = !jsonObject.isNull(TYPE) ? OType.valueOf(jsonObject.getString(TYPE)) : null;
    OArchitectOProperty property = null;
    if (!Strings.isNullOrEmpty(name) && type != null) {
        property = new OArchitectOProperty(name, type);
        if (!jsonObject.isNull(SUBCLASS_PROPERTY)) {
            String subClassProperty = jsonObject.getString(SUBCLASS_PROPERTY);
            property.setSubClassProperty(subClassProperty.equals("1") || subClassProperty.equals("true"));
        }
        if (!jsonObject.isNull(LINKED_CLASS_NAME)) {
            property.setLinkedClass(jsonObject.getString(LINKED_CLASS_NAME));
        }
        if (!jsonObject.isNull(ORDER)) {
            property.setOrder(jsonObject.getInt(ORDER));
        }
        if (!jsonObject.isNull(INVERSE_PROPERY_ENABLE)) {
            property.setInversePropertyEnable(jsonObject.getBoolean(INVERSE_PROPERY_ENABLE));
            if (!jsonObject.isNull(INVERSE_PROPERTY)) {
                property.setInverseProperty(convertInverseProperty(jsonObject.getJSONObject(INVERSE_PROPERTY)));
            }
        }
    }
    return property;
}
 
Example 3
Source File: RemoteSessionObject.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static RemoteSessionObject fromString(String s) {
	JSONObject o = new JSONObject(s);
	RemoteSessionObject ro = new RemoteSessionObject();
	ro.username = o.optString("username");
	ro.firstname = o.optString("firstname");
	ro.lastname = o.optString("lastname");
	ro.pictureUrl = o.optString("pictureUrl");
	ro.email = o.optString("email");
	ro.externalId = o.getString("externalId");
	ro.externalType = o.getString("externalType");
	return ro;
}
 
Example 4
Source File: TestStreamProcessor.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
void onMessage(IWsClient c, final String cmdId, JSONObject msg) {
	KTestStream user = getByUid(c.getUid());
	switch (cmdId) {
		case "wannaRecord":
			WebSocketHelper.sendClient(c, newTestKurentoMsg()
					.put("id", "canRecord")
					.put(PARAM_ICE, kHandler.getTurnServers(null, true))
					);
			break;
		case "record":
			if (user != null) {
				user.release(this);
			}
			user = new KTestStream(c, msg, createTestPipeline());
			streamByUid.put(c.getUid(), user);
			break;
		case "iceCandidate":
			JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
			if (user != null) {
				IceCandidate cand = new IceCandidate(candidate.getString(PARAM_CANDIDATE),
						candidate.getString("sdpMid"), candidate.getInt("sdpMLineIndex"));
				user.addCandidate(cand);
			}
			break;
		case "wannaPlay":
			WebSocketHelper.sendClient(c, newTestKurentoMsg()
					.put("id", "canPlay")
					.put(PARAM_ICE, kHandler.getTurnServers(null, true))
					);
			break;
		case "play":
			if (user != null) {
				user.play(c, msg, createTestPipeline());
			}
			break;
		default:
			//no-op
			break;
	}
}
 
Example 5
Source File: KTestStream.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public void play(final IWsClient inClient, JSONObject msg, MediaPipeline inPipeline) {
	this.pipeline = inPipeline;
	webRtcEndpoint = createWebRtcEndpoint(pipeline);
	player = createPlayerEndpoint(pipeline, recPath);
	player.connect(webRtcEndpoint);
	webRtcEndpoint.addMediaSessionStartedListener(evt -> {
			log.info("Media session started {}", evt);
			player.addErrorListener(event -> {
					log.info("ErrorEvent for player with uid '{}': {}", inClient.getUid(), event.getDescription());
					sendPlayEnd(inClient);
				});
			player.addEndOfStreamListener(event -> {
					log.info("EndOfStreamEvent for player with uid '{}'", inClient.getUid());
					sendPlayEnd(inClient);
				});
			player.play();
		});

	String sdpOffer = msg.getString("sdpOffer");
	String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

	addIceListener(inClient);

	WebSocketHelper.sendClient(inClient, newTestKurentoMsg()
			.put("id", "playResponse")
			.put("sdpAnswer", sdpAnswer));

	webRtcEndpoint.gatherCandidates();
}
 
Example 6
Source File: RoomMenuPanel.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public void update(IPartialPageRequestHandler handler) {
	if (!isVisible()) {
		return;
	}
	Room r = room.getRoom();
	boolean isInterview = Room.Type.INTERVIEW == r.getType();
	User u = room.getClient().getUser();
	boolean notExternalUser = u.getType() != User.Type.CONTACT;
	exitMenuItem.setVisible(notExternalUser);
	filesMenu.setVisible(!isInterview && room.getSidebar().isShowFiles());
	boolean moder = room.getClient().hasRight(Room.Right.MODERATOR);
	actionsSubMenu.update(moder, notExternalUser);
	pollsSubMenu.update(moder, notExternalUser, r);
	menuPanel.update(handler);
	StringBuilder roomClass = new StringBuilder("room name");
	String roomTitle = "";
	if (streamProcessor.isRecording(r.getId())) {
		JSONObject ru = kHandler.getRecordingUser(r.getId());
		if (!Strings.isEmpty(ru.optString("login"))) {
			roomTitle += getString("419") + " " + ru.getString("login");
			if (!Strings.isEmpty(ru.optString("firstName"))) {
				roomTitle += " " + ru.getString("firstName");
			}
			if (!Strings.isEmpty(ru.optString("lastName"))) {
				roomTitle += " " + ru.getString("lastName");
			}
			roomTitle += " " + df.format(new Date(ru.getLong("started")));
			roomClass.append(" screen");
		}
	}
	handler.add(roomName.add(AttributeModifier.replace(ATTR_CLASS, roomClass), AttributeModifier.replace(ATTR_TITLE, roomTitle)));
	handler.add(askBtn.setVisible(!moder && r.isAllowUserQuestions()));
	handler.add(shareBtn.setVisible(room.screenShareAllowed()));
	handler.appendJavaScript("$('#share-dlg-btn').off().click(Sharer.open);");
}
 
Example 7
Source File: JsonUtil.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private static OArchitectOClass convertOClassFromJson(JSONObject jsonObject) {
    OArchitectOClass oClass = new OArchitectOClass(jsonObject.getString(NAME));
    if (!jsonObject.isNull(SUPER_CLASSES)) {
        oClass.setSuperClasses(getSuperClasses(jsonObject.getJSONArray(SUPER_CLASSES)));
    }
    if (!jsonObject.isNull(EXISTS_IN_DB)) {
        String exists = jsonObject.getString(EXISTS_IN_DB);
        oClass.setExistsInDb(exists.equals("1") || exists.equals("true"));
    }
    if (!jsonObject.isNull(PROPERTIES)) {
        oClass.setProperties(getOPropertyListFromJson(jsonObject.getJSONArray(PROPERTIES)));
    }
    return oClass;
}
 
Example 8
Source File: StreamProcessor.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
void onMessage(Client c, final String cmdId, JSONObject msg) {
	final String uid = msg.optString("uid");
	KStream sender;
	StreamDesc sd;
	Optional<StreamDesc> osd;
	log.debug("Incoming message from user with ID '{}': {}", c.getUserId(), msg);
	switch (cmdId) {
		case "devicesAltered":
			sd = c.getStream(uid);
			if (sd != null) {
				if (!msg.getBoolean("audio") && c.hasActivity(Activity.AUDIO)) {
					c.remove(Activity.AUDIO);
				}
				if (!msg.getBoolean("video") && c.hasActivity(Activity.VIDEO)) {
					c.remove(Activity.VIDEO);
				}
				sd.setActivities();
				WebSocketHelper.sendRoom(new TextRoomMessage(c.getRoomId(), cm.update(c), RoomMessage.Type.RIGHT_UPDATED, c.getUid()));
			}
			break;
		case "toggleActivity":
			toggleActivity(c, Activity.valueOf(msg.getString("activity")));
			break;
		case "broadcastStarted":
			handleBroadcastStarted(c, uid, msg);
			break;
		case "onIceCandidate":
			sender = getByUid(uid);
			if (sender != null) {
				JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
				String candStr = candidate.getString(PARAM_CANDIDATE);
				if (!Strings.isEmpty(candStr)) {
					IceCandidate cand = new IceCandidate(
							candStr
							, candidate.getString("sdpMid")
							, candidate.getInt("sdpMLineIndex"));
					sender.addCandidate(cand, msg.getString("luid"));
				}
			}
			break;
		case "addListener":
			sender = getByUid(msg.getString("sender"));
			if (sender != null) {
				Client sendClient = cm.getBySid(sender.getSid());
				sd = sendClient.getStream(sender.getUid());
				if (sd == null) {
					break;
				}
				if (StreamType.SCREEN == sd.getType() && sd.hasActivity(Activity.RECORD) && !sd.hasActivity(Activity.SCREEN)) {
					break;
				}
				sender.addListener(this, c.getSid(), c.getUid(), msg.getString("sdpOffer"));
			}
			break;
		case "wannaShare":
			osd = c.getScreenStream();
			if (screenShareAllowed(c) || (osd.isPresent() && !osd.get().hasActivity(Activity.SCREEN))) {
				startSharing(c, osd, msg, Activity.SCREEN);
			}
			break;
		case "wannaRecord":
			osd = c.getScreenStream();
			if (recordingAllowed(c)) {
				Room r = c.getRoom();
				if (Room.Type.INTERVIEW == r.getType()) {
					log.warn("This shouldn't be called for interview room");
					break;
				}
				boolean sharing = isSharing(r.getId());
				startSharing(c, osd, msg, Activity.RECORD);
				if (sharing) {
					startRecording(c);
				}
			}
			break;
		case "pauseSharing":
			pauseSharing(c, uid);
			break;
		case "stopRecord":
			stopRecording(c);
			break;
		case "errorSharing":
			errorSharing(c);
			break;
		default:
			// no-op
			break;
	}
}
 
Example 9
Source File: KTestStream.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public KTestStream(IWsClient c, JSONObject msg, MediaPipeline pipeline) {
	super(null, c.getUid());
	this.pipeline = pipeline;
	webRtcEndpoint = createWebRtcEndpoint(pipeline);
	webRtcEndpoint.connect(webRtcEndpoint);

	MediaProfileSpecType profile = getProfile(msg);
	initRecPath();
	recorder = createRecorderEndpoint(pipeline, recPath, profile);

	recorder.addRecordingListener(evt -> {
			recTime = 0;
			recHandle = scheduler.scheduleAtFixedRate(
					() -> WebSocketHelper.sendClient(c, newTestKurentoMsg().put("id", "recording").put("time", recTime++))
					, 0, 1, TimeUnit.SECONDS);
			scheduler.schedule(() -> {
					recorder.stop();
					recHandle.cancel(true);
				}, 5, TimeUnit.SECONDS);
		});
	recorder.addStoppedListener(evt -> {
			WebSocketHelper.sendClient(c, newTestKurentoMsg().put("id", "recStopped"));
			releaseRecorder();
		});
	switch (profile) {
		case WEBM:
			webRtcEndpoint.connect(recorder, MediaType.AUDIO);
			webRtcEndpoint.connect(recorder, MediaType.VIDEO);
			break;
		case WEBM_AUDIO_ONLY:
			webRtcEndpoint.connect(recorder, MediaType.AUDIO);
			break;
		case WEBM_VIDEO_ONLY:
			webRtcEndpoint.connect(recorder, MediaType.VIDEO);
			break;
		default:
			//no-op
			break;
	}

	String sdpOffer = msg.getString("sdpOffer");
	String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

	addIceListener(c);

	WebSocketHelper.sendClient(c, newTestKurentoMsg()
			.put("id", "startResponse")
			.put("sdpAnswer", sdpAnswer));
	webRtcEndpoint.gatherCandidates();
	recorder.record(new Continuation<Void>() {
		@Override
		public void onSuccess(Void result) throws Exception {
			log.info("Recording started successfully");
		}

		@Override
		public void onError(Throwable cause) throws Exception {
			sendError(c, "Failed to start recording");
			log.error("Failed to start recording", cause);
		}
	});
}
 
Example 10
Source File: RoomSidebar.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
public void roomAction(IPartialPageRequestHandler handler, JSONObject o) {
	try {
		final String uid = o.getString(PARAM_UID);
		if (Strings.isEmpty(uid)) {
			return;
		}
		Client self = room.getClient();
		Action a = Action.valueOf(o.getString(PARAM_ACTION));
		switch (a) {
			case kick:
				if (self.hasRight(Right.MODERATOR)) {
					kickedClient = cm.get(uid);
					if (kickedClient == null) {
						return;
					}
					if (!kickedClient.hasRight(Right.SUPER_MODERATOR) && !self.getUid().equals(kickedClient.getUid())) {
						confirmKick.show(handler);
					}
				}
				break;
			case muteOthers:
				if (room.getClient().hasRight(Right.MUTE_OTHERS)) {
					WebSocketHelper.sendRoom(new TextRoomMessage(room.getRoom().getId(), self, RoomMessage.Type.MUTE_OTHERS, uid));
				}
				break;
			case mute:
			{
				Client c = cm.get(uid);
				if (c == null || !c.hasActivity(Client.Activity.AUDIO)) {
					return;
				}
				if (self.hasRight(Right.MODERATOR) || self.getUid().equals(c.getUid())) {
					WebSocketHelper.sendRoom(new TextRoomMessage(room.getRoom().getId(), self, RoomMessage.Type.MUTE
							, new JSONObject()
									.put("sid", self.getSid())
									.put(PARAM_UID, uid)
									.put("mute", o.getBoolean("mute")).toString()));
				}
			}
				break;
			case toggleRight:
				toggleRight(handler, self, uid, o);
				break;
			default:
		}
	} catch (Exception e) {
		log.error("Unexpected exception while toggle 'roomAction'", e);
	}
}
 
Example 11
Source File: JsonUtil.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
private static OArchitectOProperty convertInverseProperty(JSONObject jsonObject) {
    String name = !jsonObject.isNull(NAME) ? jsonObject.getString(NAME) : null;
    OType type = !jsonObject.isNull(TYPE) ? OType.valueOf(jsonObject.getString(TYPE)) : null;
    return !Strings.isNullOrEmpty(name) && type != null ? new OArchitectOProperty(name, type) : null;
}
 
Example 12
Source File: ExistsOClassBehavior.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
private String getClassNameFromJson(String json) {
    JSONObject obj = new JSONObject(json);
    return obj.getString(EXISTS_CLASS_VAR);
}