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