Completed
Branch pre-recording-server (120b27)
by Jacob
02:07
created

tinymce/js/abstractmodule.js   A

Complexity

Total Complexity 11
Complexity/F 1.57

Size

Lines of Code 72
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 2
dl 0
loc 72
rs 10
wmc 11
mnd 1
bc 13
fnc 7
bpm 1.8571
cpm 1.5713
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
B M.tinymce_recordrtc.select_rec_options 0 33 3
A M.tinymce_recordrtc.handle_gum_errors 0 18 2
A M.tinymce_recordrtc.show_alert 0 12 1
1
// TinyMCE recordrtc library functions for function abstractions.
2
// @package    tinymce_recordrtc.
3
// @author     Jesus Federico  (jesus [at] blindsidenetworks [dt] com).
4
// @author     Jacob Prud'homme (jacob [dt] prudhomme [at] blindsidenetworks [dt] com)
5
// @copyright  2016 onwards, Blindside Networks Inc.
6
// @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
7
8
// ESLint directives.
9
/* global tinyMCEPopup */
10
/* exported countdownTicker, playerDOM */
11
/* eslint-disable camelcase, no-alert */
12
13
// Scrutinizer CI directives.
14
/** global: M */
15
/** global: Y */
16
/** global: tinyMCEPopup */
17
18
M.tinymce_recordrtc = M.tinymce_recordrtc || {};
19
20
// A helper for making a Moodle alert appear.
21
// Subject is the content of the alert (which error ther alert is for).
22
// Possibility to add on-alert-close event.
23
M.tinymce_recordrtc.show_alert = function(subject, onCloseEvent) {
24
    Y.use('moodle-core-notification-alert', function() {
25
        var dialogue = new M.core.alert({
26
            title: M.util.get_string(subject + '_title', 'tinymce_recordrtc'),
27
            message: M.util.get_string(subject, 'tinymce_recordrtc')
28
        });
29
30
        if (onCloseEvent) {
31
            dialogue.after('complete', onCloseEvent);
32
        }
33
    });
34
};
35
36
// Handle getUserMedia errors.
37
M.tinymce_recordrtc.handle_gum_errors = function(error, commonConfig) {
38
    var btnLabel = M.util.get_string('recordingfailed', 'tinymce_recordrtc'),
39
        treatAsStopped = function() {
40
            commonConfig.onMediaStopped(btnLabel);
41
        };
42
43
    // Changes 'CertainError' -> 'gumcertain' to match language string names.
44
    var stringName = 'gum' + error.name.replace('Error', '').toLowerCase();
45
46
    // After alert, proceed to treat as stopped recording, or close dialogue.
47
    if (stringName !== 'gumsecurity') {
48
        M.tinymce_recordrtc.show_alert(stringName, treatAsStopped);
49
    } else {
50
        M.tinymce_recordrtc.show_alert(stringName, function() {
51
            tinyMCEPopup.close();
52
        });
53
    }
54
};
55
56
// Select best options for the recording codec.
57
M.tinymce_recordrtc.select_rec_options = function(recType) {
58
    var types, options;
59
60
    if (recType === 'audio') {
61
        types = [
62
            'audio/webm;codecs=opus',
63
            'audio/ogg;codecs=opus'
64
        ];
65
        options = {
66
            audioBitsPerSecond: window.parseInt(window.params.audiobitrate)
67
        };
68
    } else {
69
        types = [
70
            'video/webm;codecs=vp9,opus',
71
            'video/webm;codecs=h264,opus',
72
            'video/webm;codecs=vp8,opus'
73
        ];
74
        options = {
75
            audioBitsPerSecond: window.parseInt(window.params.audiobitrate),
76
            videoBitsPerSecond: window.parseInt(window.params.videobitrate)
77
        };
78
    }
79
80
    var compatTypes = types.filter(function(type) {
81
        return window.MediaRecorder.isTypeSupported(type);
82
    });
83
84
    if (compatTypes !== []) {
85
        options.mimeType = compatTypes[0];
86
    }
87
88
    return options;
89
};
90