0x9 Long Connections (Sockets)
Definition
ROOM: An independent collaborative workspace (room).
RESOURCE: A data resource unit that participates in collaboration in ROOM, which can be a datasheet, widget, etc. Relationship:
- Each ROOM is unique and includes one or more collaborators and RESOURCEs.
- The same RESOURCE can be in different ROOMs, and the relationship between the two is many-to-many.
- Users can open multiple clients and be in multiple ROOMs.

Message Types
Client Actively Pushes
-
User establishes a collaborative ROOM long connection channel. (WATCH_ROOM)
-
Each datasheet (form/dashboard, etc.) opened by the user can create an independent ROOM.
-
The ROOM identifier is a node ID or resource unit ID (such as: a separately opened widget).
-
Request message body structure:
{ "roomId": string; "shareId": string; } -
Web Socket pushes events to Nest server to obtain collaborator information and the latest revision numbers of various resources within the ROOM.
-
Data structure returned to client:
{ "collaborators": { "socketId": string; "createTime": number; "userId": string; "avatar": string; "userName" : string; "memberName": string; }[]; "resourceRevisions":{ "resourceId": string; "revision": number; }[] } -
Data structure broadcasted to collaborators: (ACTIVATE_COLLABORATOR)
{ "socketId": string; "createTime": number; "userId": string; "avatar": string; "userName": string; "memberName": string; } -
User leaves collaboration room (LEAVE_ROOM):
{ "roomId": string; } -
Data structure broadcasted to collaborators: (DEACTIVATE_COLLABORATOR)
{ "roomId": string; "socketId": string; } -
ROOM sends changesets (CLIENT_ROOM_CHANGE):
{ "roomId": string; "changesets": ILocalChangeset[]; } interface ILocalChangeset { "messageId": string; "baseRevision": number; "resourceId": string; "resourceType": ResourceType; "operations": IOperation[]; } -
Web Socket pushes evnets to Nest server
-
Nest server: Process changesets transactionally
-
Data structure returned to Socket server:
{ "changeset": IRemoteChangeset; "roomIds": string[]; }[] -
Every Changeset of a RESOURCE is broadcasted to all ROOMs that contain that RESOURCE.
-
Data structure broadcasted to collaborators (SERVER_ROOM_CHANGE):
{ "success": boolean; "code": number; "message": string; "data": IRemoteChangeset[]; } -
collaborate the cursor (ENGAGEMENT_CURSOR)
-
Send data about the activated cell:
{ "datasheetId": string; "viewId": string; "fieldId": string; "recordId": string; "time": number; } -
Web Socket broadcasts to collaborators (ENGAGEMENT_CURSOR), the data structure is the same as above ENGAGEMENT_CURSOR.
Client Passively Receives
- A new collaborator enters the room. (ACTIVATE_COLLABORATOR)
- A collaborator leaves the room. (DEACTIVATE_COLLABORATOR)
- Collaborative changesets in the room. (SERVER_ROOM_CHANGE)
- The collaborative cursor of other collaborators in the room. (ENGAGEMENT_CURSOR)

ROOM-RESOURCE two-way relation
Nest server is responsible for maintaining ROOM-RESOURCE two-way relations.
Maintain update points:
- Load resource data
- Room Changeset involving the addition or deletion of resources.