@gethashd/bytecave-browser 1.0.42 → 1.0.44

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.
@@ -6077,12 +6077,14 @@ var StorageWebSocketClient = class {
6077
6077
  }
6078
6078
  async connect() {
6079
6079
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
6080
+ console.log("[Storage WS] Already connected");
6080
6081
  return;
6081
6082
  }
6083
+ console.log("[Storage WS] Connecting to relay:", this.relayUrl);
6082
6084
  return new Promise((resolve, reject) => {
6083
6085
  this.ws = new WebSocket(this.relayUrl);
6084
6086
  this.ws.onopen = () => {
6085
- console.log("[Storage WS] Connected to relay");
6087
+ console.log("[Storage WS] \u2713 Connected to relay");
6086
6088
  resolve();
6087
6089
  };
6088
6090
  this.ws.onmessage = (event) => {
@@ -6139,11 +6141,21 @@ var StorageWebSocketClient = class {
6139
6141
  }
6140
6142
  }
6141
6143
  async store(options) {
6144
+ console.log("[Storage WS] store() called, data size:", options.data.length, "bytes");
6142
6145
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6146
+ console.log("[Storage WS] Not connected, connecting now...");
6143
6147
  await this.connect();
6144
6148
  }
6145
6149
  const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
6146
- const base64Data = btoa(String.fromCharCode(...options.data));
6150
+ console.log("[Storage WS] Converting data to base64...");
6151
+ const chunkSize = 8192;
6152
+ let binaryString = "";
6153
+ for (let i = 0; i < options.data.length; i += chunkSize) {
6154
+ const chunk = options.data.subarray(i, i + chunkSize);
6155
+ binaryString += String.fromCharCode(...chunk);
6156
+ }
6157
+ const base64Data = btoa(binaryString);
6158
+ console.log("[Storage WS] Base64 data length:", base64Data.length);
6147
6159
  const request = {
6148
6160
  type: "storage-request",
6149
6161
  requestId,
@@ -6152,16 +6164,20 @@ var StorageWebSocketClient = class {
6152
6164
  hashIdToken: options.hashIdToken,
6153
6165
  authorization: options.authorization
6154
6166
  };
6167
+ console.log("[Storage WS] Creating promise for request:", requestId);
6155
6168
  return new Promise((resolve, reject) => {
6156
6169
  const timeout = setTimeout(() => {
6170
+ console.error("[Storage WS] Request timed out:", requestId);
6157
6171
  this.pendingRequests.delete(requestId);
6158
6172
  reject(new Error("Storage request timeout"));
6159
6173
  }, options.timeout || 3e4);
6160
6174
  this.pendingRequests.set(requestId, { resolve, reject, timeout });
6161
6175
  try {
6176
+ console.log("[Storage WS] Sending request to relay, WS state:", this.ws?.readyState);
6162
6177
  this.ws.send(JSON.stringify(request));
6163
- console.log("[Storage WS] Sent storage request:", requestId);
6178
+ console.log("[Storage WS] \u2713 Sent storage request:", requestId);
6164
6179
  } catch (error) {
6180
+ console.error("[Storage WS] Failed to send request:", error.message);
6165
6181
  clearTimeout(timeout);
6166
6182
  this.pendingRequests.delete(requestId);
6167
6183
  reject(error);
package/dist/index.cjs CHANGED
@@ -6130,12 +6130,14 @@ var StorageWebSocketClient = class {
6130
6130
  }
6131
6131
  async connect() {
6132
6132
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
6133
+ console.log("[Storage WS] Already connected");
6133
6134
  return;
6134
6135
  }
6136
+ console.log("[Storage WS] Connecting to relay:", this.relayUrl);
6135
6137
  return new Promise((resolve, reject) => {
6136
6138
  this.ws = new WebSocket(this.relayUrl);
6137
6139
  this.ws.onopen = () => {
6138
- console.log("[Storage WS] Connected to relay");
6140
+ console.log("[Storage WS] \u2713 Connected to relay");
6139
6141
  resolve();
6140
6142
  };
6141
6143
  this.ws.onmessage = (event) => {
@@ -6192,11 +6194,21 @@ var StorageWebSocketClient = class {
6192
6194
  }
6193
6195
  }
6194
6196
  async store(options) {
6197
+ console.log("[Storage WS] store() called, data size:", options.data.length, "bytes");
6195
6198
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
6199
+ console.log("[Storage WS] Not connected, connecting now...");
6196
6200
  await this.connect();
6197
6201
  }
6198
6202
  const requestId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
6199
- const base64Data = btoa(String.fromCharCode(...options.data));
6203
+ console.log("[Storage WS] Converting data to base64...");
6204
+ const chunkSize = 8192;
6205
+ let binaryString = "";
6206
+ for (let i = 0; i < options.data.length; i += chunkSize) {
6207
+ const chunk = options.data.subarray(i, i + chunkSize);
6208
+ binaryString += String.fromCharCode(...chunk);
6209
+ }
6210
+ const base64Data = btoa(binaryString);
6211
+ console.log("[Storage WS] Base64 data length:", base64Data.length);
6200
6212
  const request = {
6201
6213
  type: "storage-request",
6202
6214
  requestId,
@@ -6205,16 +6217,20 @@ var StorageWebSocketClient = class {
6205
6217
  hashIdToken: options.hashIdToken,
6206
6218
  authorization: options.authorization
6207
6219
  };
6220
+ console.log("[Storage WS] Creating promise for request:", requestId);
6208
6221
  return new Promise((resolve, reject) => {
6209
6222
  const timeout = setTimeout(() => {
6223
+ console.error("[Storage WS] Request timed out:", requestId);
6210
6224
  this.pendingRequests.delete(requestId);
6211
6225
  reject(new Error("Storage request timeout"));
6212
6226
  }, options.timeout || 3e4);
6213
6227
  this.pendingRequests.set(requestId, { resolve, reject, timeout });
6214
6228
  try {
6229
+ console.log("[Storage WS] Sending request to relay, WS state:", this.ws?.readyState);
6215
6230
  this.ws.send(JSON.stringify(request));
6216
- console.log("[Storage WS] Sent storage request:", requestId);
6231
+ console.log("[Storage WS] \u2713 Sent storage request:", requestId);
6217
6232
  } catch (error) {
6233
+ console.error("[Storage WS] Failed to send request:", error.message);
6218
6234
  clearTimeout(timeout);
6219
6235
  this.pendingRequests.delete(requestId);
6220
6236
  reject(error);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-P7BUV66R.js";
16
+ } from "./chunk-M5BKEAWD.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-P7BUV66R.js";
11
+ } from "../chunk-M5BKEAWD.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.42",
3
+ "version": "1.0.44",
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",
@@ -71,14 +71,16 @@ export class StorageWebSocketClient {
71
71
 
72
72
  async connect(): Promise<void> {
73
73
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
74
+ console.log('[Storage WS] Already connected');
74
75
  return;
75
76
  }
76
77
 
78
+ console.log('[Storage WS] Connecting to relay:', this.relayUrl);
77
79
  return new Promise((resolve, reject) => {
78
80
  this.ws = new WebSocket(this.relayUrl);
79
81
 
80
82
  this.ws.onopen = () => {
81
- console.log('[Storage WS] Connected to relay');
83
+ console.log('[Storage WS] Connected to relay');
82
84
  resolve();
83
85
  };
84
86
 
@@ -144,15 +146,27 @@ export class StorageWebSocketClient {
144
146
  }
145
147
 
146
148
  async store(options: StoreViaWebSocketOptions): Promise<{ success: boolean; cid?: string; error?: string }> {
149
+ console.log('[Storage WS] store() called, data size:', options.data.length, 'bytes');
150
+
147
151
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
152
+ console.log('[Storage WS] Not connected, connecting now...');
148
153
  await this.connect();
149
154
  }
150
155
 
151
156
  const requestId = Math.random().toString(36).substring(2, 15) +
152
157
  Math.random().toString(36).substring(2, 15);
153
158
 
159
+ console.log('[Storage WS] Converting data to base64...');
154
160
  // Convert Uint8Array to base64
155
- const base64Data = btoa(String.fromCharCode(...options.data));
161
+ // Chunk the data to avoid stack overflow with large files
162
+ const chunkSize = 8192;
163
+ let binaryString = '';
164
+ for (let i = 0; i < options.data.length; i += chunkSize) {
165
+ const chunk = options.data.subarray(i, i + chunkSize);
166
+ binaryString += String.fromCharCode(...chunk);
167
+ }
168
+ const base64Data = btoa(binaryString);
169
+ console.log('[Storage WS] Base64 data length:', base64Data.length);
156
170
 
157
171
  const request: StorageRequestMessage = {
158
172
  type: 'storage-request',
@@ -163,8 +177,10 @@ export class StorageWebSocketClient {
163
177
  authorization: options.authorization
164
178
  };
165
179
 
180
+ console.log('[Storage WS] Creating promise for request:', requestId);
166
181
  return new Promise((resolve, reject) => {
167
182
  const timeout = setTimeout(() => {
183
+ console.error('[Storage WS] Request timed out:', requestId);
168
184
  this.pendingRequests.delete(requestId);
169
185
  reject(new Error('Storage request timeout'));
170
186
  }, options.timeout || 30000);
@@ -172,9 +188,11 @@ export class StorageWebSocketClient {
172
188
  this.pendingRequests.set(requestId, { resolve, reject, timeout });
173
189
 
174
190
  try {
191
+ console.log('[Storage WS] Sending request to relay, WS state:', this.ws?.readyState);
175
192
  this.ws!.send(JSON.stringify(request));
176
- console.log('[Storage WS] Sent storage request:', requestId);
193
+ console.log('[Storage WS] Sent storage request:', requestId);
177
194
  } catch (error: any) {
195
+ console.error('[Storage WS] Failed to send request:', error.message);
178
196
  clearTimeout(timeout);
179
197
  this.pendingRequests.delete(requestId);
180
198
  reject(error);