Anthony Accioly on Nostr: Morning folks. Quick one, I'm working (well, actually, talking my mouth off and ...
Morning folks. Quick one, I'm working (well, actually, talking my mouth off and getting in the way of their good work 🤣) with Keyoxide folks on their Matrix channel. They are implementing Nostr support and having an interesting issue with nostr-tools.
Apparently
```
import { WebSocket } from 'ws'
useWebSocketImplementation(WebSocket)
```
Is not setting the WS in their environment. Bizarrely, manually setting the variable works.
```
pool._WebSocket = WebSocket
```
See:
https://code.jaenis.ch/gists/nostr-tools-websocket-closure-leak/src/branch/main/nostr.js#L28If you comment line 28 things break.
The code is runnable (`npm i && npm run test`).
I'm a bit clueless when it comes to TypeScript, but it feels like this was meant be somewhat of a "private" global variable. Somehow `useWebSocketImplementation` is not working in this example. After calling `useWebSocketImplementation` WebSocket is still undefined.
Anyone more familiar with TypeScript and Nostr tools can have a look?
#devstr #asknostr #nostrtools #typescript #websockets
Published at
2025-05-27 10:16:54Event JSON
{
"id": "2f6d4674064f647c0f9feab8b2f43344567c665a99a686b8d0cca6a4235d9118",
"pubkey": "ee9d979e7e1418a9f7472baf82dc96082a0d4251b77bcb170a6ecec93fadff64",
"created_at": 1748341014,
"kind": 1,
"tags": [
[
"t",
"devstr"
],
[
"t",
"asknostr"
],
[
"t",
"nostrtools"
],
[
"t",
"typescript"
],
[
"t",
"websockets"
],
[
"r",
"https://code.jaenis.ch/gists/nostr-tools-websocket-closure-leak/src/branch/main/nostr.js#L28"
]
],
"content": "Morning folks. Quick one, I'm working (well, actually, talking my mouth off and getting in the way of their good work 🤣) with Keyoxide folks on their Matrix channel. They are implementing Nostr support and having an interesting issue with nostr-tools.\n\nApparently\n\n ```\nimport { WebSocket } from 'ws'\n\nuseWebSocketImplementation(WebSocket)\n``` \n\nIs not setting the WS in their environment. Bizarrely, manually setting the variable works.\n\n```\npool._WebSocket = WebSocket\n```\n\nSee: https://code.jaenis.ch/gists/nostr-tools-websocket-closure-leak/src/branch/main/nostr.js#L28\n\nIf you comment line 28 things break.\n\nThe code is runnable (`npm i \u0026\u0026 npm run test`).\n\nI'm a bit clueless when it comes to TypeScript, but it feels like this was meant be somewhat of a \"private\" global variable. Somehow `useWebSocketImplementation` is not working in this example. After calling `useWebSocketImplementation` WebSocket is still undefined.\n\nAnyone more familiar with TypeScript and Nostr tools can have a look?\n\n#devstr #asknostr #nostrtools #typescript #websockets",
"sig": "20271de2789f032c25ec33d8cd73fe786c924633353ceb2e7fdca9e3bd7e5fbfb2650532c5e8b185be1762be1f8b8946483f9852dfb9fb54400a3f2578818657"
}