List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.kontalk.xmppserver.registration.checkmobi.CheckmobiValidationClient.java
License:Open Source License
public StatusResult status(String requestId) throws IOException { try {/* ww w . j a v a 2s . com*/ JsonObject data = _status(requestId); try { boolean validated = data.getAsJsonPrimitive("validated").getAsBoolean(); return new StatusResult(validated); } catch (NullPointerException e) { // simulate bad request throw new HttpResponseException(400, "Bad request"); } } catch (HttpResponseException e) { return new StatusResult(e); } }
From source file:org.kurento.demo.Pipeline.java
License:Open Source License
private static List<RegionOfInterest> readRoisFromJson(JsonArray loadedRois) { List<RegionOfInterest> rois = new ArrayList<>(); for (int j = 0; j < loadedRois.size(); j++) { JsonObject roi = (JsonObject) loadedRois.get(j); JsonArray coordinates = (JsonArray) roi.get("points"); // create structure to configure crowddetector List<RelativePoint> points = new ArrayList<>(coordinates.size()); for (int i = 0; i < coordinates.size(); i++) { JsonObject coordinate = coordinates.get(i).getAsJsonObject(); float x = coordinate.getAsJsonPrimitive("x").getAsFloat(); float y = coordinate.getAsJsonPrimitive("y").getAsFloat(); if (x > 1) { x = 1;//from w w w.j a v a 2 s . c o m } if (y > 1) { y = 1; } points.add(new RelativePoint(x, y)); } RegionOfInterestConfig config = new RegionOfInterestConfig(); config.setFluidityLevelMin(roi.getAsJsonPrimitive("fluidityLevelMin").getAsInt()); config.setFluidityLevelMed(roi.getAsJsonPrimitive("fluidityLevelMed").getAsInt()); config.setFluidityLevelMax(roi.getAsJsonPrimitive("fluidityLevelMax").getAsInt()); config.setFluidityNumFramesToEvent(roi.getAsJsonPrimitive("fluidityNumFramesToEvent").getAsInt()); config.setOccupancyLevelMin(roi.getAsJsonPrimitive("occupancyLevelMin").getAsInt()); config.setOccupancyLevelMed(roi.getAsJsonPrimitive("occupancyLevelMed").getAsInt()); config.setOccupancyLevelMax(roi.getAsJsonPrimitive("occupancyLevelMax").getAsInt()); config.setOccupancyNumFramesToEvent(roi.getAsJsonPrimitive("occupancyNumFramesToEvent").getAsInt()); config.setSendOpticalFlowEvent(roi.getAsJsonPrimitive("sendOpticalFlowEvent").getAsBoolean()); config.setOpticalFlowNumFramesToEvent(roi.getAsJsonPrimitive("opticalFlowNumFramesToEvent").getAsInt()); config.setOpticalFlowNumFramesToReset(roi.getAsJsonPrimitive("opticalFlowNumFramesToReset").getAsInt()); config.setOpticalFlowAngleOffset(roi.getAsJsonPrimitive("opticalFlowAngleOffset").getAsInt()); rois.add(new RegionOfInterest(points, config, roi.getAsJsonPrimitive("id").getAsString())); } return rois; }
From source file:org.kurento.tree.demo.TreeDemoHandler.java
License:Apache License
private synchronized void presenter(WebSocketSession session, JsonObject jsonMessage) throws IOException { if (presenterUserSession == null) { presenterUserSession = new UserSession(session); treeId = kurentoTree.createTree(); String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString(); String sdpAnswer = kurentoTree.setTreeSource(treeId, sdpOffer); JsonObject response = new JsonObject(); response.addProperty("id", "presenterResponse"); response.addProperty("response", "accepted"); response.addProperty("sdpAnswer", sdpAnswer); sendMessage(presenterUserSession.getSession(), response); } else {/*from w ww . j a v a 2s.c o m*/ JsonObject response = new JsonObject(); response.addProperty("id", "presenterResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "Another user is currently acting as sender. Try again later ..."); sendMessage(session, response); } }
From source file:org.kurento.tree.demo.TreeDemoHandler.java
License:Apache License
private synchronized void viewer(WebSocketSession session, JsonObject jsonMessage) throws IOException { if (presenterUserSession == null) { JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "No active sender now. Become sender or . Try again later ..."); sendMessage(session, response);/* w w w.j a v a 2s . c o m*/ } else { if (viewers.containsKey(session.getId())) { JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "You are already viewing in this session. Use a different browser to add additional viewers."); sendMessage(session, response); return; } UserSession viewer = new UserSession(session); viewers.put(session.getId(), viewer); String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString(); TreeEndpoint treeEndpoint = kurentoTree.addTreeSink(treeId, sdpOffer); viewer.setSinkId(treeEndpoint.getId()); String sdpAnswer = treeEndpoint.getSdp(); JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "accepted"); response.addProperty("sdpAnswer", sdpAnswer); sendMessage(viewer.getSession(), response); } }
From source file:org.kurento.tutorial.one2manycall.CallHandler.java
License:Open Source License
private synchronized void presenter(final WebSocketSession session, JsonObject jsonMessage) throws IOException { if (presenterUserSession == null) { presenterUserSession = new UserSession(session); pipeline = kurento.createMediaPipeline(); presenterUserSession.setWebRtcEndpoint(new WebRtcEndpoint.Builder(pipeline).build()); WebRtcEndpoint presenterWebRtc = presenterUserSession.getWebRtcEndpoint(); presenterWebRtc.addOnIceCandidateListener(new EventListener<OnIceCandidateEvent>() { @Override/*from ww w . ja va 2 s . com*/ public void onEvent(OnIceCandidateEvent event) { JsonObject response = new JsonObject(); response.addProperty("id", "iceCandidate"); response.add("candidate", JsonUtils.toJsonObject(event.getCandidate())); try { synchronized (session) { session.sendMessage(new TextMessage(response.toString())); } } catch (IOException e) { log.debug(e.getMessage()); } } }); String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString(); String sdpAnswer = presenterWebRtc.processOffer(sdpOffer); JsonObject response = new JsonObject(); response.addProperty("id", "presenterResponse"); response.addProperty("response", "accepted"); response.addProperty("sdpAnswer", sdpAnswer); synchronized (session) { presenterUserSession.sendMessage(response); } presenterWebRtc.gatherCandidates(); } else { JsonObject response = new JsonObject(); response.addProperty("id", "presenterResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "Another user is currently acting as sender. Try again later ..."); session.sendMessage(new TextMessage(response.toString())); } }
From source file:org.kurento.tutorial.one2manycall.CallHandler.java
License:Open Source License
private synchronized void viewer(final WebSocketSession session, JsonObject jsonMessage) throws IOException { if (presenterUserSession == null || presenterUserSession.getWebRtcEndpoint() == null) { JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "No active sender now. Become sender or . Try again later ..."); session.sendMessage(new TextMessage(response.toString())); } else {//from w ww . j av a 2 s . co m if (viewers.containsKey(session.getId())) { JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "You are already viewing in this session. Use a different browser to add additional viewers."); session.sendMessage(new TextMessage(response.toString())); return; } UserSession viewer = new UserSession(session); viewers.put(session.getId(), viewer); String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString(); WebRtcEndpoint nextWebRtc = new WebRtcEndpoint.Builder(pipeline).build(); nextWebRtc.addOnIceCandidateListener(new EventListener<OnIceCandidateEvent>() { @Override public void onEvent(OnIceCandidateEvent event) { JsonObject response = new JsonObject(); response.addProperty("id", "iceCandidate"); response.add("candidate", JsonUtils.toJsonObject(event.getCandidate())); try { synchronized (session) { session.sendMessage(new TextMessage(response.toString())); } } catch (IOException e) { log.debug(e.getMessage()); } } }); viewer.setWebRtcEndpoint(nextWebRtc); presenterUserSession.getWebRtcEndpoint().connect(nextWebRtc); String sdpAnswer = nextWebRtc.processOffer(sdpOffer); JsonObject response = new JsonObject(); response.addProperty("id", "viewerResponse"); response.addProperty("response", "accepted"); response.addProperty("sdpAnswer", sdpAnswer); synchronized (session) { viewer.sendMessage(response); } nextWebRtc.gatherCandidates(); } }
From source file:org.kurento.tutorial.one2onecalladv.CallHandler.java
License:Open Source License
private void call(UserSession caller, JsonObject jsonMessage) throws IOException { String to = jsonMessage.get("to").getAsString(); String from = jsonMessage.get("from").getAsString(); JsonObject response = new JsonObject(); if (registry.exists(to)) { UserSession callee = registry.getByName(to); caller.setSdpOffer(jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString()); caller.setCallingTo(to);//from w w w . ja v a 2 s.c o m response.addProperty("id", "incomingCall"); response.addProperty("from", from); callee.sendMessage(response); callee.setCallingFrom(from); } else { response.addProperty("id", "callResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "user '" + to + "' is not registered"); caller.sendMessage(response); } }
From source file:org.kurento.tutorial.one2onecallrec.CallHandler.java
License:Apache License
private void call(UserSession caller, JsonObject jsonMessage) throws IOException { String to = jsonMessage.get("to").getAsString(); String from = jsonMessage.get("from").getAsString(); JsonObject response = new JsonObject(); if (registry.exists(to)) { caller.setSdpOffer(jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString()); caller.setCallingTo(to);/*from www . jav a 2 s .co m*/ response.addProperty("id", "incomingCall"); response.addProperty("from", from); UserSession callee = registry.getByName(to); callee.sendMessage(response); callee.setCallingFrom(from); } else { response.addProperty("id", "callResponse"); response.addProperty("response", "rejected"); response.addProperty("message", "user '" + to + "' is not registered"); caller.sendMessage(response); } }
From source file:org.lanternpowered.server.text.gson.JsonTextBaseSerializer.java
License:MIT License
public static void deserialize(JsonObject json, Text.Builder builder, JsonDeserializationContext context, @Nullable JsonArray children) throws JsonParseException { JsonElement element;// w w w.j a va2s . c o m if ((element = json.get(COLOR)) != null) { Sponge.getRegistry().getType(TextColor.class, element.getAsString()).ifPresent(builder::color); } TextStyle style = builder.getStyle(); if ((element = json.get(BOLD)) != null) { style = style.bold(element.getAsBoolean()); } if ((element = json.get(ITALIC)) != null) { style = style.italic(element.getAsBoolean()); } if ((element = json.get(UNDERLINE)) != null) { style = style.underline(element.getAsBoolean()); } if ((element = json.get(STRIKETHROUGH)) != null) { style = style.strikethrough(element.getAsBoolean()); } if ((element = json.get(OBFUSCATED)) != null) { style = style.obfuscated(element.getAsBoolean()); } builder.style(style); if (children != null) { builder.append((Text[]) context.deserialize(children, Text[].class)); } if ((element = json.get(CLICK_EVENT)) != null) { final JsonObject jsonClickEvent = element.getAsJsonObject(); if (jsonClickEvent != null) { final JsonPrimitive jsonEventAction = jsonClickEvent.getAsJsonPrimitive(EVENT_ACTION); final JsonPrimitive jsonEventValue = jsonClickEvent.getAsJsonPrimitive(EVENT_VALUE); if (jsonEventAction != null && jsonEventValue != null) { final String action = jsonEventAction.getAsString(); final String value = jsonEventValue.getAsString(); final ClickAction<?> clickAction = LanternTextHelper.parseClickAction(action, value); if (clickAction != null) { builder.onClick(clickAction); } } } } if ((element = json.get(HOVER_EVENT)) != null) { final JsonObject jsonHoverEvent = element.getAsJsonObject(); if (jsonHoverEvent != null) { final JsonPrimitive jsonEventAction = jsonHoverEvent.getAsJsonPrimitive(EVENT_ACTION); final JsonPrimitive jsonEventValue = jsonHoverEvent.getAsJsonPrimitive(EVENT_VALUE); if (jsonEventAction != null && jsonEventValue != null) { final String action = jsonEventAction.getAsString(); final String value = jsonEventValue.getAsString(); final HoverAction<?> hoverAction = LanternTextHelper.parseHoverAction(action, value); if (hoverAction != null) { builder.onHover(hoverAction); } } } } if ((element = json.get(INSERTION)) != null) { builder.onShiftClick(TextActions.insertText(element.getAsString())); } }
From source file:org.matrix.androidsdk.call.MXCallsManager.java
License:Apache License
/** * Manage the call events.//from w w w . ja v a 2s.c o m * @param event the call event. */ public void handleCallEvent(final Event event) { if (event.isCallEvent() && isSupported()) { Log.d(LOG_TAG, "handleCallEvent " + event.getType()); // always run the call event in the UI thread // MXChromeCall does not work properly in other thread (because of the webview) mUIThreadHandler.post(new Runnable() { @Override public void run() { boolean isMyEvent = TextUtils.equals(event.getSender(), mSession.getMyUserId()); Room room = mSession.getDataHandler().getRoom(event.roomId); String callId = null; JsonObject eventContent = null; try { eventContent = event.getContentAsJsonObject(); callId = eventContent.getAsJsonPrimitive("call_id").getAsString(); } catch (Exception e) { Log.e(LOG_TAG, "handleCallEvent : fail to retrieve call_id " + e.getMessage()); } // sanity check if ((null != callId) && (null != room)) { // receive an invitation if (Event.EVENT_TYPE_CALL_INVITE.equals(event.getType())) { long lifeTime = event.getAge(); if (Long.MAX_VALUE == lifeTime) { lifeTime = System.currentTimeMillis() - event.getOriginServerTs(); } // ignore older call messages if (lifeTime < 30000) { // create the call only it is triggered from someone else IMXCall call = getCallWithCallId(callId, !isMyEvent); // sanity check if (null != call) { // init the information if (null == call.getRoom()) { call.setRooms(room, room); } if (!isMyEvent) { call.prepareIncomingCall(eventContent, callId, null); call.setIsIncoming(true); mxPendingIncomingCallId.add(callId); } else { call.handleCallEvent(event); } } } else { Log.d(LOG_TAG, "## handleCallEvent() : " + Event.EVENT_TYPE_CALL_INVITE + " is ignored because it is too old"); } } else if (Event.EVENT_TYPE_CALL_CANDIDATES.equals(event.getType())) { if (!isMyEvent) { IMXCall call = getCallWithCallId(callId); if (null != call) { if (null == call.getRoom()) { call.setRooms(room, room); } call.handleCallEvent(event); } } } else if (Event.EVENT_TYPE_CALL_ANSWER.equals(event.getType())) { IMXCall call = getCallWithCallId(callId); if (null != call) { // assume it is a catch up call. // the creation / candidates / // the call has been answered on another device if (IMXCall.CALL_STATE_CREATED.equals(call.getCallState())) { call.onAnsweredElsewhere(); synchronized (this) { mCallsByCallId.remove(callId); } } else { if (null == call.getRoom()) { call.setRooms(room, room); } call.handleCallEvent(event); } } } else if (Event.EVENT_TYPE_CALL_HANGUP.equals(event.getType())) { final IMXCall call = getCallWithCallId(callId); if (null != call) { // trigger call events only if the call is active final boolean isActiveCall = !IMXCall.CALL_STATE_CREATED .equals(call.getCallState()); if (null == call.getRoom()) { call.setRooms(room, room); } if (isActiveCall) { call.handleCallEvent(event); } synchronized (this) { mCallsByCallId.remove(callId); } // warn that a call has been hung up mUIThreadHandler.post(new Runnable() { @Override public void run() { // must warn anyway any listener that the call has been killed // for example, when the device is in locked screen // the callview is not created but the device is ringing // if the other participant ends the call, the ring should stop dispatchOnCallHangUp(call); } }); } } } } }); } }