Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

fix: window is not defined in worker contexts #59

Merged
merged 10 commits into from
Mar 24, 2023
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"build": "aegir build",
"test": "aegir test -t browser",
"test": "aegir test -t browser -t webworker",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"release": "aegir release",
Expand All @@ -168,7 +168,6 @@
"uint8arraylist": "^2.3.3"
},
"devDependencies": {
"@fails-components/webtransport": "^0.1.5",
"aegir": "^38.1.7",
"libp2p": "^0.43.2"
},
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type { Duplex, Source } from 'it-stream-types'
import type { StreamMuxerFactory, StreamMuxerInit, StreamMuxer } from '@libp2p/interface-stream-muxer'
import { Uint8ArrayList } from 'uint8arraylist'

declare global {
var WebTransport: any
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why get rid of the typings...?

}

SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
const log = logger('libp2p:webtransport')

// @ts-expect-error - Not easy to combine these types.
Expand Down Expand Up @@ -359,7 +363,7 @@ class WebTransportTransport implements Transport {
yield val.value
}

if (val.done) {
if (val.done === true) {
break
}
}
Expand Down Expand Up @@ -413,9 +417,11 @@ class WebTransportTransport implements Transport {
const reader = wt.incomingBidirectionalStreams.getReader()
while (true) {
const { done, value: wtStream } = await reader.read()
if (done) {

if (done === true) {
break
}

if (activeStreams.length >= config.maxInboundStreams) {
// We've reached our limit, close this stream.
wtStream.writable.close().catch((err: Error) => {
Expand Down
9 changes: 0 additions & 9 deletions src/types.ts

This file was deleted.