Skip to content

Commit

Permalink
Cloudflare Worker fixes (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
kearfy authored Nov 20, 2024
1 parent 794092a commit 39c950b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/engines/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export class WebsocketEngine extends AbstractEngine {

socket.addEventListener("error", (e) => {
const error = new UnexpectedConnectionError(
"error" in e ? e.error : "An unexpected error occurred",
"detail" in e
? e.detail
: "error" in e
? e.error
: "An unexpected error occurred",
);
this.setStatus(ConnectionStatus.Error, error);
reject(error);
Expand All @@ -78,12 +82,14 @@ export class WebsocketEngine extends AbstractEngine {
socket.addEventListener("message", async ({ data }) => {
try {
const decoded = this.decodeCbor(
data instanceof Blob
? await data.arrayBuffer()
: data.buffer.slice(
data.byteOffset,
data.byteOffset + data.byteLength,
),
data instanceof ArrayBuffer
? data
: data instanceof Blob
? await data.arrayBuffer()
: data.buffer.slice(
data.byteOffset,
data.byteOffset + data.byteLength,
),
);

if (
Expand Down

0 comments on commit 39c950b

Please # to comment.