feat: rooms broadcast-hub primitive, auto-provided to handlers
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+68
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
} from './metadata';
|
||||
import { getArgs, getHandlerNeeds, resolveArgs } from './params';
|
||||
import { connectLink, type Link } from './mesh/link';
|
||||
import { Rooms } from './rooms';
|
||||
import { buildRemote } from './mesh/teacup';
|
||||
import { buildManifest, createMeshControl } from './mesh/teapot';
|
||||
import type { MeshControl } from './http';
|
||||
@@ -126,6 +127,14 @@ export function createApp(opts: { modules: Ctor[]; plugins?: Plugin[]; mesh?: Me
|
||||
setRunner(n.name, n.run);
|
||||
}
|
||||
|
||||
// built-in: auto-provide a shared Rooms instance (unless the user declares one)
|
||||
if (!runners.has('rooms')) {
|
||||
const roomsInstance = new Rooms();
|
||||
providerNodes.push({ name: 'rooms', needs: [], provides: ['rooms'], origin: 'builtin' });
|
||||
providerMeta.set('rooms', { optional: false });
|
||||
setRunner('rooms', () => ({ rooms: roomsInstance })); // merge object -> ctx.rooms
|
||||
}
|
||||
|
||||
// For each route, resolve which providers/steps feed it via topo order.
|
||||
// MVP: every route depends on every declared step + provider in the app graph.
|
||||
// For mesh apps, finalize is DEFERRED to listen() so remote scopes can join the graph first.
|
||||
|
||||
@@ -16,6 +16,7 @@ export { needs, ctx, param, query, body, headers } from './params';
|
||||
export type { Query, Headers, Context, ArgSpec } from './params';
|
||||
export { channel, isAsyncIterable } from './channel';
|
||||
export type { Channel } from './channel';
|
||||
export { Rooms } from './rooms';
|
||||
export { Sse, Ws, Stream, Post, Put, Patch, Delete } from './metadata';
|
||||
export type { Transport, HttpMethod } from './metadata';
|
||||
export { inbound, abort } from './params';
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { channel, type Channel } from './channel';
|
||||
|
||||
export class Rooms {
|
||||
private readonly hubs = new Map<string, Channel<unknown>>();
|
||||
room<T = unknown>(name: string): Channel<T> {
|
||||
let hub = this.hubs.get(name);
|
||||
if (!hub) { hub = channel<unknown>(); this.hubs.set(name, hub); }
|
||||
return hub as unknown as Channel<T>;
|
||||
}
|
||||
names(): string[] { return [...this.hubs.keys()]; }
|
||||
}
|
||||
Reference in new issue
Block a user