lukejacksonn
lukejacksonn
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Forgot to say thanks for all your assistance here @Milan 🙇‍♂️
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
For future folks with this issue.. Add this code to your DO constructor:
this.state.setWebSocketAutoResponse(
new WebSocketRequestResponsePair("ping", "pong")
);
this.state.setWebSocketAutoResponse(
new WebSocketRequestResponsePair("ping", "pong")
);
Then on the client (the browser in this case):
ws.send("ping")
ws.send("ping")
You should get back a pong message but the DO webSocketMessage will not be called in response to pings (which I assume confrims that the application is handling that request rather than waking up the socket from hibernation).
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
That seems to work now.. it is pinging and ponging without me having to handle those messages explicitly in the webSocketMessage handler
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Ahh silly me, I was doing ws.send("foo") from the client.. but to the worker I had yet to set the auto response on 🤦‍♂️
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
So that resolved the type arror and the code now runs on the server ✅ but (and excuse my ignorance here) but how do I send a foo request from the client?
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Oh great, thank you so much for taking the time! I will try that out
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Ok no worries!
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
which I thought I saw somewhere.. but it throws:
Uncaught (in response) TypeError: Failed to execute 'setWebSocketAutoResponse' on 'DurableObjectState': parameter 1 is not of type 'WebSocketRequestResponsePair'.
Uncaught (in response) TypeError: Failed to execute 'setWebSocketAutoResponse' on 'DurableObjectState': parameter 1 is not of type 'WebSocketRequestResponsePair'.
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
I tried:
session.setWebSocketAutoResponse({
request: "ping",
response: "pong"
})
session.setWebSocketAutoResponse({
request: "ping",
response: "pong"
})
18 replies
CDCloudflare Developers
Created by lukejacksonn on 10/24/2024 in #durable-objects
Hey 👋 I have a DO based off of this
Thanks for the answer! Ok so I think I understood that.. do you have an example of the syntax to use for the setWebSocketAutoResponse call and the message that the clinet needs to send?
18 replies