@osimatic/helpers-js 1.0.35 → 1.0.38

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/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,6 +1,6 @@
1
1
 
2
2
  class HTTPRequest {
3
- static init(){
3
+ static init() {
4
4
  require('whatwg-fetch'); //fetch polyfill loaded in window.fetch
5
5
  }
6
6
 
@@ -12,18 +12,7 @@ class HTTPRequest {
12
12
  this.refreshTokenCallback = callback;
13
13
  }
14
14
 
15
- static setHeader(key, value) {
16
- if (typeof this.headers == 'undefined') {
17
- this.headers = {};
18
- }
19
- this.headers[key] = value;
20
- }
21
-
22
15
  static getHeaders(asObject) {
23
- //if (typeof httpHeaders != 'undefined') {
24
- // return httpHeaders;
25
- //}
26
-
27
16
  if (typeof this.headers == 'undefined') {
28
17
  this.headers = {};
29
18
  }
@@ -36,9 +25,34 @@ class HTTPRequest {
36
25
  Object.entries(this.headers).forEach(([key, value]) => {
37
26
  httpHeaders.append(key, value);
38
27
  });
28
+
39
29
  return httpHeaders;
40
30
  }
41
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
+
42
56
  static formatQueryString(data) {
43
57
  if (data == null) {
44
58
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.35",
3
+ "version": "1.0.38",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/web_rtc.js CHANGED
@@ -1,14 +1,17 @@
1
1
  class WebRTC {
2
- static init (turnSecret, turnUrl, stunUrl) {
3
- this.turnSecret = turnSecret;
2
+ static setIceServers(turnUrl, stunUrl) {
4
3
  this.turnUrl = turnUrl;
5
4
  this.stunUrl = stunUrl;
6
5
  }
7
6
 
7
+ static setTurnAccount(turnAccount) {
8
+ this.turnAccount = turnAccount;
9
+ }
10
+
8
11
  static offer(stream, onICECandidateCallback) {
9
12
  return new Promise((resolve, reject) => {
10
13
  try {
11
- let { username, password } = this.getTurnCredentials();
14
+ let { username, password } = this.turnAccount;
12
15
  let peerConn = new RTCPeerConnection(
13
16
  {
14
17
  iceServers: [
@@ -19,8 +22,11 @@ class WebRTC {
19
22
  );
20
23
 
21
24
  stream.getTracks().forEach(track => peerConn.addTrack(track, stream));
22
-
23
- peerConn.onicecandidate = (event) => onICECandidateCallback(event);
25
+ peerConn.onicecandidate = ((event) => {
26
+ if (event.candidate) {
27
+ onICECandidateCallback(event.candidate);
28
+ }
29
+ });
24
30
 
25
31
  peerConn.createOffer()
26
32
  .then(sdp => peerConn.setLocalDescription(sdp))
@@ -34,7 +40,7 @@ class WebRTC {
34
40
  static answer (remoteDescription, onTrackCallback, onICECandidateCallback) {
35
41
  return new Promise((resolve, reject) => {
36
42
  try {
37
- let { username, password } = this.getTurnCredentials();
43
+ let { username, password } = this.turnAcccount;
38
44
  let peerConn = new RTCPeerConnection(
39
45
  {
40
46
  iceServers: [
@@ -44,8 +50,13 @@ class WebRTC {
44
50
  }
45
51
  );
46
52
 
47
- peerConn.ontrack = event => onTrackCallback(event);
48
- peerConn.onicecandidate = event => onICECandidateCallback(event);
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
+ });
49
60
 
50
61
  peerConn.setRemoteDescription(remoteDescription)
51
62
  .then(() => peerConn.createAnswer())
@@ -72,32 +83,6 @@ class WebRTC {
72
83
 
73
84
  return peerConn;
74
85
  }
75
-
76
- /*
77
- The idea is that WebRTC (or other) clients receive temporary TURN credentials where the user name is comprised of the (Unix)
78
- expiry timestamp and the password is derived from a secret shared between the service generating those credentials and eturnal.
79
- The service offering the credentials performs a Base64(HMAC-SHA1($secret, $timestamp)) operation to generate the ephemeral password,
80
- and eturnal does the same to verify it.
81
-
82
- https://eturnal.net/documentation/
83
- https://datatracker.ietf.org/doc/html/draft-uberti-behave-turn-rest-00
84
- https://stackoverflow.com/questions/35766382/coturn-how-to-use-turn-rest-api
85
- */
86
- static getTurnCredentials() {
87
- try {
88
- let crypto = require('crypto');
89
- let username = String(parseInt(Date.now() / 1000) + 24 * 3600);
90
- let hmac = crypto.createHmac('sha1', this.turnSecret);
91
-
92
- hmac.setEncoding('base64');
93
- hmac.write(username);
94
- hmac.end();
95
-
96
- return { username: username, password: hmac.read() };
97
- } catch(error) {
98
- throw error;
99
- }
100
- }
101
86
  }
102
87
 
103
88
  module.exports = { WebRTC };