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();
}
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;
}
}
}
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(" ", " ") + " ";
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);
}
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()));
}
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()));
}
Aggregations