Real-Time user presence tracking with Phoenix Presence

May 30, 2023

A comprehensive explanation of how to display the currently logged-in user using Phoenix Presence in a Phoenix LiveView application. The video covers the concepts, implementation details, and code snippets, providing valuable insights for developers interested in real-time web development with Elixir and Phoenix.

In the Func Prog Sweden video titled “Displaying current logged-in user using Phoenix Presence” AbulAsar Sayyad demonstrates the implementation of displaying the currently logged-in user using Phoenix Presence in a Phoenix LiveView application.

AbulAsar begins by introducing Phoenix LiveView as a real-time web framework that eliminates the need for client-side JavaScript to create interactive user interfaces. He highlights the advantages of using Elixir and Phoenix LiveView, such as scalability, fault tolerance, and improved productivity.

The video focuses on the concept of Phoenix Presence, which allows tracking user presence in real-time applications. AbulAsar explains how Phoenix Presence integrates with Phoenix LiveView using WebSocket connections and server-side rendering of UI changes.

AbulAsar provides an overview of the flow and implementation of Phoenix Presence, covering topics like user login tracking, broadcasting presence changes, and handling presence updates. He showcases code snippets and diagrams to illustrate the process.

During the code walkthrough, AbulAsar explains various aspects, including authentication, subscribing to topics, handling presence changes, and installing/configuring Phoenix Presence. He emphasizes the role of PubSub integration and the use of presence events.

Phoenix Presence is a real-time user presence tracking library in the Phoenix framework. It allows you to track users joining or leaving topics or channels in real-time. Presence leverages Phoenix’s PubSub for broadcasting presence updates to connected clients. With Phoenix Presence, you can display logged-in users, notify users about join/leave events, and create interactive real-time applications. It simplifies user activity tracking and enables features like live chat and online user lists.

Phoenix LiveView is a server-centric feature of the Phoenix web framework that enables real-time, interactive user experiences without writing client-side JavaScript. It simplifies development, reduces the need for JavaScript code, and allows for rapid prototyping. LiveView uses web sockets to establish a persistent connection between the client and server, providing automatic UI updates. It is suitable for various use cases and delivers a seamless user experience with minimal page reloads.

Elixir is a dynamic, functional programming language built on the Erlang virtual machine (BEAM). It combines the productivity of modern languages with the scalability and fault-tolerance of the Erlang ecosystem. Elixir is known for its concurrency model, which enables lightweight processes, message passing, and built-in support for distributed computing. It offers pattern matching, immutability, and powerful abstractions for building scalable and fault-tolerant applications. Elixir is often used for developing reliable and high-performance systems, including web applications, distributed systems, and IoT platforms.

Check out the Ada Beat Functional Programming blog for more topics, including functional programming principles, summaries of MeetUps, language specific articles, and much more. Whether you’re interested in functional programming theory or practical application, we have something for everyone.