Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Tiny Record RTC - Video context menu command.
18
 *
19
 * @module      tiny_recordrtc/commands_video_context_menu
20
 * @copyright   2024 The Open University
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import {getString} from 'core/str';
25
import {getButtonImage} from 'editor_tiny/utils';
26
import {
27
    videoButtonName,
28
    screenButtonName,
29
    videoContextMenuName,
30
    component,
31
} from './common';
32
import {isVideoAllowed, isScreenAllowed} from './options';
33
import videoRecorder from "./video_recorder";
34
import screenRecorder from "./screen_recorder";
35
 
36
export default async() => {
37
    const [
38
        videoContextMenuTitle,
39
        videoButtonTitle,
40
        screenButtonTitle,
41
        buttonImageVideo,
42
        buttonImageScreen,
43
    ] = await Promise.all([
44
        getString('videorecordmenutitle', component),
45
        getString('videobuttontitle', component),
46
        getString('screenbuttontitle', component),
47
        getButtonImage('video', component),
48
        getButtonImage('screen', component),
49
    ]);
50
 
51
    return (editor) => {
52
        let useContextMenu = true;
53
        let singleButton = 'video';
54
        let singleButtonTitle = videoButtonTitle;
55
        let imageHtml = buttonImageVideo.html;
56
        let recorder;
57
        if (!isVideoAllowed(editor) && !isScreenAllowed(editor)) {
58
            return;
59
        } else if (isVideoAllowed(editor) && !isScreenAllowed(editor)) {
60
            // Only video recording is allowed.
61
            useContextMenu = false;
62
            recorder = videoRecorder;
63
        } else if (isScreenAllowed(editor) && !isVideoAllowed(editor)) {
64
            // Only screen recording is allowed.
65
            useContextMenu = false;
66
            singleButton = 'screen';
67
            singleButtonTitle = screenButtonTitle;
68
            imageHtml = buttonImageScreen.html;
69
            recorder = screenRecorder;
70
        }
71
        editor.ui.registry.addIcon(singleButton, imageHtml);
72
 
73
        if (useContextMenu) {
74
            // Add the video and screen buttons to the context menu.
75
            editor.ui.registry.addMenuButton(videoContextMenuName, {
76
                icon: singleButton,
77
                tooltip: videoContextMenuTitle,
78
                fetch: callback => callback(`${videoButtonName} ${screenButtonName}`),
79
            });
80
        } else {
81
            // Add the video or screen button to the toolbar.
82
            editor.ui.registry.addButton(videoContextMenuName, {
83
                icon: singleButton,
84
                tooltip: singleButtonTitle,
85
                onAction: () => recorder.display(editor),
86
            });
87
        }
88
    };
89
};