GithubHelp home page GithubHelp logo

Comments (6)

sepbot avatar sepbot commented on September 17, 2024 7
export {}

declare global {
  interface WebSocket {
    accept(): void;
  }

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

  interface ResponseInit {
    webSocket?: WebSocket;
  }
}

from workers-types.

hronro avatar hronro commented on September 17, 2024 3

Any updates?
Why those types are not included in this library?

from workers-types.

stof avatar stof commented on September 17, 2024

the doc is now available at https://developers.cloudflare.com/workers/runtime-apis/websockets

from workers-types.

helloimalastair avatar helloimalastair commented on September 17, 2024

Any updates?
Why those types are not included in this library?

Try adding a pull request, it might make it faster for them to make changes if all they have to do is review your code.

from workers-types.

OwenDelahoy avatar OwenDelahoy commented on September 17, 2024
export { }

declare global {
  interface CloudflareWebsocket {
    accept(): unknown;
    addEventListener(event: 'close', callbackFunction: (code?: number, reason?: string) => unknown): unknown;
    addEventListener(event: 'error', callbackFunction: (e: unknown) => unknown): unknown;
    addEventListener(event: 'message', callbackFunction: (event: { data: any }) => unknown): unknown;
    
    /**
     * @param code https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
     * @param reason
     */
    close(code?: number, reason?: string): unknown;
    send(message: string|Uint8Array): unknown;
  }

  class WebSocketPair {
    0: CloudflareWebsocket; // Client
    1: CloudflareWebsocket; // Server
  }

  interface ResponseInit {
    webSocket?: CloudflareWebsocket;
  }
}

from workers-types.

aboodman avatar aboodman commented on September 17, 2024

Warning to anyone else using these types:

Using sepbot's suggestion (#84 (comment)) has the effect of adding accept() to any pre-existing WebSocket definition. In most cases, this will be the standard DOM WebSocket in your code.

This would be fine if Cloudflare Workers actually implemented the complete WebSocket spec, but it doesn't. For example, the readyState property from the spec is not currently supported.

I suggest using instead something like OwenDelahoy's suggestion (#84 (comment)) will narrowly defines only the features actually supported by CF workers.

from workers-types.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.