drashland / wocket

A WebSocket library for Deno
MIT License
104 stars 4 forks source link

Upgrade websocket approach #132

Closed crookse closed 2 years ago

crookse commented 2 years ago

The new server in this PR uses all of the same logic that we currently use in the server.ts file. Only difference is it doesn't use the ws module. It uses the the native HTTP server and Deno.upgradeWebSocket()

How to use:

$ deno run -A new_server.ts
$ deno
// Open a connection -- Deno.upgradeWebSocket should take care of opening the socket connection
const w = new WebSocket("ws://localhost:1447");

// Send a message to the "test" channel
w.send(`{"channel":"test", "message": {"hello":"world"}}`);

// Close the client -- you should see logging that shows that the client was deleted from the clients map
w.close();