Search in sources :

Example 1 with Whiteboard

use of org.apache.openmeetings.db.dto.room.Whiteboard in project openmeetings by apache.

the class WbPanel method loadWhiteboards.

private StringBuilder loadWhiteboards(StringBuilder sb, Client cl, Whiteboards wbs, Set<Entry<Long, Whiteboard>> boardSet) {
    for (Entry<Long, Whiteboard> entry : boardSet) {
        Whiteboard wb = entry.getValue();
        sb.append(new StringBuilder("WbArea.create(").append(getAddWbJson(wb)).append(");"));
        JSONArray arr = new JSONArray();
        for (JSONObject o : wb.list()) {
            arr.put(addFileUrl(cl, wbs.getUid(), o));
        }
        sb.append("WbArea.load(").append(getObjWbJson(entry.getKey(), arr).toString(new NullStringer())).append(");");
    }
    return sb;
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray) NullStringer(org.apache.openmeetings.util.NullStringer) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard)

Example 2 with Whiteboard

use of org.apache.openmeetings.db.dto.room.Whiteboard in project openmeetings by apache.

the class WbPanel method sendFileToWb.

@Override
public void sendFileToWb(final BaseFileItem fi, boolean clean) {
    if (isVisible() && fi.getId() != null) {
        Whiteboards wbs = wbm.get(roomId);
        String wuid = UUID.randomUUID().toString();
        Whiteboard wb = wbs.get(wbs.getActiveWb());
        switch(fi.getType()) {
            case Folder:
                // do nothing
                break;
            case WmlFile:
                {
                    File f = fi.getFile();
                    if (f.exists() && f.isFile()) {
                        try (BufferedReader br = Files.newBufferedReader(f.toPath())) {
                            final boolean[] updated = { false };
                            JSONArray arr = getArray(new JSONObject(new JSONTokener(br)), o -> {
                                wb.put(o.getString("uid"), o);
                                updated[0] = true;
                                return addFileUrl(rp.getClient(), wbs.getUid(), o, _f -> updateWbSize(wb, _f));
                            });
                            if (updated[0]) {
                                wbm.update(roomId, wb);
                            }
                            sendWbAll(WbAction.setSize, getAddWbJson(wb));
                            sendWbAll(WbAction.load, getObjWbJson(wb.getId(), arr));
                        } catch (Exception e) {
                            log.error("Unexpected error while loading WB", e);
                        }
                    }
                }
                break;
            case PollChart:
                break;
            default:
                {
                    JSONObject file = new JSONObject().put(ATTR_FILE_ID, fi.getId()).put(ATTR_FILE_TYPE, fi.getType().name()).put("count", fi.getCount()).put(ATTR_TYPE, "image").put("left", UPLOAD_WB_LEFT).put("top", UPLOAD_WB_TOP).put("width", fi.getWidth() == null ? DEFAULT_WIDTH : fi.getWidth()).put("height", fi.getHeight() == null ? DEFAULT_HEIGHT : fi.getHeight()).put("uid", wuid).put(ATTR_SLIDE, wb.getSlide());
                    if (FileItem.Type.Video == fi.getType() || FileItem.Type.Recording == fi.getType()) {
                        file.put(ATTR_TYPE, "video");
                        file.put(PARAM_STATUS, new JSONObject().put("paused", true).put("pos", 0.0).put("updated", System.currentTimeMillis()));
                    }
                    final String ruid = wbs.getUid();
                    if (clean) {
                        clearAll(roomId, wb.getId());
                    }
                    wb.put(wuid, file);
                    updateWbSize(wb, fi);
                    wbm.update(roomId, wb);
                    sendWbAll(WbAction.setSize, getAddWbJson(wb));
                    WbWebSocketHelper.sendWbFile(roomId, wb.getId(), ruid, file, fi);
                }
                break;
        }
    }
}
Also used : JSONTokener(com.github.openjson.JSONTokener) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard) Arrays(java.util.Arrays) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) Strings(org.apache.directory.api.util.Strings) FileItemDao(org.apache.openmeetings.db.dao.file.FileItemDao) LoggerFactory(org.slf4j.LoggerFactory) RoomElement(org.apache.openmeetings.db.entity.room.Room.RoomElement) WbWebSocketHelper.getWbJson(org.apache.openmeetings.web.room.wb.WbWebSocketHelper.getWbJson) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) Base64(org.apache.commons.codec.binary.Base64) Whiteboards(org.apache.openmeetings.db.dto.room.Whiteboards) WhiteboardManager(org.apache.openmeetings.web.app.WhiteboardManager) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) JSONArray(com.github.openjson.JSONArray) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Right(org.apache.openmeetings.db.entity.room.Room.Right) ListView(org.apache.wicket.markup.html.list.ListView) ResourceReference(org.apache.wicket.request.resource.ResourceReference) ZoomMode(org.apache.openmeetings.db.dto.room.Whiteboard.ZoomMode) Method(org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method) NullStringer(org.apache.openmeetings.util.NullStringer) BufferedImage(java.awt.image.BufferedImage) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) ListItem(org.apache.wicket.markup.html.list.ListItem) Set(java.util.Set) UUID(java.util.UUID) Room(org.apache.openmeetings.db.entity.room.Room) List(java.util.List) JavaScriptResourceReference(org.apache.wicket.request.resource.JavaScriptResourceReference) WbWebSocketHelper.getObjWbJson(org.apache.openmeetings.web.room.wb.WbWebSocketHelper.getObjWbJson) Entry(java.util.Map.Entry) LosslessFactory(org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory) PDPage(org.apache.pdfbox.pdmodel.PDPage) JSONTokener(com.github.openjson.JSONTokener) ATTR_TYPE(org.apache.openmeetings.db.dto.room.Whiteboard.ATTR_TYPE) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NameDialog(org.apache.openmeetings.web.common.NameDialog) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) OmFileHelper(org.apache.openmeetings.util.OmFileHelper) ATTR_FILE_TYPE(org.apache.openmeetings.db.dto.room.Whiteboard.ATTR_FILE_TYPE) AppendMode(org.apache.pdfbox.pdmodel.PDPageContentStream.AppendMode) PARAM_STATUS(org.apache.openmeetings.util.OpenmeetingsVariables.PARAM_STATUS) LinkedList(java.util.LinkedList) RoomFile(org.apache.openmeetings.db.entity.room.RoomFile) RoomPanel(org.apache.openmeetings.web.room.RoomPanel) ITEMS_KEY(org.apache.openmeetings.db.dto.room.Whiteboard.ITEMS_KEY) Logger(org.slf4j.Logger) ATTR_CLASS(org.apache.openmeetings.util.OpenmeetingsVariables.ATTR_CLASS) ATTR_SLIDE(org.apache.openmeetings.db.dto.room.Whiteboard.ATTR_SLIDE) Files(java.nio.file.Files) ATTR_FILE_ID(org.apache.openmeetings.db.dto.room.Whiteboard.ATTR_FILE_ID) IOException(java.io.IOException) Client(org.apache.openmeetings.db.entity.basic.Client) AttributeModifier.append(org.apache.wicket.AttributeModifier.append) FileItem(org.apache.openmeetings.db.entity.file.FileItem) JSONObject(com.github.openjson.JSONObject) File(java.io.File) Consumer(java.util.function.Consumer) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) TreeMap(java.util.TreeMap) BufferedReader(java.io.BufferedReader) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) Whiteboards(org.apache.openmeetings.db.dto.room.Whiteboards) JSONObject(com.github.openjson.JSONObject) BufferedReader(java.io.BufferedReader) JSONArray(com.github.openjson.JSONArray) RoomFile(org.apache.openmeetings.db.entity.room.RoomFile) File(java.io.File) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard) IOException(java.io.IOException)

