ThePoet444
7 months ago

list of users online

Posted 7 months ago by ThePoet444

I currently have a list of all users using the site. I am using laravel echo server. Everything works as it should. The questions I have are this:

  1. is this the correct way to do it?
  2. The user will "blink" when they go to a new page of the site. While I understand why this happens and it is indeed normal, I'm curious if there is a way I can prevent it. IE, user 2 will go from main page to a news article and user 1 will see user 2 "blink" because of the page shift.
\app.js

let app = new Vue({
    el: '#app',
    data: {
        onlineUsers: []
    },
    mounted() {
        window.Echo.join('onlineUsers')
            .here(onlineUsers => (this.onlineUsers = onlineUsers))
            .joining(user => this.onlineUsers.push(user))
            .leaving(user => (this.onlineUsers = this.onlineUsers.filter(u => (u.id !== user.id))))
    }
});



//blade
<div>
    <h4>Users Online</h4>

    <ul>
        <li class="linone" v-for="user in onlineUsers" v-text="user.name"></li>
    </ul>
</div>

Please sign in or create an account to participate in this conversation.