Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support web sockets with hyper binding #10211

Closed
ry opened this issue Apr 16, 2021 · 1 comment · Fixed by #10359
Closed

Support web sockets with hyper binding #10211

ry opened this issue Apr 16, 2021 · 1 comment · Fixed by #10359
Labels
feat new feature (which has been agreed to/accepted) public API related to "Deno" namespace in JS runtime Relates to code in the runtime crate

Comments

@ry
Copy link
Member

ry commented Apr 16, 2021

Probably looks like this:

let { respondWith, request } = await httpConn.nextRequest();
let { ws, response } = Deno.serveWebsocket(request);
respondWith(response);
// use web standard ws

Should use tungstenite

Probably this should proceed #10210

@lucacasonato lucacasonato added feat new feature (which has been agreed to/accepted) public API related to "Deno" namespace in JS runtime Relates to code in the runtime crate labels Apr 20, 2021
@axetroy
Copy link
Contributor

axetroy commented Apr 21, 2021

why not use something like upgrader for Upgrade the protocol?

Maybe such code is less intrusive, It can work well with the HTTP interface.

import { serve } from "https://deno.land/std/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");

const upgrader = Deno.upgrader({
  maxBuff: 1024 * 1024 * 20
  // and other config
})

for await (const req of s) {
	if (req.url.pathname === '/v1/api/ws') {
          // upgrade protocol
		  const conn = upgrader.upgrade(req)
	  
		  for await (const msg of conn.readMessage()) {
			  // accpet message from client then echo hello world
			  conn.writeString("Hello World\n")
	      }
    } else {
		req.respond({ body: "Hello World\n" });
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) public API related to "Deno" namespace in JS runtime Relates to code in the runtime crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants