@osimatic/helpers-js 1.0.34 → 1.0.37

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.
@@ -42,4 +42,7 @@ FormHelper.logRequestFailure(status, exception) -> HTTPRequest.logJqueryRequestF
42
42
  Location.checkCoordinates(...) -> GeographicCoordinates.check(...) (car Location est déjà défini en javascript natif)
43
43
 
44
44
  FormHelper.getFormErrorTextBis(...) -> FormHelper.getFormErrorText(...)
45
- FormHelper.displayFormErrorsFromXhr(form, btnSubmit, xhr) -> FormHelper.displayFormErrors(form, btnSubmit, xhr.responseJSON)
45
+ FormHelper.displayFormErrorsFromXhr(form, btnSubmit, xhr) -> FormHelper.displayFormErrors(form, btnSubmit, xhr.responseJSON)
46
+
47
+ 1.0.35 :
48
+ ajout méthode HTTPRequest.init() (charge le polyfill de fetch)
package/index.js CHANGED
@@ -33,6 +33,7 @@ const { CountDown } = require('./count_down');
33
33
  const { ImportFromCsv } = require('./import_from_csv');
34
34
  const { JwtToken, JwtSession } = require('./jwt');
35
35
  const { ListBox } = require('./list_box');
36
+ const { WebRTC } = require('./web_rtc');
36
37
 
37
38
  // exports surcouche lib externe
38
39
  const { GoogleCharts } = require('./google_charts');
@@ -43,7 +44,7 @@ const { OpenStreetMap } = require('./open_street_map');
43
44
  module.exports = {
44
45
  Array, Object, Number, String,
45
46
  HTTPRequest, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, SocialNetwork,
46
- DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox,
47
+ DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ListBox, WebRTC,
47
48
  sleep, refresh, chr, ord, trim, empty,
48
49
  GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
49
50
  };
package/network.js CHANGED
@@ -1,24 +1,18 @@
1
1
 
