Last online activity on a website

I need to record the exact time when a user last interacted with a website - whether they clicked the mouse, typed on the keyboard, or moved the cursor.

By capturing this timestamp, I can calculate the remaining duration until the Web Token expires.

Answer №1

If you're looking to implement event handling using RxJS, check out this example on Plunker: https://plnkr.co/edit/4kPM5FX6vX2QGC0xDQQO

The key function here is called _listenToEvent:

function _listenToEvent(name, debounceTime) {
  rxjs.fromEvent(document, name)
  .pipe(
    rxjs.operators.debounceTime(debounceTime)
  )
  .subscribe(() => _updateTimestamp())
}

This function allows you to listen to events on the document object. The debounceTime parameter enables you to delay sending AJAX requests until after a specified time interval, preventing unnecessary requests triggered by rapid mouse movements or keystrokes. Debouncing for the click event may not be needed since users don't typically click rapidly.

You can easily incorporate this with a user service that handles AJAX requests as needed. Keep in mind, though, that this solution may not cover all scenarios. If your code prevents event bubbling, RxJS might miss certain events.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Code snippet that will emphasize the active page if there are multiple pages, such as highlighting page 2

My current project involves implementing a script to highlight the current page on a Tumblr blog. I found the script I am using here: $(function(){ $('a').each(function() { if ($(this).prop('href') == window.location.href) { ...

next-auth: after hitting login, user will be redirected to /api/auth/error

I'm encountering an issue where NextAuth consistently redirects to the error page without returning a user as expected based on my code in: ./app/account/login/page.tsx "use client"; import React, { useState } from "react"; import ...

Traveling within a layered object

Currently, I'm working with an object and iterating through it to retrieve outputs as shown below: var obj = { "first": { "Bob": { "1": "foo", "2": "bar" }, "Jim": { "1": "baz" } }, "second": { "Bob": { ...

The functionality of an external Javascript library fails to operate properly once the website is deployed to a hosting

Encountering a peculiar bug with my website at . The website is supposed to load both the JQuery and EasyUI libraries. JQuery is loading correctly as a function to print out "ready" when the page loads. The issue arises when trying to drag products onto th ...

Unable to load component within feature module's router-outlet

I am in the process of incorporating lazy loading for feature modules. How can I dynamically load components declared in a feature module onto a specific router-outlet within the feature module component? Within my application, there is a base module (App ...

Fixed-bottom footer in Bootstrap 5 that overlays content

Having trouble creating a fixed footer using the fixed-bottom class in react & bootstrap. The issue is that it's covering some content and I've tried various solutions without success. Any suggestions on how to fix this? (Code and Demo provided b ...

Convert a date from the format of YYYY-MM-DD HH:MM:SS to MM-DD-YYYY using Javascript

Looking to transform YYYY-MM-DD HH:MM:SS into MM-DD-YYYY For instance: Given a date string in the format: 2013-06-15 03:00:00 The goal is to convert this string to 06-15-2013 using JavaScript. Is there a library available for this task, or should I rely ...

Tips for generating a subject in rx.js while utilizing 2 parameters

Within my Angular2 application, I am utilizing a communication service to handle interactions between components. When calling the method: this.notification.create('test'); The service structure is as follows: export class NotificationServic ...

Displaying a specific fieldset based on the radio button selection

I have created a form to handle user input using PHP, with the initial question prompting the user to choose from three radio buttons for the "type" parameter - the options being "book", "journal", and "website". Here is what the code looks like: <stro ...

Issue with Google Maps Angular directive failing to function correctly

Trying to implement the Google Maps for AngularJS directive within a function has been a challenge. I've managed to make it work by moving $scope.map outside the function call and setting the lat/lon statically. However, my goal is to dynamically set ...

Grunt compilation: Implement a fixed path for image assets

I'm currently working on a Django application that utilizes AngularJS for the front end. I use grunt to build the application, but I'm facing an issue where the images appear broken when served through Django. It seems that the image paths are mi ...

Leveraging a specially designed function within an equation

After creating a function called calculateObjectDepth(object) that determines the depth of an object and returns a corresponding string (for example, if the depth is 3, it will return "sub-sub-sub"), I realized that in my directive template, I need to util ...

Maintaining binding while appending inner elements within a container using jQuery

I'm struggling to transfer the contents of one container to another without losing any bindings, and it's proving quite tricky! <div class="container"> <div class="field"> <label>Username</label> < ...

Creating a modal in Ruby on Rails with Bootstrap

I'm attempting to utilize bootstrap modal with ajax, but I'm facing an issue where the screen darkens upon clicking, but the modal never appears. Any tips or a better approach to tackle this problem? measures/index.html.erb <%= link_to &apo ...

Complicated connections between TypeORM and MySQL

Currently leveraging TypeORM in tandem with MySQL, my database comprises of two main Entities, namely User and Project: @Entity() class User { @PrimaryGeneratedColumn('uuid') id: string; @Column({}) name: string; } @Entity() ...

Utilize the '#' symbol within Angular route paths

Can routes be defined in Angular using #? Instead of the usual setup like: const routes: Routes = [ { path: 'home', component: HomeComponent } ]; is it possible to do it like this: const routes: Routes = [ { path: '#home& ...

Hover over parts of an image to bring attention to them

I am interested in developing a webpage featuring a black and white image of 5 individuals. When hovering over each person, I would like them to illuminate and display relevant information in a dialog box next to them. Do you have any tips on how I can ac ...

Tips on resolving the problem of a user surpassing their 24-hour sending limit

Hey there! I need some assistance with a contact form I'm developing using react and node.js. I've set up both the front end and backend, and everything was running smoothly for up to 25 emails a day. However, I've started encountering an er ...

What is the best way to know which API will return the result the fastest?

If we were to make 2 API calls, each taking around 6ms to return JSON data, what would be the sequence in which they provide the resulting data? The official JavaScript documentation mentions using Promise.all to manage multiple API calls. ...

How to properly load components in React?

I've been diving into building a simple app in React using ES6 and Babel. While working on it, I encountered an issue. I decided to incorporate the react-notifications package from https://github.com/minhtranite/react-notifications Following the docu ...