Skip to content

Commit

Permalink
Accept ws requests
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Dec 2, 2024
1 parent fcf4e86 commit 52faa72
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/cf/counter-actor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cf/counter-actor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"wrangler": "^3.91.0"
},
"dependencies": {
"@deco/actors": "npm:@jsr/deco__actors@^0.14.0-beta.8",
"@deco/actors": "npm:@jsr/deco__actors@^0.14.0-beta.9",
"hono": "^4.6.12"
}
}
4 changes: 4 additions & 0 deletions examples/cf/counter-actor/src/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export class Counter {
return this.watchTarget.subscribe();
}
chan(name: string): ChannelUpgrader<string, string> {
console.log("HERE");
return (async ({ send, recv }) => {
console.log("HERE1");
await send(`Hello ${name}`);
console.log("Sent Hello");
for await (const str of recv()) {
console.log({ str });
if (str === "PING") {
await send("PONG");
}
Expand Down
6 changes: 1 addition & 5 deletions examples/cf/counter-actor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ export { ActorDurableObject } from "@deco/actors/cf";
const app = new Hono<{ Bindings: Env }>();

const runtime = new ActorCfRuntime([Counter]);
const mid = withActors(runtime)
app.use(async (ctx, next) => {
await mid(ctx, next);
console.log(await ctx.res.text())
});
app.use(withActors(runtime));

app.get("/", (c) => c.text("Hello Cloudflare Workers!"));

Expand Down
1 change: 1 addition & 0 deletions src/actors/runtimes/cf/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ActorCfRuntime implements ActorFetcher<Env> {
registerActors(actorsConstructors, () => {
const webSocketPair = new WebSocketPair();
const [client, server] = Object.values(webSocketPair);
server.accept();
return {
socket: server,
response: new Response(null, {
Expand Down

0 comments on commit 52faa72

Please sign in to comment.