mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 06:10:01 -04:00
WINDOW.ARRAYBUFFER IM GOING CRAZY
This commit is contained in:
parent
f6a06b5fb3
commit
0e1410bb95
5 changed files with 19 additions and 9 deletions
|
@ -13,7 +13,8 @@
|
|||
"@types/uuid": "^9.0.2",
|
||||
"bare-client-custom": "file:../bare-client-custom",
|
||||
"firebase": "^10.1.0",
|
||||
"protocol": "workspace:*"
|
||||
"protocol": "workspace:*",
|
||||
"web-streams-polyfill": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.4.10"
|
||||
|
|
|
@ -26,14 +26,14 @@ function createBodyStream(
|
|||
body = new TextEncoder().encode(body);
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(body)) {
|
||||
if (window.ArrayBuffer.isView(body)) {
|
||||
body = body.buffer.slice(
|
||||
body.byteOffset,
|
||||
body.byteOffset + body.byteLength
|
||||
);
|
||||
}
|
||||
|
||||
if (body instanceof ArrayBuffer) {
|
||||
if (body instanceof window.ArrayBuffer) {
|
||||
if (body.byteLength == 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ function createBodyStream(
|
|||
if (chunk instanceof Blob) {
|
||||
chunk = await chunk.arrayBuffer();
|
||||
}
|
||||
if (ArrayBuffer.isView(chunk)) {
|
||||
if (window.ArrayBuffer.isView(chunk)) {
|
||||
chunk = chunk.buffer.slice(
|
||||
chunk.byteOffset,
|
||||
chunk.byteOffset + chunk.byteLength
|
||||
|
@ -76,7 +76,7 @@ function createBodyStream(
|
|||
}
|
||||
|
||||
// if none of those worked, give up.
|
||||
if (!(chunk instanceof ArrayBuffer)) {
|
||||
if (!(chunk instanceof window.ArrayBuffer)) {
|
||||
console.error({ chunk });
|
||||
throw new Error("Invalid type read from body stream: " + chunk);
|
||||
}
|
||||
|
@ -187,6 +187,7 @@ export class AdriftBareClient extends Client {
|
|||
ws.dispatchEvent(new CloseEvent("close", { code, reason, wasClean }));
|
||||
},
|
||||
(data) => {
|
||||
console.log({ data, binaryType: ws.binaryType });
|
||||
ws.dispatchEvent(
|
||||
new MessageEvent("message", {
|
||||
data,
|
||||
|
|
|
@ -147,7 +147,7 @@ export class Connection {
|
|||
type: C2SRequestType,
|
||||
data?: ArrayBuffer | Blob
|
||||
): Promise<void> {
|
||||
let header = new ArrayBuffer(2 + 1);
|
||||
let header = new window.ArrayBuffer(2 + 1);
|
||||
let view = new DataView(header);
|
||||
|
||||
let cursor = 0;
|
||||
|
@ -245,11 +245,11 @@ export class Connection {
|
|||
).catch(cleanup);
|
||||
return;
|
||||
}
|
||||
if (data instanceof ArrayBuffer) {
|
||||
if (data instanceof window.ArrayBuffer) {
|
||||
this.send(seq, C2SRequestTypes.WSSendBinary, data).catch(cleanup);
|
||||
return;
|
||||
}
|
||||
if (ArrayBuffer.isView(data)) {
|
||||
if (window.ArrayBuffer.isView(data)) {
|
||||
this.send(
|
||||
seq,
|
||||
C2SRequestTypes.WSSendBinary,
|
||||
|
|
|
@ -14,7 +14,7 @@ export class DevWsTransport extends Transport {
|
|||
}
|
||||
|
||||
onmessage(msg: MessageEvent<any>) {
|
||||
if (msg.data instanceof ArrayBuffer) {
|
||||
if (msg.data instanceof window.ArrayBuffer) {
|
||||
this.ondata(msg.data);
|
||||
return;
|
||||
}
|
||||
|
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
|
@ -174,6 +174,9 @@ importers:
|
|||
protocol:
|
||||
specifier: workspace:*
|
||||
version: link:../protocol
|
||||
web-streams-polyfill:
|
||||
specifier: ^3.2.1
|
||||
version: 3.2.1
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^20.4.10
|
||||
|
@ -10998,6 +11001,11 @@ packages:
|
|||
defaults: 1.0.4
|
||||
dev: false
|
||||
|
||||
/web-streams-polyfill@3.2.1:
|
||||
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
|
||||
engines: {node: '>= 8'}
|
||||
dev: false
|
||||
|
||||
/webidl-conversions@3.0.1:
|
||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue