@osimatic/helpers-js 1.0.36 → 1.0.39
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 +2 -1
- package/package.json +1 -1
- package/web_rtc.js +11 -36
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/package.json
CHANGED
package/web_rtc.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
class WebRTC {
|
|
2
|
-
static
|
|
3
|
-
this.turnSecret = turnSecret;
|
|
2
|
+
static setIceServers(turnUrl, stunUrl) {
|
|
4
3
|
this.turnUrl = turnUrl;
|
|
5
4
|
this.stunUrl = stunUrl;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
static
|
|
7
|
+
static setTurnAccount(turnAccount) {
|
|
8
|
+
this.turnAccount = turnAccount;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static offer(stream) {
|
|
9
12
|
return new Promise((resolve, reject) => {
|
|
10
13
|
try {
|
|
11
|
-
let { username, password } = this.
|
|
14
|
+
let { username, password } = this.turnAccount;
|
|
12
15
|
let peerConn = new RTCPeerConnection(
|
|
13
16
|
{
|
|
14
17
|
iceServers: [
|
|
@@ -19,8 +22,6 @@ class WebRTC {
|
|
|
19
22
|
);
|
|
20
23
|
|
|
21
24
|
stream.getTracks().forEach(track => peerConn.addTrack(track, stream));
|
|
22
|
-
|
|
23
|
-
peerConn.onicecandidate = (event) => onICECandidateCallback(event);
|
|
24
25
|
|
|
25
26
|
peerConn.createOffer()
|
|
26
27
|
.then(sdp => peerConn.setLocalDescription(sdp))
|
|
@@ -31,10 +32,10 @@ class WebRTC {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
static answer (remoteDescription, onTrackCallback
|
|
35
|
+
static answer (remoteDescription, onTrackCallback) {
|
|
35
36
|
return new Promise((resolve, reject) => {
|
|
36
37
|
try {
|
|
37
|
-
let { username, password } = this.
|
|
38
|
+
let { username, password } = this.turnAcccount;
|
|
38
39
|
let peerConn = new RTCPeerConnection(
|
|
39
40
|
{
|
|
40
41
|
iceServers: [
|
|
@@ -44,8 +45,8 @@ class WebRTC {
|
|
|
44
45
|
}
|
|
45
46
|
);
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
peerConn.
|
|
48
|
+
//todo test si streams n'est pas vide ?
|
|
49
|
+
peerConn.ontrack = event => onTrackCallback(event.streams);
|
|
49
50
|
|
|
50
51
|
peerConn.setRemoteDescription(remoteDescription)
|
|
51
52
|
.then(() => peerConn.createAnswer())
|
|
@@ -72,32 +73,6 @@ class WebRTC {
|
|
|
72
73
|
|
|
73
74
|
return peerConn;
|
|
74
75
|
}
|
|
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
76
|
}
|
|
102
77
|
|
|
103
78
|
module.exports = { WebRTC };
|