@gethashd/bytecave-browser 1.0.59 → 1.0.61

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.
@@ -5726,32 +5726,14 @@ var P2PProtocolClient = class {
5726
5726
  } catch (e) {
5727
5727
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5728
5728
  }
5729
- console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5729
+ console.log("[ByteCave P2P] Step 2: Using existing connection...");
5730
5730
  if (existingConns.length === 0) {
5731
5731
  throw new Error("No connection to peer - cannot open protocol stream");
5732
5732
  }
5733
- let connection = existingConns[0];
5733
+ const connection = existingConns[0];
5734
5734
  const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
5735
- console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
5735
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit" : "direct");
5736
5736
  console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
5737
- if (isRelayCircuit) {
5738
- console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
5739
- const upgradeStart = Date.now();
5740
- const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
5741
- const upgradeDuration = Date.now() - upgradeStart;
5742
- if (!hasDirectConnection) {
5743
- console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
5744
- throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
5745
- }
5746
- console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
5747
- const directConns = this.node.getConnections(peerIdObj);
5748
- const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
5749
- if (!directConn) {
5750
- throw new Error("DCUtR reported success but no direct connection found");
5751
- }
5752
- connection = directConn;
5753
- console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
5754
- }
5755
5737
  console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5756
5738
  const streamStart = Date.now();
5757
5739
  let stream;
@@ -6199,6 +6181,12 @@ var StorageWebSocketClient = class {
6199
6181
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6200
6182
  await this.connect();
6201
6183
  }
6184
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6185
+ return {
6186
+ success: false,
6187
+ error: "WebSocket not connected after connect() call"
6188
+ };
6189
+ }
6202
6190
  const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
6203
6191
  const request = {
6204
6192
  type: "retrieve-request",
package/dist/index.cjs CHANGED
@@ -5794,32 +5794,14 @@ var P2PProtocolClient = class {
5794
5794
  } catch (e) {
5795
5795
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5796
5796
  }
5797
- console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
5797
+ console.log("[ByteCave P2P] Step 2: Using existing connection...");
5798
5798
  if (existingConns.length === 0) {
5799
5799
  throw new Error("No connection to peer - cannot open protocol stream");
5800
5800
  }
5801
- let connection = existingConns[0];
5801
+ const connection = existingConns[0];
5802
5802
  const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
5803
- console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
5803
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit" : "direct");
5804
5804
  console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
5805
- if (isRelayCircuit) {
5806
- console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
5807
- const upgradeStart = Date.now();
5808
- const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
5809
- const upgradeDuration = Date.now() - upgradeStart;
5810
- if (!hasDirectConnection) {
5811
- console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
5812
- throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
5813
- }
5814
- console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
5815
- const directConns = this.node.getConnections(peerIdObj);
5816
- const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
5817
- if (!directConn) {
5818
- throw new Error("DCUtR reported success but no direct connection found");
5819
- }
5820
- connection = directConn;
5821
- console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
5822
- }
5823
5805
  console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
5824
5806
  const streamStart = Date.now();
5825
5807
  let stream;
@@ -6252,6 +6234,12 @@ var StorageWebSocketClient = class {
6252
6234
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6253
6235
  await this.connect();
6254
6236
  }
6237
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6238
+ return {
6239
+ success: false,
6240
+ error: "WebSocket not connected after connect() call"
6241
+ };
6242
+ }
6255
6243
  const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
6256
6244
  const request = {
6257
6245
  type: "retrieve-request",
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-FOQ3CE3H.js";
16
+ } from "./chunk-IIXRZSDW.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6049,32 +6049,14 @@ var P2PProtocolClient = class {
6049
6049
  } catch (e) {
6050
6050
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
6051
6051
  }
6052
- console.log("[ByteCave P2P] Step 2: Checking if connection upgrade needed...");
6052
+ console.log("[ByteCave P2P] Step 2: Using existing connection...");
6053
6053
  if (existingConns.length === 0) {
6054
6054
  throw new Error("No connection to peer - cannot open protocol stream");
6055
6055
  }
6056
- let connection = existingConns[0];
6056
+ const connection = existingConns[0];
6057
6057
  const isRelayCircuit = connection.remoteAddr.toString().includes("/p2p-circuit");
6058
- console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit (limited)" : "direct");
6058
+ console.log("[ByteCave P2P] Connection type:", isRelayCircuit ? "relay circuit" : "direct");
6059
6059
  console.log("[ByteCave P2P] Connection address:", connection.remoteAddr.toString());
