Skip to content
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

[Feature Request] Update Storage in Lambda Environment #1274

Open
gerardSlate opened this issue Oct 31, 2023 · 0 comments
Open

[Feature Request] Update Storage in Lambda Environment #1274

gerardSlate opened this issue Oct 31, 2023 · 0 comments

Comments

@gerardSlate
Copy link

I'm building a multiplayer real-time CRM that requires inserting values into the JSON storage object from outside of the room context. For example, someone submits a support ticket on a page that is outside of a room context. Currently, this is a multi-step process.

  1. Make API call to backend (i.e POST /api/ticket). <-- This is a Vercel serverless function
  2. Persist full ticket details in DB (Postgres, Mongo, etc.)
  3. Publish a message to a kafka topic with minimal ticket details (i.e id, title, createdAt)
  4. Consume messages on a NodeJS Server and modify the storage document as described here: https://liveblocks.io/docs/guides/how-to-modify-liveblocks-storage-from-the-server

Currently, my understanding is that websocket connections are required to modify storage which is not supported in a Vercel Lambda. Furthermore, these updates don't work if the room is at capacity. While I don't foresee this being a major issue, it is still an edge case. Ideally, I would like to replace steps 3 and 4 with an API call to liveblocks.

Describe the solution you'd like

To be clear, I'd like to be able to just make a simple API call to modify liveblocks storage that is compatible with a serverless environment. Ideally, it would be something similar to this: https://liveblocks.io/docs/guides/modifying-yjs-document-data-with-the-rest-api.


type Params = {
  params: {
    roomId: string;
  }
}

export async function POST(request: NextRequest, { params }: Params ) {
  const data: CreateTicketRequest = await request.json();
  
  const createdTicket = await prisma.ticket.create({ data })
  const storageObject: RoomStorageObject = await fetchStorage(params.roomId);
  storageObject.tickets.push({...createdTicket })

  await liveBlocksServerClient.patch(`/rooms/${params.roomId}/storage`, { storage: storageObject})

}

Additional context
The other documentation for modifying the storage objects will cause all users to be disconnected from the room. I think this is okay as, I could simply have users automatically reconnect once the write is finished.

@gerardSlate gerardSlate added the feature request Feature requested by the community label Oct 31, 2023
@adigau adigau added the 🎪 Room label Apr 24, 2024 — with Linear
@adigau adigau removed the feature request Feature requested by the community label May 9, 2024
@adigau adigau added the Engineering label May 9, 2024 — with Linear
@adigau adigau removed the Engineering label May 9, 2024
@adigau adigau removed the 🎪 Room label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants