Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-poets-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/react-native': patch
---

Shims for AbortSignal.timeout and AbortSignal.any to handle usages in `livekit-client`
36 changes: 36 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
shimArrayAt();
shimCryptoUuid();
shimWebstreams();
shimAbortSignal();
setupNativeEvents();
}

Expand Down Expand Up @@ -152,6 +153,41 @@
}
}

function shimAbortSignal() {
// @ts-expect-error: AbortSignal.any isn't defined in RN.
if (typeof AbortSignal.any === "undefined") {

Check failure on line 158 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Replace `"undefined"` with `'undefined'`
// @ts-expect-error: AbortSignal.any isn't defined in RN.
AbortSignal.any = function (signals: AbortSignal[]): AbortSignal {
const controller = new AbortController()

Check failure on line 161 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Insert `;`

Check failure on line 162 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Delete `······`
// If any signal is already aborted, abort immediately
for (const signal of signals) {
if (signal.aborted) {
controller.abort()

Check failure on line 166 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Insert `;`
return controller.signal

Check failure on line 167 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Insert `;`
}
}

Check failure on line 170 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Delete `······`
// Listen for abort events on all signals
const abortHandler = () => controller.abort()

Check failure on line 172 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Insert `;`
for (const signal of signals) {
signal.addEventListener("abort", abortHandler)

Check failure on line 174 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Replace `"abort",·abortHandler)` with `'abort',·abortHandler);`
}

Check failure on line 176 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Delete `······`
return controller.signal

Check failure on line 177 in src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Insert `;`
}
}

// @ts-expect-error: AbortSignal.timeout isn't defined in RN.
if (typeof AbortSignal.timeout === "undefined") {
// @ts-expect-error: AbortSignal.timeout isn't defined in RN.
AbortSignal.timeout = function (ms: number): AbortSignal {
const controller = new AbortController()
setTimeout(() => controller.abort(), ms)
return controller.signal
}
}
}
export * from './hooks';
export * from './components/BarVisualizer';
export * from './components/LiveKitRoom';
Expand Down
Loading