Skip to content

Commit

Permalink
Ensure callbacks are registered before responding the request
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Jun 17, 2024
1 parent ea7c7dc commit df2b489
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deco/warp",
"version": "0.2.6",
"version": "0.2.7",
"exports": "./mod.ts",
"tasks": {
"check": "deno fmt && deno lint && deno check mod.ts"
Expand Down
21 changes: 11 additions & 10 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ export const serveHandler = (
const url = new URL(req.url);
if (url.pathname === connectPath) {
const { socket, response } = Deno.upgradeWebSocket(req);
const clientVersion = url.searchParams.get(CLIENT_VERSION_QUERY_STRING);
const chPromise = clientVersion === null
? makeWebSocket<ServerMessage, ClientMessage, string>(
socket,
jsonSerializer(),
)
: makeWebSocket<ServerMessage, ClientMessage, ArrayBuffer>(
socket,
dataViewerSerializer(),
);
(async () => {
const clientVersion = url.searchParams.get(CLIENT_VERSION_QUERY_STRING);
const ch = clientVersion === null
? await makeWebSocket<ServerMessage, ClientMessage, string>(
socket,
jsonSerializer(),
)
: await makeWebSocket<ServerMessage, ClientMessage, ArrayBuffer>(
socket,
dataViewerSerializer(),
);
const ch = await chPromise;
const clientId = crypto.randomUUID();
const hosts: string[] = [];
const state: ServerConnectionState = {
Expand Down

0 comments on commit df2b489

Please sign in to comment.