Replying to Avatar Anthony Accioly

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#L28

If 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

`pool.ts` where `_WebSocket` and `useWebSocketImplementation` can be found:

https://github.com/nbd-wtf/nostr-tools/blob/master/pool.ts

Reply to this note

Please Login to reply.

Discussion

No replies yet.