Example 3 with Whiteboard

use of org.apache.openmeetings.db.dto.room.Whiteboard in project openmeetings by apache.

the class WbPanel method processWbAction.

@Override
protected void processWbAction(WbAction a, JSONObject obj, AjaxRequestTarget target) throws IOException {
    Client c = rp.getClient();
    if (c == null) {
        return;
    }
    switch(a) {
        case createObj:
        case modifyObj:
            {
                JSONObject o = obj.optJSONObject("obj");
                if (o != null && "pointer".equals(o.getString(ATTR_TYPE))) {
                    sendWbOthers(a, obj);
                    return;
                }
            }
            break;
        case downloadPdf:
            {
                boolean moder = c.hasRight(Room.Right.moderator);
                Room r = rp.getRoom();
                if ((moder && !r.isHidden(RoomElement.ActionMenu)) || (!moder && r.isAllowUserQuestions())) {
                    try (PDDocument doc = new PDDocument()) {
                        JSONArray arr = obj.getJSONArray("slides");
                        for (int i = 0; i < arr.length(); ++i) {
                            String base64Image = arr.getString(i).split(",")[1];
                            byte[] bb = Base64.decodeBase64(base64Image);
                            BufferedImage img = ImageIO.read(new ByteArrayInputStream(bb));
                            float width = img.getWidth();
                            float height = img.getHeight();
                            PDPage page = new PDPage(new PDRectangle(width, height));
                            PDImageXObject pdImageXObject = LosslessFactory.createFromImage(doc, img);
                            try (PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.APPEND, false)) {
                                contentStream.drawImage(pdImageXObject, 0, 0, width, height);
                            }
                            doc.addPage(page);
                        }
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        doc.save(baos);
                        rp.startDownload(target, baos.toByteArray());
                    }
                }
                return;
            }
        case loadVideos:
            {
                StringBuilder sb = new StringBuilder("WbArea.initVideos(");
                JSONArray arr = new JSONArray();
                for (Entry<Long, Whiteboard> entry : wbm.list(roomId)) {
                    Whiteboard wb = entry.getValue();
                    for (JSONObject o : wb.list()) {
                        String ft = o.optString(ATTR_FILE_TYPE);
                        if (BaseFileItem.Type.Recording.name().equals(ft) || BaseFileItem.Type.Video.name().equals(ft)) {
                            JSONObject _sts = o.optJSONObject(PARAM_STATUS);
                            if (_sts == null) {
                                continue;
                            }
                            // copy
                            JSONObject sts = new JSONObject(_sts.toString());
                            sts.put("pos", sts.getDouble("pos") + (System.currentTimeMillis() - sts.getLong("updated")) * 1. / 1000);
                            arr.put(new JSONObject().put("wbId", wb.getId()).put("uid", o.getString("uid")).put(ATTR_SLIDE, o.getString(ATTR_SLIDE)).put(PARAM_STATUS, sts));
                        }
                    }
                }
                sb.append(arr.toString()).append(");");
                target.appendJavaScript(sb);
                return;
            }
        default:
            break;
    }
    // presenter-right
    if (c.hasRight(Right.presenter)) {
        switch(a) {
            case createWb:
                {
                    Whiteboard wb = wbm.add(roomId, c.getUser().getLanguageId());
                    sendWbAll(WbAction.createWb, getAddWbJson(wb));
                }
                break;
            case removeWb:
                {
                    long id = obj.optLong("wbId", -1);
                    if (id > -1) {
                        wbm.remove(roomId, id);
                        sendWbAll(WbAction.removeWb, obj);
                    }
                }
                break;
            case activateWb:
                {
                    long _id = obj.optLong("wbId", -1);
                    if (_id > -1) {
                        wbm.activate(roomId, _id);
                        sendWbAll(WbAction.activateWb, obj);
                    }
                }
                break;
            case renameWb:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.optLong("wbId", -1));
                    if (wb != null) {
                        wbm.update(roomId, wb.setName(obj.getString("name")));
                        sendWbAll(WbAction.renameWb, obj);
                    }
                }
                break;
            case setSlide:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.optLong("wbId", -1));
                    if (wb != null) {
                        wb.setSlide(obj.optInt(ATTR_SLIDE, 0));
                        wbm.update(roomId, wb);
                        sendWbOthers(WbAction.setSlide, obj);
                    }
                }
                break;
            case clearAll:
                {
                    clearAll(roomId, obj.getLong("wbId"));
                }
                break;
            case setSize:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    wb.setZoom(obj.getDouble("zoom"));
                    wb.setZoomMode(ZoomMode.valueOf(obj.getString("zoomMode")));
                    wbm.update(roomId, wb);
                    sendWbOthers(WbAction.setSize, getAddWbJson(wb));
                }
                break;
            default:
                break;
        }
    }
    // wb-right
    if (c.hasRight(Right.presenter) || c.hasRight(Right.whiteBoard)) {
        switch(a) {
            case createObj:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    JSONObject o = obj.getJSONObject("obj");
                    wb.put(o.getString("uid"), o);
                    wbm.update(roomId, wb);
                    addUndo(wb.getId(), new UndoObject(UndoObject.Type.add, o));
                    sendWbOthers(WbAction.createObj, obj);
                }
                break;
            case modifyObj:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    JSONArray arr = obj.getJSONArray("obj");
                    JSONArray undo = new JSONArray();
                    for (int i = 0; i < arr.length(); ++i) {
                        JSONObject _o = arr.getJSONObject(i);
                        String uid = _o.getString("uid");
                        JSONObject po = wb.get(uid);
                        if (po != null) {
                            undo.put(po);
                            wb.put(uid, _o);
                        }
                    }
                    if (arr.length() != 0) {
                        wbm.update(roomId, wb);
                        addUndo(wb.getId(), new UndoObject(UndoObject.Type.modify, undo));
                    }
                    sendWbOthers(WbAction.modifyObj, obj);
                }
                break;
            case deleteObj:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    JSONArray arr = obj.getJSONArray("obj");
                    JSONArray undo = new JSONArray();
                    for (int i = 0; i < arr.length(); ++i) {
                        JSONObject _o = arr.getJSONObject(i);
                        JSONObject u = wb.remove(_o.getString("uid"));
                        if (u != null) {
                            undo.put(u);
                        }
                    }
                    if (undo.length() != 0) {
                        wbm.update(roomId, wb);
                        addUndo(wb.getId(), new UndoObject(UndoObject.Type.remove, undo));
                    }
                    sendWbAll(WbAction.deleteObj, obj);
                }
                break;
            case clearSlide:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    JSONArray arr = wb.clearSlide(obj.getInt(ATTR_SLIDE));
                    if (arr.length() != 0) {
                        wbm.update(roomId, wb);
                        addUndo(wb.getId(), new UndoObject(UndoObject.Type.remove, arr));
                    }
                    sendWbAll(WbAction.clearSlide, obj);
                }
                break;
            case save:
                wb2save = obj.getLong("wbId");
                fileName.open(target);
                break;
            case undo:
                {
                    Long wbId = obj.getLong("wbId");
                    UndoObject uo = getUndo(wbId);
                    if (uo != null) {
                        Whiteboard wb = wbm.get(roomId).get(wbId);
                        switch(uo.getType()) {
                            case add:
                                {
                                    JSONObject o = new JSONObject(uo.getObject());
                                    wb.remove(o.getString("uid"));
                                    wbm.update(roomId, wb);
                                    sendWbAll(WbAction.deleteObj, obj.put("obj", new JSONArray().put(o)));
                                }
                                break;
                            case remove:
                                {
                                    JSONArray arr = new JSONArray(uo.getObject());
                                    for (int i = 0; i < arr.length(); ++i) {
                                        JSONObject o = arr.getJSONObject(i);
                                        wb.put(o.getString("uid"), o);
                                    }
                                    wbm.update(roomId, wb);
                                    sendWbAll(WbAction.createObj, obj.put("obj", new JSONArray(uo.getObject())));
                                }
                                break;
                            case modify:
                                {
                                    JSONArray arr = new JSONArray(uo.getObject());
                                    for (int i = 0; i < arr.length(); ++i) {
                                        JSONObject o = arr.getJSONObject(i);
                                        wb.put(o.getString("uid"), o);
                                    }
                                    wbm.update(roomId, wb);
                                    sendWbAll(WbAction.modifyObj, obj.put("obj", arr));
                                }
                                break;
                        }
                    }
                }
                break;
            case videoStatus:
                {
                    Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId"));
                    String uid = obj.getString("uid");
                    JSONObject po = wb.get(uid);
                    if (po != null && "video".equals(po.getString(ATTR_TYPE))) {
                        JSONObject ns = obj.getJSONObject(PARAM_STATUS);
                        po.put(PARAM_STATUS, ns.put("updated", System.currentTimeMillis()));
                        wbm.update(roomId, wb.put(uid, po));
                        obj.put(ATTR_SLIDE, po.getInt(ATTR_SLIDE));
                        sendWbAll(WbAction.videoStatus, obj);
                    }
                }
                break;
            default:
                break;
        }
    }
}
Also used : PDPage(org.apache.pdfbox.pdmodel.PDPage) JSONArray(com.github.openjson.JSONArray) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) PDImageXObject(org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) Entry(java.util.Map.Entry) JSONObject(com.github.openjson.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle) PDPageContentStream(org.apache.pdfbox.pdmodel.PDPageContentStream) Client(org.apache.openmeetings.db.entity.basic.Client) Room(org.apache.openmeetings.db.entity.room.Room) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard)