2
2
  class HTTPRequest {
3
+ static init() {
4
+ require('whatwg-fetch'); //fetch polyfill loaded in window.fetch
5
+ }
6
+
3
7
  static setRefreshTokenUrl(url) {
4
8
  this.refreshTokenUrl = url;
5
9
  }
10
+
6
11
  static setRefreshTokenCallback(callback) {
7
12
  this.refreshTokenCallback = callback;
8
13
  }
9
14
 
10
- static setHeader(key, value) {
11
- if (typeof this.headers == 'undefined') {
12
- this.headers = {};
13
- }
14
- this.headers[key] = value;
15
- }
16
-
17
15
  static getHeaders(asObject) {
18
- //if (typeof httpHeaders != 'undefined') {
19
- // return httpHeaders;
20
- //}
21
-
22
16
  if (typeof this.headers == 'undefined') {
23
17
  this.headers = {};
24
18
  }
@@ -31,9 +25,34 @@ class HTTPRequest {
31
25
  Object.entries(this.headers).forEach(([key, value]) => {
32
26
  httpHeaders.append(key, value);
33
27
  });
28
+
34
29
  return httpHeaders;
35
30
  }
36
31
 
32
+ static getHeader(key) {
33
+ if (typeof this.headers == 'undefined') {
34
+ this.headers = {};
35
+ }
36
+
37
+ return this.headers[key];
38
+ }
39
+
40
+ static setHeader(key, value) {
41
+ if (typeof this.headers == 'undefined') {
42
+ this.headers = {};
43
+ }
44
+
45
+ this.headers[key] = value;
46
+ }
47
+
48
+ static setAuthorizationHeader(accessToken) {
49
+ if (typeof this.headers == 'undefined') {
50
+ this.headers = {};
51
+ }
52
+
53
+ this.headers['Authorization'] = 'Bearer ' + accessToken;
54
+ }
55
+
37
56
  static formatQueryString(data) {
38
57
  if (data == null) {
39
58
  return '';
@@ -107,8 +126,7 @@ class HTTPRequest {
107
126
  return;
108
127
  }
109
128
 
110
- //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé
111
- console.error('fetch\'s polyfill used');
129
+ //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé dans la méthode init
112
130
  $.ajax({
113
131
  type: 'GET',
114
132
  url: url,
@@ -188,9 +206,7 @@ class HTTPRequest {
188
206
  return;
189
207
  }
190
208
 
191
- //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé
192
- console.error('fetch\'s polyfill used');
193
-
209
+ //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé dans la méthode init
194
210
  let ajaxOptions = {
195
211
  type: 'GET',
196
212
  url: url,
@@ -279,8 +295,7 @@ class HTTPRequest {
279
295
  return;
280
296
  }
281
297
 
282
- //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé
283
- console.error('fetch\'s polyfill used');
298
+ //l'api fetch n'est pas dispo pour ce navigateur => normalement ce cas ne devrait pas arriver car le polyfill est chargé dans la méthode init
284
299
  $.ajax({
285
300
  type: 'POST',
286
301
  url: url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.34",
3
+ "version": "1.0.37",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/web_rtc.js ADDED
@@ -0,0 +1,88 @@
1
+ class WebRTC {
2
+ static setIceServers(turnUrl, turnUrl) {
3
+ this.turnUrl = turnUrl;
4
+ this.stunUrl = turnUrl;
5
+ }
6
+
7
+ static setTurnAccount(turnAccount) {
8
+ this.turnAccount = turnAccount;
9
+ }
10
+
11
+ static offer(stream, onICECandidateCallback) {
12
+ return new Promise((resolve, reject) => {
13
+ try {
14
+ let { username, password } = this.turnAccount;
15
+ let peerConn = new RTCPeerConnection(
16
+ {
17
+ iceServers: [
18
+ { urls: this.turnUrl, username: username, credential: password },
19
+ { urls: this.stunUrl }
20
+ ]
21
+ }
22
+ );
23
+
24
+ stream.getTracks().forEach(track => peerConn.addTrack(track, stream));
25
+ peerConn.onicecandidate = ((event) => {
26
+ if (event.candidate) {
27
+ onICECandidateCallback(event.candidate);
28
+ }
29
+ });
30
+
31
+ peerConn.createOffer()
32
+ .then(sdp => peerConn.setLocalDescription(sdp))
33
+ .then(() => resolve(peerConn));
34
+ } catch (error) {
35
+ reject(error);
36
+ }
37
+ });
38
+ }
39
+
40
+ static answer (remoteDescription, onTrackCallback, onICECandidateCallback) {
41
+ return new Promise((resolve, reject) => {
42
+ try {
43
+ let { username, password } = this.turnAcccount;
44
+ let peerConn = new RTCPeerConnection(
45
+ {
46
+ iceServers: [
47
+ { urls: this.turnUrl, username: username, credential: password },
48
+ { urls: this.stunUrl }
49
+ ]
50
+ }
51
+ );
52
+
53
+ //todo test si streams n'est pas vide ?
54
+ peerConn.ontrack = event => onTrackCallback(event.streams);
55
+ peerConn.onicecandidate = ((event) => {
56
+ if (event.candidate) {
57
+ onICECandidateCallback(event.candidate);
58
+ }
59
+ });
60
+
61
+ peerConn.setRemoteDescription(remoteDescription)
62
+ .then(() => peerConn.createAnswer())
63
+ .then(sdp => peerConn.setLocalDescription(sdp))
64
+ .then(() => resolve(peerConn));
65
+ } catch (error) {
66
+ reject(error);
67
+ }
68
+ });
69
+ }
70
+
71
+ static disconnectPeer(peerConn) {
72
+ if (peerConn) {
73
+ peerConn.onicecandidate = null;
74
+ peerConn.ontrack = null;
75
+
76
+ if (peerConn.signalingState != 'closed') {
77
+ peerConn.getSenders().forEach(sender => peerConn.removeTrack(sender));
78
+ peerConn.close();
79
+ }
80
+
81
+ peerConn = null;
82
+ }
83
+
84
+ return peerConn;
85
+ }
86
+ }
87
+
88
+ module.exports = { WebRTC };
@@ -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>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>