webpeerjs 0.1.10 → 0.2.1
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 +82 -52
- package/package.json +40 -50
- package/src/config.js +2 -13
- package/src/utils.js +2 -2
- package/src/{webpeerjs.js → webpeer.js} +329 -369
- 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,11 +1,10 @@
|
|
|
1
|
-
# WebPEER
|
|
2
|
-
> Decentralized P2P network overlay inside browser
|
|
1
|
+
# WebPEER.js
|
|
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)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+

|
|
9
8
|
|
|
10
9
|
## Security
|
|
11
10
|
|
|
@@ -16,85 +15,116 @@ WebPEER Network run over [`libp2p gossipsub`](https://docs.libp2p.io/concepts/se
|
|
|
16
15
|
|
|
17
16
|
## Features
|
|
18
17
|
|
|
19
|
-
* ✅
|
|
18
|
+
* ✅ Distributed P2P
|
|
20
19
|
* ✅ Scalable Peers
|
|
21
20
|
* ✅ Works in Browsers
|
|
22
21
|
* ✅ Broadcast Messages
|
|
23
|
-
|
|
22
|
+
|
|
23
|
+
## Ideas
|
|
24
|
+
|
|
25
|
+
* Blockchain
|
|
26
|
+
* Voting / Polling
|
|
27
|
+
* Collaborative activity
|
|
28
|
+
* IoT
|
|
29
|
+
* social media
|
|
30
|
+
* Remote control
|
|
31
|
+
* Multiplayer games
|
|
32
|
+
* Distributed web
|
|
33
|
+
* Signalling protocol
|
|
34
|
+
* Location tracker
|
|
35
|
+
* Activity tracker.
|
|
36
|
+
|
|
37
|
+
## Try it out!
|
|
38
|
+
|
|
39
|
+
* Go to a deployed chat demo at : [p2pchat](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.
|
|
24
43
|
|
|
25
44
|
## Browser Support
|
|
26
|
-

|
|
27
|
-
--- | --- | --- | --- | --- | --- |
|
|
28
|
-
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ❓ |
|
|
45
|
+
     
|
|
29
46
|
|
|
30
47
|
## Quickstart
|
|
31
48
|
|
|
32
|
-
Try now in [Playground](https://jsbin.com/suwesaliro/1/edit?html,output) :
|
|
33
|
-
```
|
|
34
|
-
https://jsbin.com/suwesaliro/1/edit?html,output
|
|
35
|
-
```
|
|
36
|
-
|
|
37
49
|
NPM install:
|
|
38
50
|
|
|
39
51
|
```
|
|
40
|
-
npm
|
|
52
|
+
npm install webpeerjs
|
|
41
53
|
```
|
|
42
54
|
|
|
43
|
-
|
|
55
|
+
CDN :
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
* [https://esm.sh/webpeerjs](https://esm.sh/webpeerjs)
|
|
46
58
|
|
|
47
59
|
```
|
|
48
|
-
<script
|
|
60
|
+
<script type="importmap">
|
|
61
|
+
{
|
|
62
|
+
"imports": {
|
|
63
|
+
"webpeerjs" : "https://esm.sh/webpeerjs"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
49
67
|
```
|
|
50
68
|
|
|
51
69
|
## Example
|
|
52
70
|
|
|
53
71
|
```
|
|
54
|
-
import {
|
|
72
|
+
import { createWebPEER } from 'webpeerjs'
|
|
55
73
|
|
|
56
|
-
|
|
74
|
+
const config = {
|
|
75
|
+
networkName : 'myNetwork'
|
|
76
|
+
}
|
|
57
77
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
const peer = await createWebPEER();
|
|
79
|
+
|
|
80
|
+
console.log(`My peer id : ${peer.id}`)
|
|
81
|
+
|
|
82
|
+
const room = peer.joinRoom('lobbyroom')
|
|
83
|
+
|
|
84
|
+
room.onMessage((message,id) => {
|
|
85
|
+
console.log(`Message from ${id} : ${message}`)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
room.onMembersChange((data) => {
|
|
89
|
+
console.log(`Members : ${data}`)
|
|
90
|
+
room.sendMessage('hello')
|
|
91
|
+
})
|
|
72
92
|
|
|
73
|
-
}()
|
|
74
93
|
```
|
|
75
94
|
|
|
76
95
|
## API
|
|
77
96
|
|
|
78
|
-
|
|
79
|
-
- `config` - Configuration object contain:
|
|
80
|
-
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport, currently the only transport available for direct peer-to-peer connectivity between browser.
|
|
81
|
-
- `id` - Get the unique ID of the node as an identity in the global network.
|
|
82
|
-
- `status` - Get the node status, returns `connected` or `unconnected`.
|
|
83
|
-
- `peers` - Get all connected peers.
|
|
84
|
-
- `joinRoom(namespace)` - Join to the room, returns an array of three functions (Broadcaster, onListenBroadcast, onMembersUpdate).
|
|
85
|
-
- `Broadcaster` - Function to broadcast message to room members (limited to 1 message/second).
|
|
86
|
-
- `onListenBroadcast` - Callback function that listen on incoming broadcast message.
|
|
87
|
-
- `onMembersUpdate` - Callback function that listen on room members update.
|
|
97
|
+
### `peer = await createWebPEER(config)`
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
Create a new peer node.
|
|
90
100
|
|
|
91
|
-
|
|
101
|
+
`config` - Configuration object contains:
|
|
92
102
|
|
|
93
|
-
|
|
103
|
+
- `networkName` - Unique identifier name of your network.
|
|
104
|
+
|
|
105
|
+
- `rtcConfiguration` - **(optional)** Custom [rtcConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection) for WebRTC transport.
|
|
106
|
+
|
|
107
|
+
### `peer.id`
|
|
108
|
+
|
|
109
|
+
Get the unique ID of the peer node.
|
|
110
|
+
|
|
111
|
+
### `peer.status`
|
|
94
112
|
|
|
95
|
-
|
|
113
|
+
Get the peer node status, returns `connected` or `disconnected`.
|
|
96
114
|
|
|
97
|
-
|
|
115
|
+
### `room = peer.joinRoom(namespace)`
|
|
116
|
+
|
|
117
|
+
Join to a room, returns an object.
|
|
118
|
+
|
|
119
|
+
- `room.sendMessage()` - Function to broadcast message to the room.
|
|
120
|
+
- `romm.onMessage((message,id)=>{})` - Listen on incoming broadcast message.
|
|
121
|
+
- `room.onMembersChange((members)=>{})` - Listen on the room members update.
|
|
122
|
+
|
|
123
|
+
## See Also
|
|
124
|
+
|
|
125
|
+
- [p2p.js](https://github.com/nuzulul/p2p.js) - Alternative simple api WebRTC library with auto matchmaking without signaling server.
|
|
126
|
+
|
|
127
|
+
## License
|
|
98
128
|
|
|
99
|
-
[Nuzulul Zulkarnain](https://github.com/nuzulul)
|
|
129
|
+
[MIT (c) 2024](https://github.com/nuzulul/webpeerjs/blob/main/LICENSE) [Nuzulul Zulkarnain](https://github.com/nuzulul)
|
|
100
130
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeerjs",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "WebPEER is 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'
|
|
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'
|