tinymce/js/compatcheckmodule.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 2

Size

Lines of Code 38
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 0
c 2
b 1
f 0
nc 176
dl 0
loc 38
rs 10
wmc 10
mnd 2
bc 9
fnc 5
bpm 1.8
cpm 2
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A M.tinymce_recordrtc.check_has_gum 0 7 2
A M.tinymce_recordrtc.check_secure 0 14 4
A M.tinymce_recordrtc.check_browser 0 7 2
1
// TinyMCE recordrtc library functions for checking browser compatibility.
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, alertWarning, alertDanger */
10
/* exported countdownTicker, playerDOM */
11
/* eslint-disable camelcase, no-alert */
12
13
// Scrutinizer CI directives.
14
/** global: navigator */
15
/** global: M */
16
/** global: tinyMCEPopup */
17
/** global: alertDanger */
18
/** global: alertWarning */
19
20
M.tinymce_recordrtc = M.tinymce_recordrtc || {};
21
22
// Show alert and close plugin if browser does not support WebRTC at all.
23
M.tinymce_recordrtc.check_has_gum = function() {
24
    if (!(navigator.mediaDevices && window.MediaRecorder)) {
25
        M.tinymce_recordrtc.show_alert('nowebrtc', function() {
26
            tinyMCEPopup.close();
27
        });
28
    }
29
};
30
31
// Notify and redirect user if plugin is used from insecure location.
32
M.tinymce_recordrtc.check_secure = function() {
33
    var isSecureOrigin = (window.location.protocol === 'https:') ||
34
                         (window.location.host.indexOf('localhost') !== -1);
35
36
    if (!isSecureOrigin) {
37
        alertDanger.ancestor().ancestor().removeClass('hide');
38
39
        if (window.bowser.chrome || window.bowser.opera) {
40
            M.tinymce_recordrtc.show_alert('gumsecurity', function() {
41
                tinyMCEPopup.close();
42
            });
43
        }
44
    }
45
};
46
47
// Display "consider switching browsers" message if not using:
48
// - Firefox 29+;
49
// - Chrome 49+;
50
// - Opera 36+.
51
M.tinymce_recordrtc.check_browser = function() {
52
    if (!((window.bowser.firefox && window.bowser.version >= 29) ||
53
          (window.bowser.chrome && window.bowser.version >= 49) ||
54
          (window.bowser.opera && window.bowser.version >= 36))) {
55
        alertWarning.ancestor().ancestor().removeClass('hide');
56
    }
57
};
58