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

    vans163

    04/14/2021, 2:32 AM
    seems the websockets from durableobjects dont negotiate it
  • v

    vans163

    04/14/2021, 2:54 AM
    sending to a websocket is not working for me if the request that calls websocket.send originated from a POST request, could that be right?
  • v

    vans163

    04/14/2021, 2:54 AM
    a POST request into a durable object triggers a broadcast
  • v

    vans163

    04/14/2021, 2:54 AM
    (if that cant be right it might be some other bug i got)
  • v

    vans163

    04/14/2021, 3:06 AM
    ah
  • v

    vans163

    04/14/2021, 3:07 AM
    it seems a crash inside a function in a DO does not report error in all cases
  • v

    vans163

    04/14/2021, 3:07 AM
    trying to reference an undefined does not report any errors
  • v

    vans163

    04/14/2021, 3:07 AM
    state = {tmp: {limit: 50}} state.tmp.jobs.length <<< this does not throw, silently fails with no error
  • v

    vans163

    04/14/2021, 3:12 AM
    yup ignore that above about the POST, it was a mistake on my part that DOs do not throw under
  • r

    robert

    04/14/2021, 4:59 AM
    i'm trying to delete a durable object with
    wrangler publish --delete-class Counter
    but I get this error:
    Copy code
    "code": 10061,
      "message": "Cannot create binding for class Counter because it is not currently configured to implement durable objects. Did you forget to apply a --new-class migration to it?"
    (wrangler version
    1.15.0-custom-builds-rc.2
    with repo: https://github.com/cloudflare/durable-objects-template) any thoughts?
  • n

    nightvisi0n

    04/14/2021, 6:10 AM
    Thanks for this super detailed explanation! 🙂
  • n

    nightvisi0n

    04/14/2021, 10:45 AM
    @User As you proposed I tried to get the
    request.cf
    value directly at the eyeball request, but it seems it's not available there as well. I created a minimal example based on the
    durable-objects-rollup-esm
    template to reproduce this: https://gist.github.com/nightvisi0n/48c4844a0a81103c31c5071383889cda (I stripped away everything related to DO for simplicity)
  • m

    mehdiiii

    04/14/2021, 12:26 PM
    Curious to know answers to these! I'd like to build a similar thing but in my mind I am treating a "room" as a durable object instance, and in that case 128mb of memory is quite generous.
  • a

    alex.b

    04/14/2021, 1:36 PM
    looks like a couple of my questions around websockets were answered in a docs last night https://github.com/cloudflare/cloudflare-docs/blob/production/products/workers/src/content/learning/using-websockets.md
  • v

    vans163

    04/14/2021, 1:56 PM
    a neat trick here is you can pass authentication/initial messages as 2nd param in form of list
  • v

    vans163

    04/14/2021, 1:57 PM
  • v

    vans163

    04/14/2021, 1:57 PM
    so 1 step handshake vs 3 way
  • j

    jed

    04/14/2021, 1:59 PM
    the docs create a WebSocket like this:
    Copy code
    const webSocketPair = new WebSocketPair()
    const [client, server] = Object.values(webSocketPair)
    any particular reason it's not just this?
    Copy code
    const [client, server] = new WebSocketPair()
  • v

    vans163

    04/14/2021, 2:02 PM
    i think cuz the pair is [0] and [1]
  • v

    vans163

    04/14/2021, 2:02 PM
    so the keys would be numeric
  • v

    vans163

    04/14/2021, 2:02 PM
    webSocketPair = {0: client, 1: server}
  • v

    vans163

    04/14/2021, 2:02 PM
    oh i see you used square brackets, does ES6 understand taht and automagically take the values?
  • v

    vans163

    04/14/2021, 2:03 PM
    regardless thats very confusing code to look at, since youl assume WebSocketPair is a list after 3 months revisiting your code
  • j

    jed

    04/14/2021, 2:03 PM
    i don't see any sense in having
    WebSocketPair
    return a non-iterable with numeric keys.
  • j

    jessepmason

    04/14/2021, 2:04 PM
    Let's say I have a DO for each user but I also have a DO for a game they are playing. Are two different websocket connections recommended for the client? Or one websocket connection to the user DO and the game sends w.e websocket messages to the users DO?
  • j

    jed

    04/14/2021, 2:04 PM
    imagine if you had to do this with React hooks:
    Copy code
    const state = useState(0)
    const [count, setCount] = Object.values(state)
  • v

    vans163

    04/14/2021, 2:13 PM
    i think its a minor detail regardless wonder if theres a reason for using a object vs a list
  • j

    jed

    04/14/2021, 2:16 PM
    it's needlessly unergonomic.
  • j

    jed

    04/14/2021, 2:16 PM
    cloudflare folks, consider adding this to the WebsocketPair class:
    Copy code
    js
      *[Symbol.iterator]() {
        yield* Object.values(this)
      }
  • j

    jed

    04/14/2021, 2:17 PM
    then destructuring will work without the
    Object.values
    call.
1...585960...567Latest