Search code examples
httpwebsocketcomet

How to implement "other users viewing this object"


For example Zendesk has a feature called Agent Collision Notification - when you edit a ticket you get a note if somebody else its editing this ticket.

What is the Infrastructure to support a feature like this? This question seems to aim at the same thing but at a much lower level.

For the system to be completely dynamic (also notifying the first viewer) and reasonable fast, probably some comet or websocket like stuff is needed. But unlike in chat systems (a prime comet example) in a Ticket system users are constantly switching pages.

What would be the program flow and the server infrastructure for a thing like this?


Solution

  • If you want to allow realtime collaboration then this question that also mentions Operational Transforms will be of interest to you. And there's also a question about operational transformation libraries.

    What would be the program flow and the server infrastructure for a thing like this?

    I work for Pusher so I can tell you one solution using our technology.

    1. User A opens page where there could be a 'collision'. Within the page subscribe to a channel for the page.
    2. User A starts editing the page. Send an AJAX request to the server so there is some persisted state about the fact the page is being edited. Trigger an event on the channel stating that the user is editing the page.
    3. User B opens the page. The page loads and can display the information from the persisted state that the page is being edited.
    4. User A finishes editing and a request is made to the server to update the page state. Trigger an event indicating that nobody is editing the page. This event will be distributed to User B (the updated page can also be distributed via within the event or via an AJAX request when the event is received).
    5. User B now knows he/she can edit the page. They begin editing (see step 2.) and User A is notified that User B is now editing the page.

    It would also be quite cool to use presence so you could see who else was viewing the page and to allow the users to discuss changes as they happen.