@yz-social/webrtc 0.1.6 → 0.1.7
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 +3 -3
- package/stun.js +0 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yz-social/webrtc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Streamlined portable webrtc management of p2p and client2server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webrtc",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"testServer": "node spec/portal.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@roamhq/wrtc": "^0.
|
|
26
|
+
"@roamhq/wrtc": "^0.10.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"express": "^5.2.1",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"registry": "https://registry.npmjs.org"
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
40
|
}
|
package/stun.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const wrtc = (typeof(process) === 'undefined') ? globalThis : (await import('#wrtc')).default;
|
|
2
|
-
|
|
3
|
-
// function getIPs(stunServer = 'stun:stun.l.google.com:19302') { // Promise external/WAN/public IP addresses for this device.
|
|
4
|
-
// // This is the equivalent of whatismyip.com and the like, but using the same stun protocol that
|
|
5
|
-
// // webrtc is using. Alas, the stun protocol itself is UDP and so cannot be fetched from a browser,
|
|
6
|
-
// // so we use WebRTC itself.
|
|
7
|
-
// return new Promise((resolve, reject) => {
|
|
8
|
-
// const addresses = [];
|
|
9
|
-
// const pc = new wrtc.RTCPeerConnection({ iceServers: [ {urls: stunServer} ] });
|
|
10
|
-
// const done = () => {
|
|
11
|
-
// console.log('done');
|
|
12
|
-
// pc.onicecandidateerror = pc.onicegatheringstatechange = pc.onicecandidate = null;
|
|
13
|
-
// pc.close();
|
|
14
|
-
// resolve(addresses);
|
|
15
|
-
// };
|
|
16
|
-
// pc.createDataChannel('');
|
|
17
|
-
// pc.createOffer()
|
|
18
|
-
// .then(offer => pc.setLocalDescription(offer))
|
|
19
|
-
// .catch(reject);
|
|
20
|
-
// pc.onicecandidateerror = e => reject(e);
|
|
21
|
-
// pc.onicegatheringstatechange = e => (pc.iceGatheringState === 'complete') && done();
|
|
22
|
-
// pc.onicecandidate = (ice) => {
|
|
23
|
-
// console.log(ice.candidate.type);
|
|
24
|
-
// if (!ice || !ice.candidate) return done();
|
|
25
|
-
// if (ice.candidate.type === 'host') return null;
|
|
26
|
-
// return addresses.push(ice.candidate.address);
|
|
27
|
-
// };
|
|
28
|
-
// });
|
|
29
|
-
// }
|
|
30
|
-
|
|
31
|
-
export function getPublicIP(stunServer = "stun:stun.l.google.com:19302") {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
const pc = new wrtc.RTCPeerConnection({iceServers: [{ urls: stunServer }] });
|
|
34
|
-
pc.createDataChannel("");
|
|
35
|
-
pc.onicecandidate = ({candidate}) => {
|
|
36
|
-
if (!candidate) return;
|
|
37
|
-
if (candidate.type !== "srflx") return;
|
|
38
|
-
resolve(candidate.address);
|
|
39
|
-
pc.onicecandidate = pc.onicecandidateerror = null;
|
|
40
|
-
pc.close();
|
|
41
|
-
};
|
|
42
|
-
pc.onicecandidateerror = reject;
|
|
43
|
-
pc.createOffer()
|
|
44
|
-
.then((offer) => pc.setLocalDescription(offer))
|
|
45
|
-
.catch(reject);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Usage
|
|
50
|
-
//await getPublicIP().then(ip => console.log("Public IP:", ip));
|
|
51
|
-
|
|
52
|
-
|