Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Added WebSocket types #100

Closed
wants to merge 2 commits into from
Closed

Conversation

benycodes
Copy link

Added the following:

interface WebSocket {
  accept(): void;
}

declare class WebSocketPair {
  0: WebSocket;
  1: WebSocket;
}

interface ResponseInit {
  webSocket?: WebSocket;
}

Closes:
#84

@benycodes
Copy link
Author

@koeninger

@vicary
Copy link

vicary commented Jul 27, 2021

@benycodes Should ResponseInit be Response?

@RamIdeas
Copy link

RamIdeas commented Aug 7, 2021

@benycodes Should ResponseInit be Response?

No. ResponseInit is the 2nd param to the Response constructor and you pass the 'client' websocket from the WebSocketPair as the webSocket property of ResponseInit

@ItsWendell
Copy link

@benycodes Thanks for doing this, in response to @vicary and @RamIdeas, the Response object should also be able to return a webSocket.

For example, if you have a connection from your worker to a durable object through WebSockets (or another WebSocket server), the fetch request to upgrade that connection to WebSockets will return the webSocket property in the Response.

So yes, we should have webSocket in Response too.

@vicary
Copy link

vicary commented Aug 9, 2021

@ItsWendell thanks for the clarification. Yes, it makes sense to include webSocket in both Response and ResponseInit.

index.d.ts Outdated Show resolved Hide resolved
Co-authored-by: Alaa Zorkane <Alaazorkane@gmail.com>
Comment on lines +722 to +725
declare class WebSocketPair extends Array {
0: WebSocket;
1: WebSocket;
}
Copy link
Contributor

@lukeed lukeed Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I see that there's been back and forth on this, but this actually isn't correct. Extending an Array means that this could be possible, which it isn't:

let [client, server] = new WebSocketPair;

The correct solution is to do the equivalent of what worktop does, which is this:

Suggested change
declare class WebSocketPair extends Array {
0: WebSocket;
1: WebSocket;
}
declare const WebSocketPair: {
new(): {
0: WebSocket;
1: WebSocket;
};
};

Here's a Playground to see the differences.

@mrkldshv
Copy link
Contributor

I see this hasn't been touched for some time. Would that be okay if I take over this PR or create a new one?

@lukeed
Copy link
Contributor

lukeed commented Sep 17, 2021

No reason for another PR here, thank you though. There's some other work being done wrt types right now, hence the temporary pause.

@mrbbot mrbbot mentioned this pull request Sep 24, 2021
threepointone added a commit that referenced this pull request Sep 30, 2021
Auto-Generated Types

Types are now automatically generated with releases by parsing the runtime's source code, and merging in overrides/docs defined in this repository (for generics, overloads, comments, etc).

webworker no longer needs to (and shouldn't) be included in tsconfig lib.

The final merged AST that's used to render the TypeScript types, workers.json, is also included in the repository. This could be used to generate bindings for other languages that compile to WebAssembly. Rust output is coming soon.

Closes: #55, #75, #76, #81, #84, #96, #97, #100, #101, #102, #105, #106, #107, #108
@mrbbot
Copy link
Contributor

mrbbot commented Sep 30, 2021

#112 has now been merged, which includes the new WebSocket and WebSocketPair types.

@mrbbot mrbbot closed this Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants