https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • p

    PhilipA

    03/06/2021, 9:25 PM
    Can a DO initiate a websocket connection?
  • r

    Robin

    03/07/2021, 8:42 PM
    1. Hey, can't remember about the DO storage limits regarding key and value size: are they the same as KV's? 2. And to confirm, calling a DO via as stub from another DO counts as part of the global sub-requests limitations? Which is then 50 calls? Thanks!
  • r

    Robin

    03/07/2021, 8:44 PM
    Not sure, I believe someone already asked this question on the discord, something with some standard websocket class not supported -feel free to use the search! 🙂
  • r

    Robin

    03/07/2021, 8:44 PM
    +1 I'm currently having to implement a workaround that same limitation
  • e

    eidam | SuperSaaS

    03/07/2021, 8:48 PM
    1. key 2048 bytes, value 32KiB https://developers.cloudflare.com/workers/runtime-apis/durable-objects#transactional-storage-api
  • r

    Robin

    03/07/2021, 8:49 PM
    dang me! I read that section like 10 min ago, just totally avoided the put() section
  • r

    Robin

    03/07/2021, 8:50 PM
    (got stuck on the "limitation" section of the doc)
  • p

    PhilipA

    03/07/2021, 11:10 PM
    Yes - I saw that the Websocket constructor has not been implemented - was wondering if WebSocketPair in DO had some functionality to replicate it..
  • k

    kenton

    03/08/2021, 6:54 PM
    If you make a request using
    fetch()
    and set the header
    Upgrade: websocket
    , the system will automatically add the other stuff to perform a WebSocket handshake. If the server fulfills its end of the handshake, then the response object will have a
    webSocket
    member. Call
    .accept()
    on it to indicate you wish to handle it locally, and then you can call
    send()
    and add event handlers like normal.
  • g

    Greg Brimble | Cloudflare Pages

    03/08/2021, 7:50 PM
    cc @User
  • p

    PhilipA

    03/08/2021, 8:02 PM
    Thanks @kenton. Appreciate your help.
  • k

    kenton

    03/08/2021, 8:51 PM
    (obviously we need to get that documented somewhere....)
  • c

    Ceru ©

    03/08/2021, 10:55 PM
    Woo
  • c

    Ceru ©

    03/08/2021, 10:55 PM
    Heck yess
  • c

    Ceru ©

    03/08/2021, 11:03 PM
    im adding this to CFW-EU asap
  • c

    Ceru ©

    03/08/2021, 11:28 PM
    doesnt seem this API is available in Workers, is this a DO only feature?
  • k

    kenton

    03/08/2021, 11:29 PM
    no, it should work for everyone
  • c

    Ceru ©

    03/08/2021, 11:29 PM
    ah then maybe my nearest PoP doesnt support it yet
  • c

    Ceru ©

    03/09/2021, 2:32 AM
    ok so, this is what im running into right now
    Copy code
    js
      var url = 'wss://echo.websocket.org'
      var resp = await fetch(url, { headers: {'upgrade': 'websocket'} })
      // resp.webSocket is null
  • c

    Ceru ©

    03/09/2021, 2:46 AM

    https://nyc3.digitaloceanspaces.com/cerulean/screenshots/2021/03/firefox_wEa6pgpUWe.png▾

  • a

    ai

    03/09/2021, 3:06 AM
    the URL needs to be http I think
  • a

    ai

    03/09/2021, 3:07 AM
    remember you're upgrading from http to wss, not connecting to wss directly
  • a

    ai

    03/09/2021, 3:13 AM
    I may also be wrong, and it could be that websocket.org doesn't support
    wss
    , just
    ws
    .
  • c

    Ceru ©

    03/09/2021, 3:13 AM
    thats the example URL they give
  • c

    Ceru ©

    03/09/2021, 3:14 AM
    and i can confirm it works
  • c

    Ceru ©

    03/09/2021, 3:14 AM
    however changing it to HTTPS doesnt change the situation
  • c

    Ceru ©

    03/09/2021, 3:14 AM
  • a

    ai

    03/09/2021, 3:18 AM
    Yeah, the example URL they give is for the living standard WebSocket API, which does the http -> ws upgrade step for you as part of the connection process:
    Copy code
    To establish a WebSocket connection, given a url, protocols, and client, run these steps:
        Let requestURL be a copy of url, with its scheme set to "http", if url’s scheme is "ws", and to "https" otherwise.
  • c

    Ceru ©

    03/09/2021, 3:19 AM
    either way, doesnt seem to be working
  • c

    Ceru ©

    03/09/2021, 3:19 AM
    from what i can tell, CF is intercepting the websocket connection and throwing a 502 in its place
1...262728...567Latest