Point0by 1gr14
  • Menu
    • GitHub
    • Blog
  • Introduction
    • Overview
    • Getting Started
    • Full Overview
    • Benchmarks
    • Points
  • Points
    • Page
    • Layout
    • Component
    • Provider
    • Mountable
    • Query
    • Infinite Query
    • Mutation
    • Action
    • Subscription
    • Root
    • Base
    • Plugin
  • Methods
    • Validation
    • Loader
    • Context
    • Middleware
    • Loading & error
    • .with
    • Mapper
    • Transformer
    • Stage Methods
  • Core
    • Navigation
    • SSR
    • RSC
    • Socket
    • Request
    • Response
    • Error handling
    • Env
    • Head
    • MDX
    • Assets
    • File upload
    • OpenAPI
    • Query client
    • Events
    • Infer
  • Engine
    • Engine Config
    • Engine Runtime
    • CLI
    • Dev
    • Build
    • Compiler
    • Generator
    • Project MCP
    • Docs MCP
    • Importer
    • Public dir
    • Testing
    • Deploy
    • Bun or Vite
  • Extra
    • SsrStore
    • CookieStore
    • Basic Auth
    • CORS
    • Cache-Control
    • Compress
  • Examples
    • Basic
    • Vite
    • Better Auth
    • Socket
    • Capacitor
    • Expo
  • 1gr14
    • Home
    • Start0
    • Support
    • Education
    • Blog
    • Author
  • Community
    • Discord
    • Telegram
  • Open Source
    • Point0
    • Route0
    • Error0
    • Flat
  • Account
    • Sign In
    • Sign Up
Point0by 1gr14
Building open-source software for the glory of the Lord Jesus Christ ☦️
With love for developers of all backgrounds around the world ❤️
Terms of ServicePrivacy PolicySergei Dmitriev 2026 😎

Socket Example

  • Category: Examples
GitHub DevGitHub Source

examples/socket is a small app built around channels, spaces & handlers: four pages, each one a complete socket feature in a single file. The buttons above and below open the full source.

The shared piece is one channel (src/lib/channel.tsx): the connector reads a nickname cookie and returns it as the connection identity — no cookie, and the connect is denied with preventRetry, so a signed-out client stops knocking until the sign-in calls reconnectAll(). The channel is resumable: true, and one <appChannel.Connection> at the app root (src/app.client.tsx) holds the socket for the whole app (gate={false} — the sign-in header renders before any connect; each page holds its own live section with gate instead, so it shows the channel's loading until the connect settles, then the interface or the deny). Everything else lives in the page that uses it — the space, its handlers, and its server code sit next to the component that renders them, and the compiler strips each side out of the other bundle:

  • pages/chat.tsx — topics with persisted messages (each topic is one room of the space): a .joiner that admits by topic name (with a clean deny), a serverHandler that writes to Prisma and pushes to the room, a buffering clientHandler (resumable: true), and the one-condition catch-up — onEnter: ({ gapless }) => gapless || refetch().
  • pages/presence.tsx — who is in the room right now: the presence recipe as written — the pointSpaceJoinServerSuccess / pointSpaceLeaveServer events compute the roster once and push it, a .query()-flavored handler serves the first paint, and the push lands via setSocketQueryData with zero refetches.
  • pages/notifications.tsx — a personal room per user: an enroller-only space (no .joiner — nobody joins from the browser), pushed to from a plain HTTP mutation.
  • pages/board.tsx — one shared, DB-less room: a global space (joiner(() => ({}))) and a bare space-wide push fanning every click out.

The engine side is one option — server: { socket: true } in src/engine.ts — which also turns the socket feature on for the client bundle. There is no backplane configured: a single process needs none (add backplane: process.env.REDIS_URL when you run several — see the backplane).

Sign-in is deliberately primitive — a nickname cookie, no passwords (src/lib/auth.tsx): the point is what happens at connect time, not the auth stack. The header's sign-in / sign-out buttons call reconnectAll() / disconnectAll() — the client half of a login flow (src/layouts/general.tsx).

Run it like basic:

cd examples/socket
bun install
bun run setup
bun run dev

Open two browser windows side by side to see the pushes cross. The tests/ folder drives the same scenarios in a real browser with Playwright — chat.e2e.test.ts (a cross-tab room push, the resume streams replaying a blip, a reload showing the persisted history) and presence.e2e.test.ts (the roster reacting to joins and leaves):

bun run test
GitHub DevGitHub Source
PreviousBetter Auth ExampleNextCapacitor Example

Enjoying Point0?

Give it a star on GitHub, ask questions, and follow what's new

Star Point0

A star on GitHub helps more developers find Point0
Star on GitHub

Start0

Point0 integrated into the Start0 SaaS boilerplate — the best way to use it
Explore Start0

YouTube

Tutorials, walkthroughs, and updates
YouTube

Discord

Questions and chat in English
Join Discord

Telegram

News channel and chat in Russian
ChannelChat

Twitter

Posts and updates
Twitter