@osimatic/helpers-js 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/media.js +96 -10
- package/package.json +1 -1
- package/.idea/helpers-js.iml +0 -8
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
package/media.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
class AudioMedia {
|
|
2
2
|
|
|
3
3
|
static getPlayer(playUrl) {
|
|
4
|
-
return '<audio controls preload="none"><source src="'+playUrl+'" type="audio/x-wav"></audio>';
|
|
4
|
+
return '<audio controls preload="none"><source src="' + playUrl + '" type="audio/x-wav"></audio>';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
static initPlayLinks(div) {
|
|
8
8
|
// Affiche un lecteur audio
|
|
9
|
-
div.find('.play_link').off('click').click(function() {
|
|
9
|
+
div.find('.play_link').off('click').click(function () {
|
|
10
10
|
let audio = $(AudioMedia.getPlayer($(this).data('play_url')));
|
|
11
11
|
audio[0].play();
|
|
12
12
|
$(this).after(audio);
|
|
@@ -14,7 +14,7 @@ class AudioMedia {
|
|
|
14
14
|
return false;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
div.find('.play_asynchronously_link').off('click').click(function() {
|
|
17
|
+
div.find('.play_asynchronously_link').off('click').click(function () {
|
|
18
18
|
if ($(this).buttonLoader('loading') != null) {
|
|
19
19
|
let button = $(this).buttonLoader('loading');
|
|
20
20
|
AudioMedia.playAudioUrl($(this).data('url'), () => button.buttonLoader('reset'));
|
|
@@ -22,11 +22,11 @@ class AudioMedia {
|
|
|
22
22
|
let button = $(this).attr('disabled', true).button('loading');
|
|
23
23
|
AudioMedia.playAudioUrl($(this).data('url'), () => button.attr('disabled', false).button('reset'));
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
return false;
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
div.find('.modal_play_link').off('click').click(function() {
|
|
29
|
+
div.find('.modal_play_link').off('click').click(function () {
|
|
30
30
|
$('#modal_voice_message_play').on('show.bs.modal', function (event) {
|
|
31
31
|
let button = $(event.relatedTarget);
|
|
32
32
|
let modal = $(this);
|
|
@@ -49,15 +49,15 @@ class AudioMedia {
|
|
|
49
49
|
Object.entries(httpHeaders).forEach(([key, value]) => request.setRequestHeader(key, value));
|
|
50
50
|
request.responseType = "arraybuffer";
|
|
51
51
|
|
|
52
|
-
request.onload = function() {
|
|
53
|
-
context.decodeAudioData(request.response, function(buffer) {
|
|
52
|
+
request.onload = function () {
|
|
53
|
+
context.decodeAudioData(request.response, function (buffer) {
|
|
54
54
|
let source = context.createBufferSource();
|
|
55
55
|
source.buffer = buffer;
|
|
56
56
|
source.connect(context.destination);
|
|
57
57
|
// auto play
|
|
58
58
|
source.start(0); // start was previously noteOn
|
|
59
59
|
|
|
60
|
-
source.onended = function(event) {
|
|
60
|
+
source.onended = function (event) {
|
|
61
61
|
if (typeof onPlayed == 'function') {
|
|
62
62
|
onPlayed(event);
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ class AudioMedia {
|
|
|
66
66
|
};
|
|
67
67
|
request.send();
|
|
68
68
|
}
|
|
69
|
-
catch(e) {
|
|
69
|
+
catch (e) {
|
|
70
70
|
console.log(e);
|
|
71
71
|
console.log('web audio api not supported');
|
|
72
72
|
}
|
|
@@ -74,7 +74,93 @@ class AudioMedia {
|
|
|
74
74
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
//Source : https://www.npmjs.com/package/mic-check
|
|
78
|
+
class UserMedia {
|
|
79
|
+
/** SystemPermissionDenied => (macOS) browser does not have permission to access cam/mic */
|
|
80
|
+
/** UserPermissionDenied => user denied permission for site to access cam/mic */
|
|
81
|
+
/** CouldNotStartVideoSource = > (Windows) browser does not have permission to access cam/mic OR camera is in use by another application or browser tab */
|
|
82
|
+
/** Generic => all other errors */
|
|
83
|
+
|
|
84
|
+
static requestMediaPermissions(constraints) {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
let userAgent = navigator.userAgent;
|
|
87
|
+
let browser;
|
|
88
|
+
|
|
89
|
+
if (userAgent.match(/chrome|chromium|crios/i)) {
|
|
90
|
+
browser = "Chrome";
|
|
91
|
+
} else if (userAgent.match(/firefox|fxios/i)) {
|
|
92
|
+
browser = "firefox";
|
|
93
|
+
} else if (userAgent.match(/safari/i)) {
|
|
94
|
+
browser = "Safari";
|
|
95
|
+
} else if(userAgent.match(/opr\//i)) {
|
|
96
|
+
browser = "Opera";
|
|
97
|
+
} else if (userAgent.match(/edg/i)) {
|
|
98
|
+
browser = "Edge";
|
|
99
|
+
} else {
|
|
100
|
+
browser = "No browser detection";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
navigator.mediaDevices.getUserMedia(constraints !== 'undefined' ? constraints : { audio: true, video: true })
|
|
104
|
+
.then((stream) => {
|
|
105
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
106
|
+
resolve();
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
const errName = error.name;
|
|
109
|
+
const errMessage = error.message;
|
|
110
|
+
let errorType = "Generic";
|
|
111
|
+
|
|
112
|
+
if (browser === 'Chrome') {
|
|
113
|
+
if (errName === 'NotAllowedError') {
|
|
114
|
+
if (errMessage === 'Permission denied by system') {
|
|
115
|
+
errorType = "SystemPermissionDenied";
|
|
116
|
+
} else if (errMessage === 'Permission denied') {
|
|
117
|
+
errorType = "UserPermissionDenied";
|
|
118
|
+
}
|
|
119
|
+
} else if (errName === 'NotReadableError') {
|
|
120
|
+
errorType = "CouldNotStartVideoSource";
|
|
121
|
+
}
|
|
122
|
+
} else if (browser === 'Safari') {
|
|
123
|
+
if (errName === 'NotAllowedError') {
|
|
124
|
+
errorType = "UserPermissionDenied";
|
|
125
|
+
}
|
|
126
|
+
} else if (browser === 'Microsoft Edge') {
|
|
127
|
+
if (errName === 'NotAllowedError') {
|
|
128
|
+
errorType = "UserPermissionDenied";
|
|
129
|
+
} else if (errName === 'NotReadableError') {
|
|
130
|
+
errorType = "CouldNotStartVideoSource";
|
|
131
|
+
}
|
|
132
|
+
} else if (browser === 'Firefox') {
|
|
133
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#exceptions
|
|
134
|
+
if (errName === 'NotFoundError') {
|
|
135
|
+
errorType = "SystemPermissionDenied";
|
|
136
|
+
} else if (errName === 'NotReadableError') {
|
|
137
|
+
errorType = "SystemPermissionDenied";
|
|
138
|
+
} else if (errName === 'NotAllowedError') {
|
|
139
|
+
errorType = "UserPermissionDenied";
|
|
140
|
+
} else if (errName === 'AbortError') {
|
|
141
|
+
errorType = "CouldNotStartVideoSource";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
reject({ type: errorType, name: error.name, message: error.message });
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static requestAudioPermissions(audioConstraints) {
|
|
151
|
+
return this.requestMediaPermissions({ audio: (audioConstraints !== 'undefined' ? audioConstraints : true), video: false });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static requestVideoPermissions(audioConstraints, videoConstraints) {
|
|
155
|
+
return this.requestMediaPermissions({ audio: (audioConstraints !== 'undefined' ? audioConstraints : true), video: (videoConstraints !== 'undefined' ? videoConstraints : true )});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static requestMutedVideoPermissions(videoConstraints) {
|
|
159
|
+
return this.requestMediaPermissions({ audio: false, video: (videoConstraints !== 'undefined' ? videoConstraints : true )});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = { AudioMedia, UserMedia };
|
|
78
164
|
|
|
79
165
|
//deprecated
|
|
80
166
|
function hasGetUserMedia() {
|
package/package.json
CHANGED
package/.idea/helpers-js.iml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/helpers-js.iml" filepath="$PROJECT_DIR$/.idea/helpers-js.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|