/

Ambitwin · source-available, not open source · © 2026 Nicolò Ghignatti

Socket

Keywords on this page
WordMeaningExample
WebSocketA connection the browser keeps open, so the server can pushOne per open tab
RoomA group of connections that get the same messagesbuilding:{id}, domain:{name}
SubscribeA browser asks to join one building’s roomOpening the library page
Claims headerWho the caller is, set by the edgex-gateway-claims
Functional corePlain functions with no network, easy to test“which room is this message for?”
Imperative shellThe part that does the network work around the coreRedis, WebSocket

Realises part of the Telemetry Distribution domain, with dashboard: it carries live data to the people following a building. Rust, no database. Code-level page: Socket Service.


Who talks to it

flowchart LR
    D["dashboard"] -. "one feed per building" .-> S["socket"]
    N["notification"] -. "alerts" .-> S
    Tw["digital-twin"] -. "device dots" .-> S
    S -- "who owns this building?" --> Tw
    S <--> C["client, over WebSocket"]

Dotted: Redis.

Comes in onGoes to roomBrowser event
A building’s feedbuilding:{id}telemetry
notificationsdomain:{name}notification
A building’s device dotsbuilding:{id}Device positions

Messages pass through unread, apart from finding the room.


Inside

flowchart LR
    subgraph Shell["Shell: network work"]
        CON["Connect and subscribe"]
        LOOP["Redis listener"]
        LOOK["Ownership lookup, cached"]
        SWEEP["Lifetime sweep"]
    end
    subgraph Core["Core: plain functions"]
        AUTH["Who is this? May they read?"]
        ROUTE["Which room is this message for?"]
        LIFE["How long may this connection live?"]
    end
    CON --> AUTH
    CON --> LOOK
    LOOP --> ROUTE
    SWEEP --> LIFE

Connecting and subscribing

sequenceDiagram
    participant C as client
    participant S as socket
    participant Tw as digital-twin
    C->>S: connect, with the cookie
    Note over S: read claims, join domain rooms
    C->>S: subscribe to building 42
    S->>Tw: who owns building 42?
    Tw-->>S: northfield-university
    Note over S: shared organization? join building:42
    S-->>C: live data from now on
Ownership answerKept for 60 s?Result
Owners foundYesJoin if an organization is shared
No owners, or unknown buildingYesRefused
Lookup failedNoRefused, the next try asks again

How long a connection lives

Example. The permission check runs only at subscribe. Ada leaves Northfield at 10:00. Her open tab keeps getting library data until its connection is closed, at most about 15 minutes later.


Choices

ChoiceWhy
No domain model, no databaseIt only carries messages; it can be replaced at any time
Trust the edge’s claimsThe edge already checked the pass; no second check
Building data per building room, alerts per organization roomNo organization sees another’s data
A message with no organization is skippedSending it to everyone would leak names across customers

Gaps