@osimatic/helpers-js 1.0.52 → 1.0.53
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/package.json +1 -1
- package/web_rtc.js +21 -4
package/package.json
CHANGED
package/web_rtc.js
CHANGED
|
@@ -4,14 +4,14 @@ class WebRTC {
|
|
|
4
4
|
this.stunUrl = stunUrl;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
static
|
|
8
|
-
this.
|
|
7
|
+
static setTurnSecret(turnSecret) {
|
|
8
|
+
this.turnSecret = turnSecret;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
static offer(stream, iceCandidateCallback) {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
try {
|
|
14
|
-
let { username, password } = this.
|
|
14
|
+
let { username, password } = this.getTurnCredentials();
|
|
15
15
|
let peerConn = new RTCPeerConnection(
|
|
16
16
|
{
|
|
17
17
|
iceServers: [
|
|
@@ -40,7 +40,7 @@ class WebRTC {
|
|
|
40
40
|
static answer (remoteDescription, onTrackCallback, iceCandidateCallback) {
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
try {
|
|
43
|
-
let { username, password } = this.
|
|
43
|
+
let { username, password } = this.getTurnCredentials();
|
|
44
44
|
let peerConn = new RTCPeerConnection(
|
|
45
45
|
{
|
|
46
46
|
iceServers: [
|
|
@@ -82,6 +82,23 @@ class WebRTC {
|
|
|
82
82
|
|
|
83
83
|
return peerConn;
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
static-auth credentials
|
|
88
|
+
https://eturnal.net/documentation/
|
|
89
|
+
https://datatracker.ietf.org/doc/html/draft-uberti-behave-turn-rest-00
|
|
90
|
+
*/
|
|
91
|
+
static getTurnCredentials() {
|
|
92
|
+
let crypto = require('crypto');
|
|
93
|
+
let username = String(parseInt(Date.now() / 1000) + 24 * 3600); //ttl: 24h
|
|
94
|
+
let hmac = crypto.createHmac('sha1', this.turnSecret);
|
|
95
|
+
|
|
96
|
+
hmac.setEncoding('base64');
|
|
97
|
+
hmac.write(username);
|
|
98
|
+
hmac.end();
|
|
99
|
+
|
|
100
|
+
return { username: username, password: hmac.read() };
|
|
101
|
+
}
|
|
85
102
|
}
|
|
86
103
|
|
|
87
104
|
module.exports = { WebRTC };
|