Open monotter opened 2 years ago
This is a great library! I have the same problem with Oak, any guidance from Sono core team?
I also like to use Sono with Oak. Why there is no response from core team? Is this project dead?
I'm also interested in Oak support. Is support for this use-case planned? If not, is there an unsupported workaround?
For visibility, error output:
$ deno run -A src\main.ts
Server is running on http://localhost:9339
Request: Request {
hasBody: false,
headers: Headers {
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
connection: "Upgrade",
host: "localhost:9339",
origin: "http://localhost:9339",
pragma: "no-cache",
"sec-websocket-extensions": "permessage-deflate; client_max_window_bits",
"sec-websocket-key": "1hp25SiMNg7l+d5U4a21KA==",
"sec-websocket-version": "13",
upgrade: "websocket",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Sa"... 25 more characters
},
ip: "127.0.0.1",
ips: [],
method: "GET",
secure: false,
url: "http://localhost:9339/ws"
}
TypeError: Cannot read properties of undefined (reading 'write')
at writeAll (https://deno.land/std@0.96.0/io/util.ts:159:25)
at BufWriter.flush (https://deno.land/std@0.96.0/io/bufio.ts:470:13)
at writeResponse (https://deno.land/std@0.96.0/http/_io.ts:292:16)
at eventLoopTick (ext:core/01_core.js:168:7)
at async acceptWebSocket (https://deno.land/std@0.96.0/ws/mod.ts:447:5) err
The code:
import * as path from "https://deno.land/std/path/mod.ts";
import { Sono } from "https://deno.land/x/sono@v1.1/mod.ts";
import { Application, Router, send, Context } from "https://deno.land/x/oak@v12.5.0/mod.ts";
const app = new Application();
const router = new Router();
const sono = new Sono();
router.get("/ws", (context: Context) => {
if (!context.isUpgradable) {
context.throw(501);
}
try {
console.log(`Request:`, context.request);
sono.connect(context.request, () => {
sono.emit("new client connected");
});
} catch (error) {
console.error(`Faled to create Sono connection:`, error);
context.response.status = 500;
context.response.body = "Server Error";
}
});
app.use(router.routes());
app.use(router.allowedMethods());
app.use(async (context) => {
try {
const rootDir = path.resolve(Deno.cwd());
await send(context, context.request.url.pathname, {
root: `${rootDir}/public`,
index: "index.html",
});
} catch (error) {
console.error(`Failed to serve static content:`, error);
context.response.status = 404;
context.response.body = "Not Found! </3";
}
});
const port = 9339;
console.log(`Server is running on http://localhost:${port}`);
await app.listen({ port });
i made below code to make sono connection with oak
./Dependencies.ts
but it wont work because oak's
context.request.originalRequest
does not includesbufWriter
andbufReader