Example 4 with Whiteboard

use of org.apache.openmeetings.db.dto.room.Whiteboard in project openmeetings by apache.

the class WhiteboardManager method add.

private static Whiteboard add(Whiteboards wbs, Long langId) {
    Whiteboard wb = new Whiteboard(getDefaultName(langId == null ? getDefaultLang() : langId, wbs.count()));
    wbs.add(wb);
    return wb;
}
Also used : Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard)

Example 5 with Whiteboard

use of org.apache.openmeetings.db.dto.room.Whiteboard in project openmeetings by apache.

the class RecordingResourceReference method getRecording.

private Recording getRecording(Long id, String ruid, String uid) {
    log.debug("Recording with id {} is requested", id);
    Recording r = recDao.get(id);
    if (r == null || r.getType() == Type.Folder || r.isDeleted()) {
        return null;
    }
    if (id.equals(getRecordingId())) {
        return r;
    }
    Client c = cm.get(uid);
    if (c != null && c.getRoom() != null) {
        Whiteboards wbs = wbm.get(c.getRoom().getId());
        if (wbs != null && !Strings.isEmpty(ruid) && ruid.equals(wbs.getUid())) {
            for (Entry<Long, Whiteboard> e : wbs.getWhiteboards().entrySet()) {
                if (e.getValue().contains(r.getHash())) {
                    // item IS on WB
                    return r;
                }
            }
        }
    }
    if (r.getOwnerId() == null && r.getGroupId() == null) {
        // public
        return r;
    }
    if (r.getOwnerId() != null && getUserId().equals(r.getOwnerId())) {
        // own
        return r;
    }
    if (r.getGroupId() != null && groupUserDao.isUserInGroup(r.getGroupId(), getUserId())) {
        return r;
    }
    // external group check was added for plugin recording download
    String extType = getExternalType();
    if (extType != null) {
        User creator = userDao.get(r.getInsertedBy());
        if (extType.equals(creator.getExternalType())) {
            return r;
        }
    }
    return null;
}
Also used : User(org.apache.openmeetings.db.entity.user.User) Whiteboards(org.apache.openmeetings.db.dto.room.Whiteboards) Recording(org.apache.openmeetings.db.entity.record.Recording) Client(org.apache.openmeetings.db.entity.basic.Client) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard)

Aggregations

Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)16 Whiteboards (org.apache.openmeetings.db.dto.room.Whiteboards)8 JSONObject (com.github.openjson.JSONObject)7 JSONArray (com.github.openjson.JSONArray)4 Client (org.apache.openmeetings.db.entity.basic.Client)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)3 FileItem (org.apache.openmeetings.db.entity.file.FileItem)3 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Entry (java.util.Map.Entry)2 TreeMap (java.util.TreeMap)2 Room (org.apache.openmeetings.db.entity.room.Room)2