@osimatic/helpers-js 1.0.28 → 1.0.31
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/details_sub_array.js +1 -1
- package/file.js +1 -1
- package/flash_message.js +0 -1
- package/location.js +21 -4
- package/media.js +43 -0
- package/network.js +54 -28
- package/package.json +1 -1
package/details_sub_array.js
CHANGED
package/file.js
CHANGED
package/flash_message.js
CHANGED
|
@@ -33,7 +33,6 @@ class FlashMessage {
|
|
|
33
33
|
console.log('request failure. Status: ', status, ' Exception: ', exception);
|
|
34
34
|
this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
module.exports = { FlashMessage };
|
package/location.js
CHANGED
|
@@ -8,19 +8,19 @@ class Country {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
static fillCountrySelect(select, defaultValue) {
|
|
11
|
-
Object.entries(Country.
|
|
11
|
+
Object.entries(Country.getCountries()).forEach(([countryCode, countryName]) => select.append('<option value="'+countryCode+'">'+countryName+'</option>'));
|
|
12
12
|
if (typeof defaultValue != 'undefined') {
|
|
13
13
|
select.val(defaultValue);
|
|
14
14
|
}
|
|
15
15
|
select.selectpicker('refresh');
|
|
16
16
|
}
|
|
17
17
|
static getCountryName(countryCode) {
|
|
18
|
-
if (Country.
|
|
19
|
-
return Country.
|
|
18
|
+
if (Country.getCountries().hasOwnProperty(countryCode)) {
|
|
19
|
+
return Country.getCountries()[countryCode];
|
|
20
20
|
}
|
|
21
21
|
return countryCode;
|
|
22
22
|
}
|
|
23
|
-
static
|
|
23
|
+
static getCountries() {
|
|
24
24
|
return {
|
|
25
25
|
AF:'Afghanistan',
|
|
26
26
|
AX:'Åland Islands',
|
|
@@ -268,6 +268,23 @@ class Country {
|
|
|
268
268
|
ZW:'Zimbabwe',
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
+
|
|
272
|
+
static getContinents() {
|
|
273
|
+
return {
|
|
274
|
+
1: "Europe",
|
|
275
|
+
2: "Moyen-Orient",
|
|
276
|
+
3: "Afrique",
|
|
277
|
+
4: "Amérique du Nord",
|
|
278
|
+
5: "Amérique du Sud",
|
|
279
|
+
6: "Asie",
|
|
280
|
+
7: "Océanie",
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** @deprecated **/
|
|
285
|
+
static getCountryList() {
|
|
286
|
+
return Country.getCountries();
|
|
287
|
+
}
|
|
271
288
|
}
|
|
272
289
|
|
|
273
290
|
class PostalAddress {
|
package/media.js
CHANGED
|
@@ -72,6 +72,49 @@ class AudioMedia {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
static initAudioVisualization(canvas, audioStream) {
|
|
76
|
+
let canvasCtx = canvas.getContext("2d");
|
|
77
|
+
let canvasWidth = canvas.width;
|
|
78
|
+
let canvasHeight = canvas.height;
|
|
79
|
+
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
|
80
|
+
let analyser = audioCtx.createAnalyser();
|
|
81
|
+
|
|
82
|
+
let distortion = audioCtx.createWaveShaper();
|
|
83
|
+
let source = audioCtx.createMediaStreamSource(audioStream);
|
|
84
|
+
source.connect(analyser);
|
|
85
|
+
analyser.connect(distortion);
|
|
86
|
+
distortion.connect(audioCtx.destination);
|
|
87
|
+
|
|
88
|
+
analyser.fftSize = 256;
|
|
89
|
+
let bufferLength = analyser.frequencyBinCount;
|
|
90
|
+
console.log(bufferLength);
|
|
91
|
+
let dataArray = new Uint8Array(bufferLength);
|
|
92
|
+
|
|
93
|
+
canvasCtx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
94
|
+
|
|
95
|
+
function draw() {
|
|
96
|
+
let drawVisual = requestAnimationFrame(draw);
|
|
97
|
+
|
|
98
|
+
analyser.getByteFrequencyData(dataArray);
|
|
99
|
+
|
|
100
|
+
canvasCtx.fillStyle = 'rgb(0, 0, 0)';
|
|
101
|
+
canvasCtx.fillRect(0, 0, canvasWidth, canvasHeight);
|
|
102
|
+
|
|
103
|
+
let barWidth = (canvasWidth / bufferLength) * 2.5;
|
|
104
|
+
let barHeight;
|
|
105
|
+
let x = 0;
|
|
106
|
+
for (let i = 0; i < bufferLength; i++) {
|
|
107
|
+
barHeight = dataArray[i] / 2;
|
|
108
|
+
|
|
109
|
+
canvasCtx.fillStyle = 'rgb(' + (barHeight + 100) + ',50,50)';
|
|
110
|
+
canvasCtx.fillRect(x, canvasHeight - barHeight / 2, barWidth, barHeight);
|
|
111
|
+
|
|
112
|
+
x += barWidth + 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
draw();
|
|
117
|
+
}
|
|
75
118
|
}
|
|
76
119
|
|
|
77
120
|
//Source : https://www.npmjs.com/package/mic-check
|
package/network.js
CHANGED
|
@@ -43,6 +43,15 @@ class HTTPRequest {
|
|
|
43
43
|
return data;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
static formatFormData(data) {
|
|
47
|
+
if (!(data instanceof FormData)) {
|
|
48
|
+
let formData = new FormData();
|
|
49
|
+
Object.entries(data).forEach(([key, value]) => formData.append(key, value));
|
|
50
|
+
return formData;
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
static logRequestFailure(response, json) {
|
|
47
56
|
console.error('Request failure. Status: '+response.statusText+' ; HTTP Code : '+response.status, json);
|
|
48
57
|
}
|
|
@@ -52,18 +61,18 @@ class HTTPRequest {
|
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
static async get(url, data, successCallback, errorCallback) {
|
|
55
|
-
|
|
64
|
+
url += (!url.includes('?') ? '?' : '') + this.formatQueryString(data);
|
|
65
|
+
data = null;
|
|
56
66
|
|
|
57
67
|
if (window.fetch) {
|
|
58
|
-
|
|
68
|
+
const response = await fetch(url, {
|
|
59
69
|
method: 'GET',
|
|
60
70
|
headers: HTTPRequest.getHeaders(),
|
|
61
71
|
mode: 'cors',
|
|
62
72
|
cache: 'no-cache'
|
|
63
|
-
}
|
|
73
|
+
});
|
|
64
74
|
|
|
65
75
|
let jsonData = {};
|
|
66
|
-
const response = await fetch(url + (!url.includes('?') ? '?' : '') + data, requestInit);
|
|
67
76
|
try {
|
|
68
77
|
jsonData = await response.json();
|
|
69
78
|
//console.log(url, jsonData);
|
|
@@ -98,7 +107,7 @@ class HTTPRequest {
|
|
|
98
107
|
console.error('fetch\'s polyfill used');
|
|
99
108
|
$.ajax({
|
|
100
109
|
type: 'GET',
|
|
101
|
-
url: url
|
|
110
|
+
url: url,
|
|
102
111
|
headers: HTTPRequest.getHeaders(),
|
|
103
112
|
dataType: 'json',
|
|
104
113
|
cache: false,
|
|
@@ -117,8 +126,13 @@ class HTTPRequest {
|
|
|
117
126
|
});
|
|
118
127
|
}
|
|
119
128
|
|
|
120
|
-
static async download(url, data, errorCallback, completeCallback) {
|
|
121
|
-
|
|
129
|
+
static async download(url, data, errorCallback, completeCallback, method) {
|
|
130
|
+
method = typeof method == 'undefined' || null == method ? 'GET' : method;
|
|
131
|
+
|
|
132
|
+
if ('POST' !== method) {
|
|
133
|
+
url += (!url.includes('?') ? '?' : '') + this.formatQueryString(data);
|
|
134
|
+
data = null;
|
|
135
|
+
}
|
|
122
136
|
|
|
123
137
|
if (window.fetch) {
|
|
124
138
|
let requestInit = {
|
|
@@ -128,14 +142,19 @@ class HTTPRequest {
|
|
|
128
142
|
cache: 'no-cache'
|
|
129
143
|
}
|
|
130
144
|
|
|
131
|
-
|
|
145
|
+
if ('POST' === method) {
|
|
146
|
+
requestInit['method'] = 'POST';
|
|
147
|
+
requestInit['body'] = this.formatFormData(data);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const response = await fetch(url, requestInit);
|
|
132
151
|
try {
|
|
133
152
|
const blobData = await response.blob();
|
|
134
153
|
/*console.log(url);
|
|
135
154
|
console.log(blobData);*/
|
|
136
155
|
|
|
137
156
|
if (response.status == 401 && response.statusText === "Expired JWT Token") {
|
|
138
|
-
HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback));
|
|
157
|
+
HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method));
|
|
139
158
|
return;
|
|
140
159
|
}
|
|
141
160
|
|
|
@@ -163,18 +182,29 @@ class HTTPRequest {
|
|
|
163
182
|
|
|
164
183
|
//l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé
|
|
165
184
|
console.error('fetch\'s polyfill used');
|
|
166
|
-
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
let ajaxOptions = {
|
|
167
188
|
type: 'GET',
|
|
168
|
-
url: url
|
|
189
|
+
url: url,
|
|
169
190
|
headers: HTTPRequest.getHeaders(),
|
|
170
191
|
cache: false,
|
|
171
192
|
xhrFields: {
|
|
172
193
|
responseType: 'blob'
|
|
173
194
|
},
|
|
195
|
+
};
|
|
196
|
+
if ('POST' === method) {
|
|
197
|
+
ajaxOptions['type'] = 'POST';
|
|
198
|
+
ajaxOptions['data'] = this.formatFormData(data);
|
|
199
|
+
ajaxOptions['contentType'] = false;
|
|
200
|
+
ajaxOptions['processData'] = false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
$.ajax(Object.assign({...ajaxOptions}, {
|
|
174
204
|
success: (data, status, jqxhr) => File.download(data, jqxhr.getResponseHeader('Content-Type'), jqxhr.getResponseHeader('Content-Disposition')),
|
|
175
205
|
error: (jqxhr, status, errorThrown) => {
|
|
176
206
|
if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
|
|
177
|
-
HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback));
|
|
207
|
+
HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method));
|
|
178
208
|
return;
|
|
179
209
|
}
|
|
180
210
|
|
|
@@ -188,33 +218,27 @@ class HTTPRequest {
|
|
|
188
218
|
completeCallback(jqxhr, status);
|
|
189
219
|
}
|
|
190
220
|
}
|
|
191
|
-
});
|
|
221
|
+
}));
|
|
192
222
|
}
|
|
193
223
|
|
|
194
224
|
static async post(url, formData, successCallback, errorCallback, formErrorCallback) {
|
|
195
|
-
|
|
196
|
-
let formDataObject = new FormData();
|
|
197
|
-
Object.entries(formData).forEach(([key, value]) => formDataObject.append(key, value));
|
|
198
|
-
formData = formDataObject;
|
|
199
|
-
}
|
|
225
|
+
formData = this.formatFormData(formData);
|
|
200
226
|
|
|
201
227
|
if (window.fetch && false) {
|
|
202
|
-
|
|
228
|
+
const response = await fetch(url, {
|
|
203
229
|
method: 'POST',
|
|
204
230
|
body: formData,
|
|
205
231
|
headers: HTTPRequest.getHeaders(),
|
|
206
232
|
mode: 'cors',
|
|
207
233
|
cache: 'no-cache'
|
|
208
|
-
};
|
|
234
|
+
});
|
|
209
235
|
|
|
210
236
|
let jsonData = {};
|
|
211
|
-
const response = await fetch(url, requestInit);
|
|
212
|
-
|
|
213
237
|
try {
|
|
214
238
|
jsonData = await response.json();
|
|
215
239
|
//console.log(url, jsonData);
|
|
216
240
|
|
|
217
|
-
if (response.status == 401 && (response.statusText === "Expired JWT Token" || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
|
|
241
|
+
if (response.status == 401 && url !== HTTPRequest.refreshTokenUrl && (response.statusText === "Expired JWT Token" || (typeof jsonData['error'] != 'undefined' && jsonData['error'] === 'expired_token'))) {
|
|
218
242
|
HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
|
|
219
243
|
return;
|
|
220
244
|
}
|
|
@@ -263,7 +287,7 @@ class HTTPRequest {
|
|
|
263
287
|
}
|
|
264
288
|
},
|
|
265
289
|
error: (jqxhr, status, errorThrown) => {
|
|
266
|
-
if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
|
|
290
|
+
if (typeof jqxhr.responseJSON != 'undefined' && jqxhr.responseJSON.code == 401 && url !== HTTPRequest.refreshTokenUrl && (jqxhr.responseJSON.message === "Expired JWT Token" || (typeof jqxhr.responseJSON['error'] != 'undefined' && jqxhr.responseJSON['error'] === 'expired_token' ))) {
|
|
267
291
|
HTTPRequest.refreshToken(() => HTTPRequest.post(url, formData, successCallback, errorCallback, formErrorCallback));
|
|
268
292
|
return;
|
|
269
293
|
}
|
|
@@ -300,8 +324,7 @@ class HTTPRequest {
|
|
|
300
324
|
JwtSession.setRefreshToken(data.refresh_token);
|
|
301
325
|
onCompleteCallback();
|
|
302
326
|
},
|
|
303
|
-
(
|
|
304
|
-
console.log(exception);
|
|
327
|
+
() => {
|
|
305
328
|
JwtSession.logout();
|
|
306
329
|
}
|
|
307
330
|
);
|
|
@@ -327,11 +350,12 @@ class HTTPRequest {
|
|
|
327
350
|
|
|
328
351
|
xhr.onreadystatechange = function () {
|
|
329
352
|
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
|
|
353
|
+
let data;
|
|
330
354
|
if (formatRetour == 'xml') {
|
|
331
|
-
|
|
355
|
+
data = xhr.responseXML;
|
|
332
356
|
}
|
|
333
357
|
else {
|
|
334
|
-
|
|
358
|
+
data = eval('(' + xhr.responseText + ')');
|
|
335
359
|
}
|
|
336
360
|
callback(data);
|
|
337
361
|
}
|
|
@@ -573,6 +597,7 @@ class UrlAndQueryString {
|
|
|
573
597
|
|
|
574
598
|
// deprecated
|
|
575
599
|
|
|
600
|
+
/** @deprecated **/
|
|
576
601
|
static parseQueryString(string) {
|
|
577
602
|
if (string === "" || string == null) return {};
|
|
578
603
|
if (string.charAt(0) === "?") string = string.slice(1);
|
|
@@ -612,6 +637,7 @@ class UrlAndQueryString {
|
|
|
612
637
|
return data0;
|
|
613
638
|
}
|
|
614
639
|
|
|
640
|
+
/** @deprecated **/
|
|
615
641
|
static getQuery(url) {
|
|
616
642
|
var str = url;
|
|
617
643
|
var strpos = str.indexOf('?');
|