#[Mid+ Level] How to sync kanban board using websocket?
13 messages · Page 1 of 1 (latest)
You can send a payload with the board_id and then maybe have filtering done in the backend?
[Mid+ Level] How to sync kanban board using websocket?
Just have a user subscribed to a board channel. Whenever anything on the board updates send an event with what updated (TaskUpdated, CardUpdated, ColumnUpdated, etc). Then just refresh the item that updated
If that's the case why not just have a dedicated channel per user then? When something happens on your app your server will then get the event, figure out all users who should recieve said event, and broadcast the event on all the user channels
No harm in sending an event anyway right?
Maybe they change their view in between the time that you start broadcasting the event and they recieve it
Yeah I think that's fine. On a lot of websocket connections I've seen there are events being sent all the time that I may not actually "see" changes for
Or just something like :
Echo.private('App.User.' + userId)
.notification((notification) => {
console.log(notification.type);
});
I'm not 100% sure as it would depend on how you set it up. Just throwing out ideas I've heard before
Why not broadcast the update events in a board channel, and then listen for the events when that component is loaded/viewed in the front end?
I always like to think of it as something like this:
- backend sends events to related channels (specific or broadcast to all) or notifications to specific users
- frontend will listen to the broadcasts where and when they are needed. And then is responsible for doing something with it.
For me it's oké to broadcast and then have the frontend miss it, when for example the user is not viewing that part of the app, when I make sure to (re)load the contents upon the next load/view. If you want you could (re)load in the background, but that all depends on your setup and type of broadcast.
Hope this helps, feel free to clarify more if there's anything specific you're running into with this
This. That's exactly how Laravel's Echo works. You create new items using normal XHR requests, or even normal form submissions, then on the backend you just broadcast those. The frontend listens to them and adds them to the current view. When you load that page it just grabs the items from the database, then starts to listen again and any change just modifies the current view