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 CHANGED
@@ -1,11 +1,10 @@
1
- # WebPEER
2
- > Decentralized P2P network overlay inside browser
1
+ # WebPEER.js
3
2
 
4
- [WebPEER.js](https://github.com/nuzulul/webpeerjs) enables browser to browser connectivity without a central server. Build completely peer-to-peer web applications, no trackers or relay servers required. Connecting projects safely, privately, and reliably in WebPEER Network.
3
+ WebPEER is a P2P Network that Runs in a Standard Browser.
5
4
 
6
- Basic Connection Demo available at : [https://nuzulul.github.io/webpeerjs/demo/](https://nuzulul.github.io/webpeerjs/demo/)
5
+ [>DEMO<](https://nuzulul.github.io/webpeerjs/demo/chat.html)
7
6
 
8
- Basic Chat App Demo available at : [https://nuzulul.github.io/webpeerjs/demo/chat.html](https://nuzulul.github.io/webpeerjs/demo/chat.html)
7
+ ![WebPEER](webpeer.png)
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
- * ✅ Decentralized P2P
18
+ * ✅ Distributed P2P
20
19
  * ✅ Scalable Peers
21
20
  * ✅ Works in Browsers
22
21
  * ✅ Broadcast Messages
23
- * ✅ Censorship Resistant
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
- ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![Brave](https://raw.github.com/alrra/browser-logos/master/src/brave/brave_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) |
27
- --- | --- | --- | --- | --- | --- |
28
- Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ❓ |
45
+ ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) ![Brave](https://raw.github.com/alrra/browser-logos/master/src/brave/brave_48x48.png) ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png)
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 i webpeerjs
52
+ npm install webpeerjs
41
53
  ```
42
54
 
43
- Browser `<script>` tag :
55
+ CDN :
44
56
 
45
- Uses built-in JS files from [latest release](https://github.com/nuzulul/webpeerjs/releases/latest) or [CDN](https://www.jsdelivr.com/package/npm/webpeerjs) will make it's exports available as `webpeerjs` in the global namespace.
57
+ * [https://esm.sh/webpeerjs](https://esm.sh/webpeerjs)
46
58
 
47
59
  ```
48
- <script src="https://cdn.jsdelivr.net/npm/webpeerjs@0.1/dist/umd/webpeerjs.min.js"></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 { webpeerjs } from 'webpeerjs'
72
+ import { createWebPEER } from 'webpeerjs'
55
73
 
56
- void async function main() {
74
+ const config = {
75
+ networkName : 'myNetwork'
76
+ }
57
77
 
58
- const node = await webpeerjs.createWebpeer()
59
-
60
- console.log(`My node id : ${node.id}`)
61
-
62
- const [broadcast,listen,onmembersupdate] = node.joinRoom('globalroom')
63
-
64
- listen((message,id) => {
65
- console.log(`Message from ${id} : ${message}`)
66
- })
67
-
68
- onmembersupdate((data) => {
69
- console.log(`Members : ${data}`)
70
- broadcast('hello')
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
- - `createWebpeer(config)` - Create a new node.
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
- ## API Docs
99
+ Create a new peer node.
90
100
 
91
- [https://nuzulul.github.io/webpeerjs](https://nuzulul.github.io/webpeerjs)
101
+ `config` - Configuration object contains:
92
102
 
93
- ## License
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
- MIT
113
+ Get the peer node status, returns `connected` or `disconnected`.
96
114
 
97
- ## Maintainers
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.10",
4
- "description": "WebPEER.js is Decentralized P2P network overlay inside browser.",
5
- "main": "./dist/umd/webpeerjs.js",
6
- "module": "./src/webpeerjs.js",
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/webpeerjs.js",
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
- "p2p",
37
- "p2p-network",
38
- "webpeer-network",
27
+ "p2p",
28
+ "p2p-network",
29
+ "webpeer-network",
39
30
  "ipfs",
40
- "libp2p",
31
+ "libp2p",
41
32
  "peer",
42
33
  "peer-to-peer",
43
34
  "decentralized",
44
35
  "browser-to-browser",
45
- "distributed",
46
- "serverless"
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-gossipsub": "^13.0.0",
59
- "@chainsafe/libp2p-noise": "^15.0.0",
60
- "@chainsafe/libp2p-yamux": "^6.0.2",
61
- "@helia/delegated-routing-v1-http-api-client": "^3.0.1",
62
- "@libp2p/circuit-relay-v2": "^1.0.24",
63
- "@libp2p/dcutr": "^1.1.0",
64
- "@libp2p/identify": "^2.0.2",
65
- "@libp2p/kad-dht": "^12.0.17",
66
- "@libp2p/peer-id": "^4.1.2",
67
- "@libp2p/pubsub-peer-discovery": "^10.0.2",
68
- "@libp2p/simple-metrics": "^1.0.2",
69
- "@libp2p/webrtc": "^4.1.0",
70
- "@libp2p/websockets": "^8.1.0",
71
- "@libp2p/webtransport": "^4.0.32",
72
- "datastore-idb": "^2.1.9",
73
- "libp2p": "^1.6.0"
74
- },
75
- "devDependencies": {
76
- "@eslint/js": "^9.4.0",
77
- "@rollup/plugin-commonjs": "^25.0.8",
78
- "@rollup/plugin-node-resolve": "^15.2.3",
79
- "@rollup/plugin-terser": "^0.4.4",
80
- "@rollup/plugin-typescript": "^11.1.6",
81
- "eslint": "^9.4.0",
82
- "globals": "^15.3.0",
83
- "rollup": "^4.18.0",
84
- "tslib": "^2.6.2",
85
- "typescript": "^5.4.5",
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 = 'webpeerjs'
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 = false
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'