bump UV, implement arraybufferimpl

This commit is contained in:
CoolElectronics 2023-08-15 13:14:44 -04:00
parent 0e1410bb95
commit b638ab7c98
No known key found for this signature in database
GPG key ID: F63593D168636C50
7 changed files with 35 additions and 21 deletions

View file

@ -18,7 +18,8 @@ const NULL_BODY_STATUSES = [101, 103, 204, 205, 304];
* below MAX_CHUNK_SIZE.
*/
function createBodyStream(
body: BodyInit | null
body: BodyInit | null,
arrayBufferImpl: ArrayBufferConstructor
): ReadableStream<ArrayBuffer | Uint8Array> | null {
if (body === null || typeof body === "undefined") return null;
@ -113,9 +114,10 @@ export class AdriftBareClient extends Client {
remote: URL,
cache: string | undefined,
duplex: string | undefined,
signal: AbortSignal | undefined
signal: AbortSignal | undefined,
arrayBufferImpl: ArrayBufferConstructor,
): Promise<BareResponse> {
const bodyStream = createBodyStream(body);
const bodyStream = createBodyStream(body, arrayBufferImpl);
let { payload, body: respRawBody } = await this.connection.httprequest(
{
method,
@ -152,7 +154,8 @@ export class AdriftBareClient extends Client {
getRequestHeaders: GetRequestHeadersCallback,
onMeta: MetaCallback,
onReadyState: ReadyStateCallback,
webSocketImpl: WebSocketImpl
webSocketImpl: WebSocketImpl,
arrayBufferImpl: ArrayBufferConstructor,
): WebSocket {
const ws = new webSocketImpl("ws:null", protocols);
// this will error. that's okay
@ -188,6 +191,10 @@ export class AdriftBareClient extends Client {
},
(data) => {
console.log({ data, binaryType: ws.binaryType });
if (data instanceof ArrayBuffer) {
(data as any).__proto__ = arrayBufferImpl.prototype;
}
ws.dispatchEvent(
new MessageEvent("message", {
data,
@ -197,7 +204,8 @@ export class AdriftBareClient extends Client {
(message: string) => {
console.log({ message });
ws.dispatchEvent(new ErrorEvent("error", { message }));
}
},
arrayBufferImpl
);
ws.send = (data: any) => {