6060
- if (isRelayCircuit) {
6061
- console.log("[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...");
6062
- const upgradeStart = Date.now();
6063
- const hasDirectConnection = await this.waitForDirectConnection(peerId, 5e3);
6064
- const upgradeDuration = Date.now() - upgradeStart;
6065
- if (!hasDirectConnection) {
6066
- console.error("[ByteCave P2P] DCUtR upgrade failed after", upgradeDuration, "ms");
6067
- throw new Error("Cannot use storage protocol - relay circuit upgrade to WebRTC failed");
6068
- }
6069
- console.log("[ByteCave P2P] DCUtR upgrade successful after", upgradeDuration, "ms");
6070
- const directConns = this.node.getConnections(peerIdObj);
6071
- const directConn = directConns.find((conn) => !conn.remoteAddr.toString().includes("/p2p-circuit"));
6072
- if (!directConn) {
6073
- throw new Error("DCUtR reported success but no direct connection found");
6074
- }
6075
- connection = directConn;
6076
- console.log("[ByteCave P2P] Using direct connection:", connection.remoteAddr.toString());
6077
- }
6078
6060
  console.log("[ByteCave P2P] Step 3: Opening protocol stream...");
6079
6061
  const streamStart = Date.now();
6080
6062
  let stream;
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-FOQ3CE3H.js";
11
+ } from "../chunk-IIXRZSDW.js";
12
12
  import "../chunk-EEZWRIUI.js";
13
13
  export {
14
14
  HashdAudio,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gethashd/bytecave-browser",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "description": "ByteCave browser client for WebRTC P2P connections to storage nodes",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -150,41 +150,20 @@ export class P2PProtocolClient {
150
150
  console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
151
151
  }
152
152
 
153
- // Step 2: Wait for connection upgrade from limited relay circuit to full WebRTC
154
- console.log('[ByteCave P2P] Step 2: Checking if connection upgrade needed...');
153
+ // Step 2: Use existing connection (relay circuit or direct)
154
+ console.log('[ByteCave P2P] Step 2: Using existing connection...');
155
155
 
156
156
  if (existingConns.length === 0) {
157
157
  throw new Error('No connection to peer - cannot open protocol stream');
158
158
  }
159
159
 
160
- let connection = existingConns[0];
160
+ const connection = existingConns[0];
161
161
  const isRelayCircuit = connection.remoteAddr.toString().includes('/p2p-circuit');
162
- console.log('[ByteCave P2P] Connection type:', isRelayCircuit ? 'relay circuit (limited)' : 'direct');
162
+ console.log('[ByteCave P2P] Connection type:', isRelayCircuit ? 'relay circuit' : 'direct');
163
163
  console.log('[ByteCave P2P] Connection address:', connection.remoteAddr.toString());
164
164
 
165
- // If it's a relay circuit, wait for DCUtR to upgrade to direct WebRTC
166
- if (isRelayCircuit) {
167
- console.log('[ByteCave P2P] Waiting for DCUtR to upgrade relay circuit to direct WebRTC...');
168
- const upgradeStart = Date.now();
169
- const hasDirectConnection = await this.waitForDirectConnection(peerId, 5000);
170
- const upgradeDuration = Date.now() - upgradeStart;
171
-
172
- if (!hasDirectConnection) {
173
- console.error('[ByteCave P2P] DCUtR upgrade failed after', upgradeDuration, 'ms');
174
- throw new Error('Cannot use storage protocol - relay circuit upgrade to WebRTC failed');
175
- }
176
-
177
- console.log('[ByteCave P2P] DCUtR upgrade successful after', upgradeDuration, 'ms');
178
-
179
- // Get the new direct connection
180
- const directConns = this.node!.getConnections(peerIdObj);
181
- const directConn = directConns.find(conn => !conn.remoteAddr.toString().includes('/p2p-circuit'));
182
- if (!directConn) {
183
- throw new Error('DCUtR reported success but no direct connection found');
184
- }
185
- connection = directConn;
186
- console.log('[ByteCave P2P] Using direct connection:', connection.remoteAddr.toString());
187
- }
165
+ // Note: We allow both relay circuits and direct connections
166
+ // Relay circuits work fine for storage operations via the relay
188
167
 
189
168
  // Step 3: Open protocol stream on the connection
190
169
  console.log('[ByteCave P2P] Step 3: Opening protocol stream...');
@@ -219,6 +219,14 @@ export class StorageWebSocketClient {
219
219
  await this.connect();
220
220
  }
221
221
 
222
+ // Double-check connection state after connect() completes
223
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
224
+ return {
225
+ success: false,
226
+ error: 'WebSocket not connected after connect() call'
227
+ };
228
+ }
229
+
222
230
  const requestId = Math.random().toString(36).substring(2, 15) +
223
231
  Math.random().toString(36).substring(2, 15);
224
232