Search in sources :

Example 41 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class KUser method receiveVideoFrom.

public void receiveVideoFrom(final KurentoHandler h, KUser sender, String sdpOffer) {
    log.info("USER {}: connecting with {} in room {}", this.uid, sender.getUid(), this.roomId);
    log.trace("USER {}: SdpOffer for {} is {}", this.uid, sender.getUid(), sdpOffer);
    final String sdpAnswer = this.getEndpointForUser(h, sender).processOffer(sdpOffer);
    final JSONObject scParams = newKurentoMsg();
    scParams.put("id", "videoResponse");
    scParams.put("uid", sender.getUid());
    scParams.put("sdpAnswer", sdpAnswer);
    log.trace("USER {}: SdpAnswer for {} is {}", this.uid, sender.getUid(), sdpAnswer);
    h.sendClient(uid, scParams);
    log.debug("gather candidates");
    this.getEndpointForUser(h, sender).gatherCandidates();
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 42 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class KurentoHandler method onMessage.

public void onMessage(IWsClient _c, JSONObject msg) {
    if (client == null) {
        sendError(_c, "Multimedia server is inaccessible");
        return;
    }
    final String cmdId = msg.getString("id");
    if ("test".equals(msg.optString("mode"))) {
        KTestUser user = getTestByUid(_c.getUid());
        switch(cmdId) {
            case "start":
                {
                    // TODO FIXME assert null user ???
                    user = new KTestUser(_c, msg, client.createMediaPipeline());
                    testsByUid.put(_c.getUid(), user);
                }
                break;
            case "iceCandidate":
                {
                    JSONObject candidate = msg.getJSONObject("candidate");
                    if (user != null) {
                        IceCandidate cand = new IceCandidate(candidate.getString("candidate"), candidate.getString("sdpMid"), candidate.getInt("sdpMLineIndex"));
                        user.addCandidate(cand);
                    }
                }
                break;
            case "play":
                user.play(_c, msg, client.createMediaPipeline());
                break;
        }
    } else {
        final Client c = (Client) _c;
        if (c != null) {
            log.debug("Incoming message from user with ID '{}': {}", c.getUserId(), msg);
        } else {
            log.debug("Incoming message from new user: {}", msg);
        }
        KUser user = getByUid(_c.getUid());
        switch(cmdId) {
            case "joinRoom":
                joinRoom(c);
                break;
            case "receiveVideoFrom":
                final String senderUid = msg.getString("sender");
                final KUser sender = getByUid(senderUid);
                final String sdpOffer = msg.getString("sdpOffer");
                if (user == null) {
                    KRoom room = getRoom(c.getRoomId());
                    user = room.addUser(this, _c.getUid());
                }
                user.receiveVideoFrom(this, sender, sdpOffer);
                break;
            case "onIceCandidate":
                {
                    JSONObject candidate = msg.getJSONObject("candidate");
                    if (user == null) {
                        KRoom room = getRoom(c.getRoomId());
                        user = room.addUser(this, _c.getUid());
                    }
                    IceCandidate cand = new IceCandidate(candidate.getString("candidate"), candidate.getString("sdpMid"), candidate.getInt("sdpMLineIndex"));
                    user.addCandidate(cand, msg.getString("uid"));
                }
                break;
        }
    }
}
Also used : JSONObject(com.github.openjson.JSONObject) Client(org.apache.openmeetings.db.entity.basic.Client) KurentoClient(org.kurento.client.KurentoClient) IWsClient(org.apache.openmeetings.db.entity.basic.IWsClient) IceCandidate(org.kurento.client.IceCandidate)

Example 43 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class WebSocketHelper method getMessage.

public static JSONObject getMessage(User curUser, List<ChatMessage> list, BiConsumer<JSONObject, User> uFmt) {
    JSONArray arr = new JSONArray();
    final FastDateFormat fullFmt = FormatHelper.getDateTimeFormat(curUser);
    final FastDateFormat dateFmt = FormatHelper.getDateFormat(curUser);
    final FastDateFormat timeFmt = FormatHelper.getTimeFormat(curUser);
    for (ChatMessage m : list) {
        String smsg = m.getMessage();
        smsg = smsg == null ? smsg : " " + smsg.replaceAll("&nbsp;", " ") + " ";
        JSONObject from = new JSONObject().put("id", m.getFromUser().getId()).put("displayName", m.getFromName()).put("name", getDisplayName(m.getFromUser()));
        if (uFmt != null) {
            uFmt.accept(from, m.getFromUser());
        }
        arr.put(setScope(new JSONObject(), m, curUser.getId()).put("id", m.getId()).put("message", smsg).put("from", from).put("actions", curUser.getId() == m.getFromUser().getId() ? "short" : "full").put("sent", fullFmt.format(m.getSent())).put("date", dateFmt.format(m.getSent())).put("time", timeFmt.format(m.getSent())));
    }
    return new JSONObject().put("type", "chat").put("msg", arr);
}
Also used : JSONObject(com.github.openjson.JSONObject) ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) JSONArray(com.github.openjson.JSONArray) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 44 with JSONObject

use of com.github.openjson.JSONObject in project triplea by triplea-game.

the class OpenJsonUtilsTest method toMap_ShouldConvertNullSentinelValueToNull.

@Test
public void toMap_ShouldConvertNullSentinelValueToNull() {
    final JSONObject jsonObject = new JSONObject(ImmutableMap.of("name", JSONObject.NULL));
    final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
    // NB: need to test using reference equality because JSONObject#NULL#equals() is defined to be equal to null
    assertThat(properties.get("name"), is(nullValue()));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Example 45 with JSONObject

use of com.github.openjson.JSONObject in project triplea by triplea-game.

the class OpenJsonUtilsTest method toMap_ShouldReturnEmptyMapWhenJsonObjectHasNoProperties.

@Test
public void toMap_ShouldReturnEmptyMapWhenJsonObjectHasNoProperties() {
    final JSONObject jsonObject = new JSONObject();
    final Map<String, Object> properties = OpenJsonUtils.toMap(jsonObject);
    assertThat(properties, is(anEmptyMap()));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONObject(com.github.openjson.JSONObject) Test(org.junit.jupiter.api.Test)

Aggregations

JSONObject (com.github.openjson.JSONObject)64 JSONArray (com.github.openjson.JSONArray)23 Test (org.junit.jupiter.api.Test)11 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)7 Client (org.apache.openmeetings.db.entity.basic.Client)7 ArrayList (java.util.ArrayList)6 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)6 NullStringer (org.apache.openmeetings.util.NullStringer)6 Form (javax.ws.rs.core.Form)5 Response (javax.ws.rs.core.Response)5 List (java.util.List)4 Map (java.util.Map)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 Room (org.apache.openmeetings.db.entity.room.Room)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JSONFunction (org.apache.wicket.ajax.json.JSONFunction)3 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)3 JSONException (com.github.openjson.JSONException)2