You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{DurableObject}from"cloudflare:workers";exportclassWebSocketManagerextendsDurableObject{asyncfetch(request){// Creates two ends of a WebSocket connection.constwebSocketPair=newWebSocketPair();const[client,server]=Object.values(webSocketPair);// Calling `acceptWebSocket()` informs the runtime that this WebSocket is to begin terminating// request within the Durable Object. It has the effect of "accepting" the connection,// and allowing the WebSocket to send and receive messages.// Unlike `ws.accept()`, `state.acceptWebSocket(ws)` informs the Workers Runtime that the WebSocket// is "hibernatable", so the runtime does not need to pin this Durable Object to memory while// the connection is open. During periods of inactivity, the Durable Object can be evicted// from memory, but the WebSocket connection will remain open. If at some later point the// WebSocket receives a message, the runtime will recreate the Durable Object// (run the `constructor`) and deliver the message to the appropriate handler.this.ctx.acceptWebSocket(server);returnnewResponse(null,{status: 101,webSocket: client,});}asyncwebSocketMessage(ws,message){// Upon receiving a message from the client, reply with the same message,// but will prefix the message with "[Durable Object]: " and return the// total number of connections.ws.send(`[Durable Object] message: ${message}, connections: ${this.ctx.getWebSockets().length}`,);}asyncwebSocketClose(ws,code,reason,wasClean){// If the client closes the connection, the runtime will invoke the webSocketClose() handler.ws.close(code,"Durable Object is closing WebSocket");}}
Here is my wrangler.toml
[durable_objects]
bindings = [{ name = "WEBSOCKET_MANAGER", class_name = "WebSocketManager" }]
[[migrations]]
tag = "v1"new_classes = ["WebSocketManager"]
What is the expected behavior?
I am suppose to connect, send a message through websocket and receive an answer back from it.
What do you see instead?
I can connect to the websocket, but if I send anything, I have no answer back or any errors.
The main issue is that webSocketMessage is never triggered....
Additional information
I have deployed this Durable object online, but still having the same behaviour.
Does Hono go through some specific process I am not aware of?
Is the controller part correct?
The text was updated successfully, but these errors were encountered:
What version of Hono are you using?
4.5.2
What runtime/platform is your app running on?
Cloudflare Worker
What steps can reproduce the bug?
Here is my route
Here is the controller
Here is my durable Object coming from Cloudflare docs... https://developers.cloudflare.com/durable-objects/examples/websocket-hibernation-server/
Here is my wrangler.toml
What is the expected behavior?
I am suppose to connect, send a message through websocket and receive an answer back from it.
What do you see instead?
I can connect to the websocket, but if I send anything, I have no answer back or any errors.
The main issue is that webSocketMessage is never triggered....
Additional information
I have deployed this Durable object online, but still having the same behaviour.
Does Hono go through some specific process I am not aware of?
Is the controller part correct?
The text was updated successfully, but these errors were encountered: