@miniflare/web-sockets
Advanced tools
Comparing version 2.8.1 to 2.9.0-next.1
@@ -42,2 +42,4 @@ import { Dispatcher } from 'undici'; | ||
declare const kSend: unique symbol; | ||
export declare class MessageEvent extends Event { | ||
@@ -61,2 +63,3 @@ readonly data: ArrayBuffer | string; | ||
send(message: ArrayBuffer | string): void; | ||
[kSend](message: ArrayBuffer | string): void; | ||
close(code?: number, reason?: string): void; | ||
@@ -63,0 +66,0 @@ [kClose](code?: number, reason?: string): void; |
@@ -44,2 +44,3 @@ var __create = Object.create; | ||
// packages/web-sockets/src/couple.ts | ||
var import_events = __toModule(require("events")); | ||
var import_shared2 = __toModule(require("@miniflare/shared")); | ||
@@ -80,2 +81,3 @@ var import_ws = __toModule(require("ws")); | ||
var kClosed = Symbol("kClosed"); | ||
var kSend = Symbol("kSend"); | ||
var kClose = Symbol("kClose"); | ||
@@ -122,2 +124,5 @@ var WebSocket = class extends import_shared.InputGatedEventTarget { | ||
} | ||
this[kSend](message); | ||
} | ||
[kSend](message) { | ||
if (this[kClosed]) { | ||
@@ -186,15 +191,6 @@ throw new TypeError("Can't call WebSocket send() after close()."); | ||
ws.on("message", (message, isBinary) => { | ||
if (isBinary) { | ||
pair.send((0, import_shared2.viewToBuffer)(message)); | ||
} else { | ||
pair.send(message.toString()); | ||
if (!pair[kClosed]) { | ||
pair[kSend](isBinary ? (0, import_shared2.viewToBuffer)(message) : message.toString()); | ||
} | ||
}); | ||
ws.on("close", (code, reason) => { | ||
if (!pair[kClosed]) | ||
pair[kClose](code, reason.toString()); | ||
}); | ||
ws.on("error", (error) => { | ||
pair.dispatchEvent(new ErrorEvent("error", { error })); | ||
}); | ||
pair.addEventListener("message", (e) => { | ||
@@ -213,20 +209,15 @@ ws.send(e.data); | ||
if (ws.readyState === import_ws.default.CONNECTING) { | ||
await new Promise((resolve, reject) => { | ||
ws.once("open", () => { | ||
pair.accept(); | ||
pair[kCoupled] = true; | ||
ws.off("close", reject); | ||
ws.off("error", reject); | ||
resolve(); | ||
}); | ||
ws.once("close", reject); | ||
ws.once("error", reject); | ||
}); | ||
} else { | ||
pair.accept(); | ||
pair[kCoupled] = true; | ||
if (ws.readyState >= import_ws.default.CLOSING) { | ||
throw new TypeError("Incoming WebSocket connection already closed."); | ||
} | ||
await (0, import_events.once)(ws, "open"); | ||
} else if (ws.readyState >= import_ws.default.CLOSING) { | ||
throw new TypeError("Incoming WebSocket connection already closed."); | ||
} | ||
pair.accept(); | ||
pair[kCoupled] = true; | ||
ws.on("close", (code, reason) => { | ||
if (!pair[kClosed]) | ||
pair[kClose](code, reason.toString()); | ||
}); | ||
ws.on("error", (error) => { | ||
pair.dispatchEvent(new ErrorEvent("error", { error })); | ||
}); | ||
} | ||
@@ -233,0 +224,0 @@ |
{ | ||
"name": "@miniflare/web-sockets", | ||
"version": "2.8.1", | ||
"version": "2.9.0-next.1", | ||
"description": "WebSocket module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -38,4 +38,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@miniflare/core": "2.8.1", | ||
"@miniflare/shared": "2.8.1", | ||
"@miniflare/core": "2.9.0-next.1", | ||
"@miniflare/shared": "2.9.0-next.1", | ||
"undici": "5.9.1", | ||
@@ -45,5 +45,5 @@ "ws": "^8.2.2" | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.8.1", | ||
"@miniflare/shared-test": "2.9.0-next.1", | ||
"@types/ws": "^8.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20102
386
1
+ Added@miniflare/core@2.9.0-next.1(transitive)
+ Added@miniflare/queues@2.9.0-next.1(transitive)
+ Added@miniflare/shared@2.9.0-next.1(transitive)
+ Added@miniflare/watcher@2.9.0-next.1(transitive)
- Removed@miniflare/core@2.8.1(transitive)
- Removed@miniflare/queues@2.8.1(transitive)
- Removed@miniflare/shared@2.8.1(transitive)
- Removed@miniflare/watcher@2.8.1(transitive)
Updated@miniflare/core@2.9.0-next.1