mirror of
https://github.com/MercuryWorkshop/bare-mux.git
synced 2025-05-16 15:40:01 -04:00
support safari with a workaround, clean up code a bit
This commit is contained in:
parent
e82c0f0d08
commit
63211161f1
3 changed files with 29 additions and 11 deletions
|
@ -8,7 +8,7 @@ export type WorkerMessage = {
|
|||
remote: string,
|
||||
method: string,
|
||||
headers: BareHeaders,
|
||||
body: ReadableStream | undefined,
|
||||
body: ReadableStream | ArrayBuffer | undefined,
|
||||
}
|
||||
websocket?: {
|
||||
url: string,
|
||||
|
@ -96,6 +96,25 @@ function createPort(path: string, registerHandlers: boolean): MessagePort {
|
|||
return worker.port;
|
||||
}
|
||||
|
||||
let browserSupportsTransferringStreamsCache: boolean | null = null;
|
||||
export function browserSupportsTransferringStreams(): boolean {
|
||||
if (browserSupportsTransferringStreamsCache === null) {
|
||||
const chan = new MessageChannel();
|
||||
const stream = new ReadableStream();
|
||||
let res: boolean;
|
||||
try {
|
||||
chan.port1.postMessage(stream, [stream]);
|
||||
res = true;
|
||||
} catch(err) {
|
||||
res = false;
|
||||
}
|
||||
browserSupportsTransferringStreamsCache = res;
|
||||
return res;
|
||||
} else {
|
||||
return browserSupportsTransferringStreamsCache;
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkerConnection {
|
||||
channel: BroadcastChannel;
|
||||
port: MessagePort | Promise<MessagePort>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue