@unicitylabs/nostr-js-sdk 0.0.2 → 0.0.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/dist/browser/index.js +6 -21
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.min.js +1 -1
- package/dist/browser/index.min.js.map +1 -1
- package/dist/browser/index.umd.js +6 -21
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/browser/index.umd.min.js +1 -1
- package/dist/browser/index.umd.min.js.map +1 -1
- package/dist/cjs/client/WebSocketAdapter.browser.js +43 -0
- package/dist/cjs/client/WebSocketAdapter.browser.js.map +1 -0
- package/dist/cjs/client/WebSocketAdapter.js +1 -2
- package/dist/cjs/client/WebSocketAdapter.js.map +1 -1
- package/dist/esm/client/WebSocketAdapter.browser.js +38 -0
- package/dist/esm/client/WebSocketAdapter.browser.js.map +1 -0
- package/dist/esm/client/WebSocketAdapter.js +1 -2
- package/dist/esm/client/WebSocketAdapter.js.map +1 -1
- package/dist/types/client/WebSocketAdapter.browser.d.ts +54 -0
- package/dist/types/client/WebSocketAdapter.browser.d.ts.map +1 -0
- package/dist/types/client/WebSocketAdapter.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -4434,8 +4434,8 @@
|
|
|
4434
4434
|
});
|
|
4435
4435
|
|
|
4436
4436
|
/**
|
|
4437
|
-
* WebSocketAdapter -
|
|
4438
|
-
*
|
|
4437
|
+
* WebSocketAdapter - Browser implementation.
|
|
4438
|
+
* Uses the native WebSocket API.
|
|
4439
4439
|
*/
|
|
4440
4440
|
/** WebSocket ready state constants */
|
|
4441
4441
|
const CONNECTING = 0;
|
|
@@ -4443,28 +4443,18 @@
|
|
|
4443
4443
|
const CLOSING = 2;
|
|
4444
4444
|
const CLOSED = 3;
|
|
4445
4445
|
/**
|
|
4446
|
-
* Create a WebSocket connection
|
|
4446
|
+
* Create a WebSocket connection using native browser WebSocket.
|
|
4447
4447
|
* @param url WebSocket URL (ws:// or wss://)
|
|
4448
4448
|
* @returns WebSocket instance
|
|
4449
4449
|
*/
|
|
4450
4450
|
async function createWebSocket(url) {
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
return new WebSocket(url);
|
|
4454
|
-
}
|
|
4455
|
-
// Node.js environment - dynamically import ws
|
|
4456
|
-
try {
|
|
4457
|
-
// @vite-ignore
|
|
4458
|
-
const { default: WS } = await import(/* @vite-ignore */ 'ws');
|
|
4459
|
-
return new WS(url);
|
|
4460
|
-
}
|
|
4461
|
-
catch {
|
|
4462
|
-
throw new Error('WebSocket not available. In Node.js, install the "ws" package: npm install ws');
|
|
4451
|
+
if (typeof WebSocket === 'undefined') {
|
|
4452
|
+
throw new Error('WebSocket not available in this environment');
|
|
4463
4453
|
}
|
|
4454
|
+
return new WebSocket(url);
|
|
4464
4455
|
}
|
|
4465
4456
|
/**
|
|
4466
4457
|
* Extract string data from WebSocket message event.
|
|
4467
|
-
* Handles different message types across platforms.
|
|
4468
4458
|
* @param event WebSocket message event
|
|
4469
4459
|
* @returns String message data
|
|
4470
4460
|
*/
|
|
@@ -4476,13 +4466,8 @@
|
|
|
4476
4466
|
return new TextDecoder().decode(event.data);
|
|
4477
4467
|
}
|
|
4478
4468
|
if (typeof Blob !== 'undefined' && event.data instanceof Blob) {
|
|
4479
|
-
// This shouldn't happen in normal Nostr relay communication
|
|
4480
4469
|
throw new Error('Blob messages are not supported');
|
|
4481
4470
|
}
|
|
4482
|
-
// Node.js Buffer case
|
|
4483
|
-
if (Buffer && Buffer.isBuffer(event.data)) {
|
|
4484
|
-
return event.data.toString('utf-8');
|
|
4485
|
-
}
|
|
4486
4471
|
return String(event.data);
|
|
4487
4472
|
}
|
|
4488
4473
|
|