@osimatic/helpers-js 1.0.57 → 1.0.60

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.
@@ -0,0 +1,8 @@
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>
@@ -0,0 +1,8 @@
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 ADDED
@@ -0,0 +1,6 @@
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>
package/network.js CHANGED
@@ -53,6 +53,48 @@ class HTTPRequest {
53
53
  this.headers['Authorization'] = 'Bearer ' + accessToken;
54
54
  }
55
55
 
56
+ static convertObjectToFormData(obj) {
57
+ // 30/05/2022 : ancienne version, qui ne fonctionne pas avec des tableaux
58
+ // let formData = new FormData();
59
+ // Object.entries(data).forEach(([key, value]) => formData.append(key, value));
60
+ // return formData;
61
+
62
+ var formData = new FormData();
63
+
64
+ function appendFormData(data, root) {
65
+ //console.log('appendFormData', data, root);
66
+ root = root || '';
67
+ if (data instanceof File) {
68
+ formData.append(root, data);
69
+ }
70
+ else if (Array.isArray(data)) {
71
+ for (var i = 0; i < data.length; i++) {
72
+ appendFormData(data[i], root + '[' + i + ']');
73
+ }
74
+ }
75
+ else if (typeof data === 'object' && data) {
76
+ for (var key in data) {
77
+ if (data.hasOwnProperty(key)) {
78
+ if (root === '') {
79
+ appendFormData(data[key], key);
80
+ } else {
81
+ appendFormData(data[key], root + '.' + key);
82
+ }
83
+ }
84
+ }
85
+ }
86
+ else {
87
+ if (data !== null && typeof data !== 'undefined') {
88
+ formData.append(root, data);
89
+ }
90
+ }
91
+ }
92
+
93
+ appendFormData(obj);
94
+
95
+ return formData;
96
+ }
97
+
56
98
  static formatQueryString(data) {
57
99
  if (data == null) {
58
100
  return '';
@@ -68,9 +110,7 @@ class HTTPRequest {
68
110
 
69
111
  static formatFormData(data) {
70
112
  if (!(data instanceof FormData)) {
71
- let formData = new FormData();
72
- Object.entries(data).forEach(([key, value]) => formData.append(key, value));
73
- return formData;
113
+ return HTTPRequest.convertObjectToFormData(data);
74
114
  }
75
115
  return data;
76
116
  }
@@ -580,13 +620,18 @@ class UrlAndQueryString {
580
620
  if (typeof (object) == 'object') {
581
621
  for (var name in object) {
582
622
  value = object[name];
623
+ // 06/06/2022 : ajout de ce if pour éviter bug sur fonction HTTPRequest.formatQueryString
624
+ if (typeof (value) == 'undefined') {
625
+ continue;
626
+ }
583
627
  // 14/01/2020 : les tableaux avec param[0], param[1] en query string fonctionne pas, il faut mettre param[]=x&param[]=y
584
628
  //name = p == '' ? name : '['+name+']';
585
629
  name = p == '' ? name : '[]';
586
630
  if (typeof (value) == 'object') {
587
631
  buildStringFromParam(value, p + name);
588
632
  }
589
- else if (typeof (value) != 'function' && name != '') {
633
+ // 06/06/2022 : ajout null !== value pour éviter bug sur fonction HTTPRequest.formatQueryString
634
+ else if (null !== value && typeof (value) != 'function' && name != '') {
590
635
  // 27/01/2020 : correction bug boolean affiché en string true/false
591
636
  if (typeof (value) == 'boolean') {
592
637
  value = (value ? 1 : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.57",
3
+ "version": "1.0.60",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/web_rtc.js CHANGED
@@ -8,7 +8,7 @@ class WebRTC {
8
8
  this.turnSecret = turnSecret;
9
9
  }
10
10
 
11
- static offer(stream, iceCandidateCallback, connectionStateChangeCallback, iceFailureCallback) {
11
+ static offer(stream, iceCandidateCallback) {
12
12
  return new Promise(async (resolve, reject) => {
13
13
  try {
14
14
  let { username, password } = this.getTurnCredentials();
@@ -25,16 +25,12 @@ class WebRTC {
25
25
  }
26
26
  );
27
27
 
28
- peerConn.oniceconnectionstatechange = (event) => connectionStateChangeCallback(event);
29
-
30
28
  peerConn.onicecandidate = ((event) => {
31
29
  if (event.candidate) {
32
30
  iceCandidateCallback(event.candidate);
33
31
  }
34
32
  });
35
33
 
36
- peerConn.onicecandidateerror = (event) => iceFailureCallback(event);
37
-
38
34
  stream.getTracks().forEach(track => peerConn.addTrack(track, stream));
39
35
 
40
36
  const offer = await peerConn.createOffer();
@@ -47,7 +43,7 @@ class WebRTC {
47
43
  });
48
44
  }
49
45
 
50
- static answer(remoteDescription, onTrackCallback, iceCandidateCallback, connectionStateChangeCallback, iceFailureCallback) {
46
+ static answer(remoteDescription, onTrackCallback, iceCandidateCallback) {
51
47
  return new Promise(async (resolve, reject) => {
52
48
  try {
53
49
  let { username, password } = this.getTurnCredentials();
@@ -64,16 +60,12 @@ class WebRTC {
64
60
  }
65
61
  );
66
62
 
67
- peerConn.oniceconnectionstatechange = (event) => connectionStateChangeCallback(event);
68
-
69
63
  peerConn.onicecandidate = ((event) => {
70
64
  if (event.candidate) {
71
65
  iceCandidateCallback(event.candidate);
72
66
  }
73
67
  });
74
68
 
75
- peerConn.onicecandidateerror = (event) => iceFailureCallback(event);
76
-
77
69
  peerConn.ontrack = (event) => onTrackCallback(event.streams);
78
70
 
79
71
  peerConn.setRemoteDescription(new RTCSessionDescription(remoteDescription))