-
Notifications
You must be signed in to change notification settings - Fork 3.7k
refactor(realtime): type the socket event-handler boundary with @sim/realtime-protocol #5208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+189
−47
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import type { OperationTarget, SocketOperation } from './constants' | ||
|
|
||
| /** | ||
| * Wire types for the broadcast/confirmation events the realtime Socket.IO server | ||
| * emits to clients. These mirror the exact object literals emitted by | ||
| * `apps/realtime/src/handlers/**` and `apps/realtime/src/rooms/**`, and are the | ||
| * canonical types consumed by the client socket transport | ||
| * (`apps/sim/app/workspace/providers/socket-provider.tsx`). | ||
| * | ||
| * Payload bodies that the transport forwards opaquely are typed `unknown` rather | ||
| * than a concrete operation union, because the transport never narrows them — the | ||
| * collaborative-workflow consumer dispatches on `operation`/`target` itself. | ||
| */ | ||
|
|
||
| /** A live-presence cursor position broadcast over the socket. */ | ||
| export interface CursorPosition { | ||
| x: number | ||
| y: number | ||
| } | ||
|
|
||
| /** A live-presence selection broadcast over the socket. */ | ||
| export interface PresenceSelection { | ||
| type: 'block' | 'edge' | 'none' | ||
| id?: string | ||
| } | ||
|
|
||
| /** | ||
| * `workflow-operation` broadcast. The server re-broadcasts the originating | ||
| * operation envelope plus sender identity and operation metadata. | ||
| */ | ||
| export interface WorkflowOperationBroadcast { | ||
| operation: SocketOperation | string | ||
| target: OperationTarget | string | ||
| payload: unknown | ||
| timestamp: number | ||
| senderId: string | ||
| userId: string | ||
| userName: string | ||
| metadata: { | ||
| workflowId: string | ||
| operationId: string | ||
| isPositionUpdate?: boolean | ||
| isBatchPositionUpdate?: boolean | ||
| } | ||
| } | ||
|
|
||
| /** `subblock-update` broadcast. */ | ||
| export interface SubblockUpdateBroadcast { | ||
| workflowId: string | ||
| blockId: string | ||
| subblockId: string | ||
| value: unknown | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `variable-update` broadcast. */ | ||
| export interface VariableUpdateBroadcast { | ||
| workflowId: string | ||
| variableId: string | ||
| field: string | ||
| value: unknown | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `cursor-update` presence broadcast for a single remote user. */ | ||
| export interface CursorUpdateBroadcast { | ||
| socketId: string | ||
| userId: string | ||
| userName: string | ||
| avatarUrl?: string | null | ||
| /** `null` when the remote user's cursor leaves the canvas (the client emits `{ cursor: null }`). */ | ||
| cursor: CursorPosition | null | ||
| } | ||
|
|
||
| /** `selection-update` presence broadcast for a single remote user. */ | ||
| export interface SelectionUpdateBroadcast { | ||
| socketId: string | ||
| userId: string | ||
| userName: string | ||
| avatarUrl?: string | null | ||
| selection: PresenceSelection | ||
| } | ||
|
|
||
| /** `workflow-deleted` lifecycle broadcast. */ | ||
| export interface WorkflowDeletedBroadcast { | ||
| workflowId: string | ||
| message: string | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `workflow-reverted` lifecycle broadcast. */ | ||
| export interface WorkflowRevertedBroadcast { | ||
| workflowId: string | ||
| message: string | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `workflow-updated` lifecycle broadcast. */ | ||
| export interface WorkflowUpdatedBroadcast { | ||
| workflowId: string | ||
| message: string | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `workflow-deployed` lifecycle broadcast. */ | ||
| export interface WorkflowDeployedBroadcast { | ||
| workflowId: string | ||
| timestamp: number | ||
| } | ||
|
|
||
| /** `operation-confirmed` ack for a previously-emitted operation. */ | ||
| export interface OperationConfirmedBroadcast { | ||
| operationId: string | ||
| serverTimestamp: number | ||
| } | ||
|
|
||
| /** `operation-failed` rejection for a previously-emitted operation. */ | ||
| export interface OperationFailedBroadcast { | ||
| operationId: string | ||
| error: string | ||
| retryable?: boolean | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.