webpeerjs 0.1.2 → 0.1.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpeerjs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "WebPEER.js is decentralized P2P JS library for communication between applications in browser.",
5
5
  "main": "./dist/umd/webpeerjs.js",
6
6
  "module": "./src/webpeerjs.js",
package/src/config.js CHANGED
@@ -20,6 +20,7 @@ export const CONFIG_DNS_RESOLVER = 'https://dns.google/resolve'
20
20
  export const CONFIG_KNOWN_BOOTSTRAP_DNS = '_dnsaddr.bootstrap.libp2p.io'
21
21
  export const CONFIG_JOIN_ROOM_VERSION = 1
22
22
  export const CONFIG_TIMEOUT_DIAL_KNOWN_PEERS = 15000
23
+ export const CONFIG_RUN_ON_TRANSIENT_CONNECTION = true
23
24
 
24
25
  // this list comes from https://github.com/ipfs/kubo/blob/196887cbe5fbcd41243c1dfb0db681a1cc2914ff/config/bootstrap_peers.go
25
26
  export const CONFIG_KNOWN_DEFAULT_BOOTSTRAP_ADDRESSES = [
package/src/webpeerjs.js CHANGED
@@ -515,7 +515,7 @@ class webpeerjs{
515
515
  const mddrs = []
516
516
  peer.addresses.forEach((addr)=>{
517
517
  const maddr = addr.multiaddr.toString()+'/p2p/'+id
518
- if(maddr.includes('webtransport') && maddr.includes('certhash') && maddr.includes('webrtc')){
518
+ if(maddr.includes('webtransport') && maddr.includes('certhash')){
519
519
  mddrs.push(maddr)
520
520
  }
521
521
  })
@@ -684,7 +684,14 @@ class webpeerjs{
684
684
  //join room version 1 user pupsub via pupsub peer discovery
685
685
  if(config.CONFIG_JOIN_ROOM_VERSION == 1){
686
686
 
687
- const topics = config.CONFIG_PUPSUB_PEER_DATA
687
+ let topics = []
688
+
689
+ if(config.CONFIG_RUN_ON_TRANSIENT_CONNECTION == true){
690
+ topics = config.CONFIG_PUBSUB_PEER_DISCOVERY_HYBRID
691
+ }
692
+ else{
693
+ topics = config.CONFIG_PUPSUB_PEER_DATA
694
+ }
688
695
 
689
696
  this.#rooms[room] = {
690
697
  onMessage : () => {},
@@ -834,9 +841,9 @@ class webpeerjs{
834
841
  }
835
842
 
836
843
  await this.#libp2p.handle(config.CONFIG_PROTOCOL, handler, {
837
- maxInboundStreams: 50,
838
- maxOutboundStreams: 50,
839
- runOnTransientConnection:false
844
+ maxInboundStreams: 100,
845
+ maxOutboundStreams: 100,
846
+ runOnTransientConnection:config.CONFIG_RUN_ON_TRANSIENT_CONNECTION
840
847
  })
841
848
 
842
849
  await this.#libp2p.register(config.CONFIG_PROTOCOL, {
@@ -883,7 +890,7 @@ class webpeerjs{
883
890
 
884
891
  try{
885
892
 
886
- const stream = await this.#libp2p.dialProtocol(mddr, config.CONFIG_PROTOCOL,{runOnTransientConnection:false})
893
+ const stream = await this.#libp2p.dialProtocol(mddr, config.CONFIG_PROTOCOL,{runOnTransientConnection:config.CONFIG_RUN_ON_TRANSIENT_CONNECTION})
887
894
 
888
895
  const output = await pipe(
889
896
  message,
@@ -1117,7 +1124,14 @@ class webpeerjs{
1117
1124
  }
1118
1125
 
1119
1126
  async #announce(){
1120
- const topics = config.CONFIG_PUPSUB_PEER_DATA
1127
+ let topics = []
1128
+
1129
+ if(config.CONFIG_RUN_ON_TRANSIENT_CONNECTION == true){
1130
+ topics = config.CONFIG_PUBSUB_PEER_DISCOVERY_HYBRID
1131
+ }
1132
+ else{
1133
+ topics = config.CONFIG_PUPSUB_PEER_DATA
1134
+ }
1121
1135
  const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
1122
1136
  const peer = {
1123
1137
  publicKey: this.#libp2p.peerId.publicKey,
@@ -1130,7 +1144,14 @@ class webpeerjs{
1130
1144
  }
1131
1145
 
1132
1146
  async #ping(){
1133
- const topics = config.CONFIG_PUPSUB_PEER_DATA
1147
+ let topics = []
1148
+
1149
+ if(config.CONFIG_RUN_ON_TRANSIENT_CONNECTION == true){
1150
+ topics = config.CONFIG_PUBSUB_PEER_DISCOVERY_HYBRID
1151
+ }
1152
+ else{
1153
+ topics = config.CONFIG_PUPSUB_PEER_DATA
1154
+ }
1134
1155
  const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
1135
1156
  const peer = {
1136
1157
  publicKey: this.#libp2p.peerId.publicKey,
@@ -1674,12 +1695,16 @@ class webpeerjs{
1674
1695
  let onMetricsFn = () => {}
1675
1696
  const onMetrics = f => (onMetricsFn = f)
1676
1697
 
1698
+ let listenaddress = []
1699
+
1700
+ if(config.CONFIG_RUN_ON_TRANSIENT_CONNECTION == false){
1701
+ listenaddress.push('/webrtc')
1702
+ }
1703
+
1677
1704
  //create libp2p instance
1678
1705
  const libp2p = await createLibp2p({
1679
1706
  addresses: {
1680
- listen: [
1681
- '/webrtc'
1682
- ],
1707
+ listen: listenaddress,
1683
1708
  },
1684
1709
  transports:[
1685
1710
  webTransport(),
@@ -1718,8 +1743,8 @@ class webpeerjs{
1718
1743
  connectionEncryption: [noise()],
1719
1744
  streamMuxers: [
1720
1745
  yamux({
1721
- maxInboundStreams: 20,
1722
- maxOutboundStreams: 20,
1746
+ maxInboundStreams: 100,
1747
+ maxOutboundStreams: 100,
1723
1748
  })
1724
1749
  ],
1725
1750
  connectionGater: {
@@ -1757,7 +1782,7 @@ class webpeerjs{
1757
1782
  allowPublishToZeroTopicPeers: true,
1758
1783
  msgIdFn: msgIdFnStrictNoSign,
1759
1784
  ignoreDuplicatePublishError: true,
1760
- runOnTransientConnection:false,
1785
+ runOnTransientConnection:config.CONFIG_RUN_ON_TRANSIENT_CONNECTION,
1761
1786
  }),
1762
1787
  identify: identify(),
1763
1788
  identifyPush: identifyPush(),