fix(deno): decode binary ws frames to match Node; changelog ctx.req note
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+14
-2
No files matched your search
@@ -17,6 +17,12 @@ green-tea uses calendar versioning: `YY.MM.PATCH`.
|
|||||||
### Changed
|
### Changed
|
||||||
- App-scope providers now boot exactly once (memoized): a second `app.listen()`
|
- App-scope providers now boot exactly once (memoized): a second `app.listen()`
|
||||||
call no longer re-runs provider factories or their side effects.
|
call no longer re-runs provider factories or their side effects.
|
||||||
|
- **`WsOpenCtx.req`** (available in `@Ws`/`@Sse` handlers) is now a neutral
|
||||||
|
`WsRequest` (`{ url, headers, protocol, ip }`) instead of the Node
|
||||||
|
`http.IncomingMessage`, so it works the same across Node and Deno. Node-only
|
||||||
|
fields such as `req.socket` / `req.rawHeaders` are no longer available on
|
||||||
|
`ctx.req`; use `ctx.protocol` / `ctx.ip` / `ctx.query` / `ctx.headers`
|
||||||
|
instead — all still provided.
|
||||||
|
|
||||||
## [26.7.0-beta.0] - 2026-07-07
|
## [26.7.0-beta.0] - 2026-07-07
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -6,12 +6,13 @@ import type { WsSocket, WsRequest } from './http/ws-core';
|
|||||||
// doesn't declare a global `WebSocket` either — so we ambient-declare just the shape we use
|
// doesn't declare a global `WebSocket` either — so we ambient-declare just the shape we use
|
||||||
// (both the instance interface and the `OPEN` static, mirroring the real WebSocket).
|
// (both the instance interface and the `OPEN` static, mirroring the real WebSocket).
|
||||||
interface WebSocketEventMap {
|
interface WebSocketEventMap {
|
||||||
message: { data: unknown };
|
message: { data: string | ArrayBuffer };
|
||||||
close: object;
|
close: object;
|
||||||
error: object;
|
error: object;
|
||||||
}
|
}
|
||||||
interface WebSocket {
|
interface WebSocket {
|
||||||
readonly readyState: number;
|
readonly readyState: number;
|
||||||
|
binaryType: string;
|
||||||
send(data: string): void;
|
send(data: string): void;
|
||||||
close(code?: number, reason?: string): void;
|
close(code?: number, reason?: string): void;
|
||||||
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (event: WebSocketEventMap[K]) => void): void;
|
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (event: WebSocketEventMap[K]) => void): void;
|
||||||
@@ -58,7 +59,12 @@ function toWsRequest(request: Request, info: DenoServeHandlerInfo): WsRequest {
|
|||||||
function denoSocket(ws: WebSocket): WsSocket {
|
function denoSocket(ws: WebSocket): WsSocket {
|
||||||
const inbound = channel<unknown>();
|
const inbound = channel<unknown>();
|
||||||
const ac = new AbortController();
|
const ac = new AbortController();
|
||||||
ws.addEventListener('message', (e) => inbound.push(typeof e.data === 'string' ? e.data : String(e.data)));
|
ws.binaryType = 'arraybuffer';
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
ws.addEventListener('message', (e) => {
|
||||||
|
const data = e.data;
|
||||||
|
inbound.push(typeof data === 'string' ? data : decoder.decode(data as ArrayBuffer));
|
||||||
|
});
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', () => {
|
||||||
inbound.close();
|
inbound.close();
|
||||||
ac.abort();
|
ac.abort();
|
||||||
|
|||||||
Reference in new issue
Block a user