webpeerjs 0.1.9 → 0.2.0
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/README.md +87 -46
- package/package.json +40 -50
- package/src/config.js +2 -13
- package/src/utils.js +2 -2
- package/src/{webpeerjs.js → webpeer.js} +274 -314
- package/dist/esm/package.json +0 -1
- package/dist/esm/webpeerjs.js +0 -83
- package/dist/umd/package.json +0 -1
- package/dist/umd/webpeerjs.js +0 -86
- package/src/umd.js +0 -4
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
# WebPEER
|
|
2
|
-
> Decentralized P2P JS library for communication between applications in browser.
|
|
1
|
+
# WebPEER
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
WebPEER is a P2P Network that Runs in a Standard Browser.
|
|
5
4
|
|
|
6
|
-
[
|
|
5
|
+
[>DEMO<](https://nuzulul.github.io/webpeerjs/demo/chat.html)
|
|
6
|
+
|
|
7
|
+

|
|
7
8
|
|
|
8
9
|
## Security
|
|
9
10
|
|
|
@@ -14,82 +15,122 @@ WebPEER Network run over [`libp2p gossipsub`](https://docs.libp2p.io/concepts/se
|
|
|
14
15
|
|
|
15
16
|
## Features
|
|
16
17
|
|
|
17
|
-
* ✅
|
|
18
|
+
* ✅ Distributed P2P
|
|
18
19
|
* ✅ Scalable Peers
|
|
19
20
|
* ✅ Works in Browsers
|
|
20
21
|
* ✅ Broadcast Messages
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
## Ideas
|
|
24
|
+
|
|
25
|
+
* Blockchain
|
|
26
|
+
* Voting / Polling
|
|
27
|
+
* Collaborative activity
|
|
28
|
+
* IoT
|
|
29
|
+
* Censorship resistent social media
|
|
30
|
+
* Remote control
|
|
31
|
+
* Multiplayer games
|
|
32
|
+
* Decentralized/distributed web
|
|
33
|
+
* Signalling protocol
|
|
34
|
+
* Location tracker
|
|
35
|
+
* User activity tracker.
|
|
36
|
+
|
|
37
|
+
## Try it out!
|
|
38
|
+
|
|
39
|
+
* Go to a deployed chat demo at : [https://nuzulul.github.io/webpeerjs/demo/chat.html](https://nuzulul.github.io/webpeerjs/demo/chat.html) .
|
|
40
|
+
* Open the app on another device.
|
|
41
|
+
* Both your devices should connected.
|
|
42
|
+
* Now start sending message.
|
|
22
43
|
|
|
23
44
|
## Browser Support
|
|
24
45
|
 |  |  |  |  |  |
|
|
25
46
|
--- | --- | --- | --- | --- | --- |
|
|
26
|
-
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest
|
|
47
|
+
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
|
|
27
48
|
|
|
28
49
|
## Quickstart
|
|
29
50
|
|
|
30
|
-
Try now in [Playground](https://jsbin.com/suwesaliro/1/edit?html,output) :
|
|
31
|
-
```
|
|
32
|
-
https://jsbin.com/suwesaliro/1/edit?html,output
|
|
33
|
-
```
|
|
34
|
-
|
|
35
51
|
NPM install:
|
|
36
52
|
|
|
37
53
|
```
|
|
38
|
-
npm
|
|
54
|
+
npm install webpeerjs
|
|
39
55
|
```
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
CDN :
|
|
42
58
|
|
|
43
|
-
|
|
59
|
+
* [https://esm.sh/webpeerjs](https://esm.sh/webpeerjs)
|
|
44
60
|
|
|
45
61
|
```
|
|
46
|
-
<script
|
|
62
|
+
<script type="importmap">
|
|
63
|
+
{
|
|
64
|
+
"imports": {
|
|
65
|
+
"webpeerjs" : "https://esm.sh/webpeerjs"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
47
69
|
```
|
|
48
70
|
|
|
49
71
|
## Example
|
|
50
72
|
|
|
51
73
|
```
|
|
52
|
-
import {
|
|
74
|
+
import { createWebPEER } from 'webpeerjs'
|
|
53
75
|
|
|
54
|
-
|
|
76
|
+
const config = {
|
|
77
|
+
networkName : 'myNetwork'
|
|
78
|
+
}
|
|
55
79
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
const peer = await createWebPEER();
|
|
81
|
+
|
|
82
|
+
console.log(`My peer id : ${peer.id}`)
|
|
83
|
+
|
|
84
|
+
const room = peer.joinRoom('lobbyroom')
|
|
85
|
+
|
|
86
|
+
room.onMessage((message,id) => {
|
|
87
|
+
console.log(`Message from ${id} : ${message}`)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
room.onMembersChange((data) => {
|
|
91
|
+
console.log(`Members : ${data}`)
|
|
92
|
+
room.sendMessage('hello')
|
|
93
|
+
})
|
|
70
94
|
|
|
71
|
-
}()
|
|
72
95
|
```
|
|
73
96
|
|
|
74
97
|
## API
|
|
75
98
|
|
|
76
|
-
|
|
77
|
-
- `config` - Configuration object contain:
|
|
78
|
-
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport, the only transport available for direct peer-to-peer connectivity between browser.
|
|
79
|
-
- `id` - The unique ID of the node as an identity in the global network.
|
|
80
|
-
- `status` - Get the node status, returns `connected` or `unconnected`.
|
|
81
|
-
- `peers` - Get all connected peers.
|
|
82
|
-
- `joinRoom(namespace)` - Join to the room, returns an array of three functions (Broadcaster, onListenBroadcast, onMembersUpdate).
|
|
99
|
+
### `peer = await createWebPEER(config)`
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
Create a new peer node.
|
|
85
102
|
|
|
86
|
-
|
|
103
|
+
`config` - Configuration object contains:
|
|
87
104
|
|
|
88
|
-
|
|
105
|
+
- `networkName` - Unique identifier of your network.
|
|
106
|
+
|
|
107
|
+
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport.
|
|
108
|
+
|
|
109
|
+
### `peer.id`
|
|
110
|
+
|
|
111
|
+
Get the unique ID of the node as an identity in the global network.
|
|
112
|
+
|
|
113
|
+
### `peer.status`
|
|
114
|
+
|
|
115
|
+
Get the node status, returns `connected` or `unconnected`.
|
|
89
116
|
|
|
90
|
-
|
|
117
|
+
### `peer.peers`
|
|
91
118
|
|
|
92
|
-
|
|
119
|
+
Get all connected peers.
|
|
120
|
+
|
|
121
|
+
### `room = peer.joinRoom(namespace)`
|
|
122
|
+
|
|
123
|
+
Join to the room, returns an object.
|
|
124
|
+
|
|
125
|
+
- `room.sendMessage()` - Function to broadcast message to room members.
|
|
126
|
+
- `romm.onMessage((message,id)=>{})` - Listen on incoming broadcast message.
|
|
127
|
+
- `room.onMembersChange((members)=>{})` - Listen on room members update.
|
|
128
|
+
|
|
129
|
+
## Related
|
|
130
|
+
|
|
131
|
+
- [p2p.js](https://github.com/nuzulul/p2p.js) - Alternative simple api WebRTC library with auto matchmaking without signaling server.
|
|
132
|
+
|
|
133
|
+
## License
|
|
93
134
|
|
|
94
|
-
[Nuzulul Zulkarnain](https://github.com/nuzulul)
|
|
135
|
+
[MIT (c) 2024](https://github.com/nuzulul/webpeerjs/blob/main/LICENSE) [Nuzulul Zulkarnain](https://github.com/nuzulul)
|
|
95
136
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeerjs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "P2P Network that Runs in a Standard Browser",
|
|
6
|
+
"main": "./src/webpeer.js",
|
|
7
|
+
"module": "./src/webpeer.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
|
-
"import": "./src/
|
|
10
|
-
"require": "./dist/umd/webpeerjs.js"
|
|
10
|
+
"import": "./src/webpeer.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
@@ -16,15 +16,6 @@
|
|
|
16
16
|
"LICENSE"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"start": "npm run dev",
|
|
20
|
-
"dev": "vite serve test",
|
|
21
|
-
"demo": "vite serve demo",
|
|
22
|
-
"eslint": "eslint -c ./config/eslint.config.mjs ./src",
|
|
23
|
-
"eslint:fix": "eslint -c ./config/eslint.config.mjs ./src --fix",
|
|
24
|
-
"removedir": "node -e \"var fs = require('fs'); try{process.argv.slice(1).map((fpath) => fs.rmdirSync(fpath, { recursive: true }))}catch(err){console.log(`Dist not found`)}; process.exit(0);\"",
|
|
25
|
-
"build-all": "tsc -p config/tsconfig-rollup.json && rollup -c temp/config/rollup.config.build.js && echo {\"type\": \"commonjs\"}>dist\\umd\\package.json && echo {\"type\": \"module\"}>dist\\esm\\package.json",
|
|
26
|
-
"build-types": "tsc -p config/tsconfig-esm.json",
|
|
27
|
-
"build": "npm run removedir dist temp && npm run build-all",
|
|
28
19
|
"test": "cd test && cd project && npm start"
|
|
29
20
|
},
|
|
30
21
|
"repository": {
|
|
@@ -33,17 +24,17 @@
|
|
|
33
24
|
},
|
|
34
25
|
"keywords": [
|
|
35
26
|
"webpeer",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
"p2p",
|
|
28
|
+
"p2p-network",
|
|
29
|
+
"webpeer-network",
|
|
39
30
|
"ipfs",
|
|
40
|
-
|
|
31
|
+
"libp2p",
|
|
41
32
|
"peer",
|
|
42
33
|
"peer-to-peer",
|
|
43
34
|
"decentralized",
|
|
44
35
|
"browser-to-browser",
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
"distributed",
|
|
37
|
+
"serverless"
|
|
47
38
|
],
|
|
48
39
|
"author": {
|
|
49
40
|
"name": "Nuzulul Zulkarnain",
|
|
@@ -55,34 +46,33 @@
|
|
|
55
46
|
},
|
|
56
47
|
"homepage": "https://github.com/nuzulul/webpeerjs#readme",
|
|
57
48
|
"dependencies": {
|
|
58
|
-
"@chainsafe/libp2p-
|
|
59
|
-
"@chainsafe/libp2p-
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@libp2p/
|
|
63
|
-
"@libp2p/
|
|
64
|
-
"@libp2p/identify": "^
|
|
65
|
-
"@libp2p/kad-dht": "^
|
|
66
|
-
"@libp2p/
|
|
67
|
-
"@libp2p/
|
|
68
|
-
"@libp2p/
|
|
69
|
-
"@libp2p/
|
|
70
|
-
"@libp2p/
|
|
71
|
-
"@libp2p/
|
|
72
|
-
"
|
|
73
|
-
"libp2p": "^
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"vite": "^5.2.11"
|
|
49
|
+
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
50
|
+
"@chainsafe/libp2p-yamux": "^8.0.1",
|
|
51
|
+
"@helia/delegated-routing-v1-http-api-client": "^8.0.1",
|
|
52
|
+
"@libp2p/circuit-relay-v2": "^4.2.7",
|
|
53
|
+
"@libp2p/dcutr": "^3.0.22",
|
|
54
|
+
"@libp2p/gossipsub": "^16.0.3",
|
|
55
|
+
"@libp2p/identify": "^4.1.8",
|
|
56
|
+
"@libp2p/kad-dht": "^16.3.3",
|
|
57
|
+
"@libp2p/logger": "^6.2.9",
|
|
58
|
+
"@libp2p/peer-id": "^6.0.11",
|
|
59
|
+
"@libp2p/ping": "^3.1.7",
|
|
60
|
+
"@libp2p/pubsub-peer-discovery": "^12.0.0",
|
|
61
|
+
"@libp2p/simple-metrics": "^2.0.17",
|
|
62
|
+
"@libp2p/webrtc": "^6.0.25",
|
|
63
|
+
"@libp2p/websockets": "^10.1.15",
|
|
64
|
+
"@libp2p/webtransport": "^6.0.30",
|
|
65
|
+
"@multiformats/multiaddr": "^13.0.3",
|
|
66
|
+
"datastore-idb": "^5.0.1",
|
|
67
|
+
"interface-datastore": "^10.0.1",
|
|
68
|
+
"it-length-prefixed": "^11.0.1",
|
|
69
|
+
"it-length-prefixed-stream": "^3.0.0",
|
|
70
|
+
"it-map": "^3.1.6",
|
|
71
|
+
"it-pipe": "^3.0.1",
|
|
72
|
+
"libp2p": "^3.3.4",
|
|
73
|
+
"multiformats": "^14.0.2",
|
|
74
|
+
"protons-runtime": "^7.0.0",
|
|
75
|
+
"signalingserver.js": "^0.0.6",
|
|
76
|
+
"uint8arrays": "^6.1.1"
|
|
87
77
|
}
|
|
88
78
|
}
|
package/src/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
2
2
|
|
|
3
|
-
const prefix = '
|
|
3
|
+
const prefix = 'webpeer.js'
|
|
4
4
|
export const CONFIG_PREFIX = prefix
|
|
5
5
|
export const CONFIG_PROTOCOL = '/'+prefix+'/1.0.0'
|
|
6
6
|
export const CONFIG_BLOCKSTORE_PATH = prefix+'-blockstore'
|
|
@@ -22,19 +22,8 @@ export const CONFIG_KNOWN_BOOTSTRAP_DNS = '_dnsaddr.bootstrap.libp2p.io'
|
|
|
22
22
|
export const CONFIG_JOIN_ROOM_VERSION = 1
|
|
23
23
|
export const CONFIG_TIMEOUT_DIAL_KNOWN_PEERS = 15000
|
|
24
24
|
export const CONFIG_RUN_ON_TRANSIENT_CONNECTION = false
|
|
25
|
-
export const CONFIG_WEBRTC_STUN_URLS = 'stun:stun.l.google.com:19302'
|
|
26
|
-
export const CONFIG_WEBRTC_STUN_URLS_BACKUP = 'stun:global.stun.twilio.com:3478'
|
|
27
|
-
export const CONFIG_WEBRTC_TURN_HOST = 'dHVybjp0dXJuMDEuYnJpZS5maTo1MzQ5'
|
|
28
|
-
export const CONFIG_WEBRTC_TURN_USER = 'YnJpZQ=='
|
|
29
|
-
export const CONFIG_WEBRTC_TURN_PWD = 'Zmk='
|
|
30
|
-
export const CONFIG_WEBRTC_TURN_HOST_BACKUP = 'dHVybjpyZWxheTEuZXhwcmVzc3R1cm4uY29tOjM0Nzg='
|
|
31
|
-
export const CONFIG_WEBRTC_TURN_USER_BACKUP = 'ZWZJSllZNjdDNElRMzFZQUlP'
|
|
32
|
-
export const CONFIG_WEBRTC_TURN_PWD_BACKUP = 'Vk01SmdhODlkYjJaWU9aSA=='
|
|
33
|
-
export const CONFIG_WEBRTC_TURN_HOST_BACKUP1 = 'dHVybjpzdGFuZGFyZC5yZWxheS5tZXRlcmVkLmNhOjgw'
|
|
34
|
-
export const CONFIG_WEBRTC_TURN_USER_BACKUP1 = 'ZmZlNmIxOThjOGMxYjM5ODg1OWFiOGY4'
|
|
35
|
-
export const CONFIG_WEBRTC_TURN_PWD_BACKUP1 = 'aWpkQjVTcTIwREVsZzdDRg=='
|
|
36
25
|
export const CONFIG_MESSAGE_SIZE_LIMIT = 100*1024 // 100KB
|
|
37
|
-
export const CONFIG_DEBUG_ENABLED =
|
|
26
|
+
export const CONFIG_DEBUG_ENABLED = true
|
|
38
27
|
export const CONFIG_AUTODIAL_MAX_ERROR_LIMIT = 45
|
|
39
28
|
export const CONFIG_DIAL_MAX_ERROR_LIMIT = 55
|
|
40
29
|
|
package/src/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! WebPEER.js -- https://github.com/nuzulul/webpeerjs
|
|
2
2
|
|
|
3
|
-
import * as config from './config'
|
|
4
|
-
import { Peer as PBPeer } from './peer'
|
|
3
|
+
import * as config from './config.js'
|
|
4
|
+
import { Peer as PBPeer } from './peer.js'
|
|
5
5
|
import { Key } from 'interface-datastore'
|
|
6
6
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
7
7
|
import { multiaddr } from '@multiformats/multiaddr'
|