Search in sources :

Example 1 with IceCandidate

use of org.kurento.client.IceCandidate 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)

Aggregations

JSONObject (com.github.openjson.JSONObject)1 Client (org.apache.openmeetings.db.entity.basic.Client)1 IWsClient (org.apache.openmeetings.db.entity.basic.IWsClient)1 IceCandidate (org.kurento.client.IceCandidate)1 KurentoClient (org.kurento.client.KurentoClient)1