npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

live-location-client

v0.0.9

Published

A lightweight package to send live location updates via WebSockets.

Readme

Live Location Client

The live-location-client is a simple and configurable library for sending real-time live location data from the user's device to a server via WebSocket. This package is intended for frontend usage in web applications, enabling the client to send live GPS coordinates to a backend.

Installation

To install the package, run:

npm install live-location-client

Usage

1. Importing the Client

First, import the LiveLocationClient class in your JavaScript or TypeScript code:

import LiveLocationClient from "live-location-client";

2. Initialize the Client

Create an instance of the LiveLocationClient by providing your WebSocket server URL. You can also set the update interval for sending location data.

const locationClient = new LiveLocationClient({
  websocketUrl: "ws://your-websocket-url",
  updateInterval: 5000, // Default: 5000ms (5 seconds)
});

3. Handling Events

You can configure handlers for different WebSocket events. For example, you can listen for a successful connection, handle errors, and log location updates.

Events:

  • onConnect: Fired when the WebSocket connection is successfully established.
  • onError: Fired when there is an error with the WebSocket connection.
  • onLocationUpdate: Fired when the location data is successfully sent to the server.

Example of event handling:

locationClient.onConnect(() => {
  console.log("Successfully connected to the WebSocket server.");
});

locationClient.onError((error) => {
  console.error("Error occurred:", error);
});

locationClient.onLocationUpdate((locationData) => {
  console.log("Location sent:", locationData);
});

4. Start Sending Location

Once the client is initialized and event handlers are set up, you can start sending live location data. The client will automatically fetch the user's GPS coordinates and send them at the specified interval.

locationClient.start();

5. Stop Sending Location

You can stop sending location updates by calling the stop method:

locationClient.stop();

6. Customizing the Client

You can also configure other settings such as the updateInterval (in milliseconds), and WebSocket URL. The client will use the default settings unless specified otherwise.

Example of custom settings:

const locationClient = new LiveLocationClient({
  websocketUrl: "ws://your-custom-websocket-url",
  updateInterval: 10000, // Send location every 10 seconds
});

Example Usage

Here is a full example of how to integrate and use live-location-client in a web application:

import LiveLocationClient from "live-location-client";

// Initialize the client with the WebSocket URL and update interval
const locationClient = new LiveLocationClient({
  websocketUrl: "ws://your-websocket-url", // Replace with your WebSocket server URL
  updateInterval: 5000, // Send location every 5 seconds
});

// Setup event listeners
locationClient.onConnect(() => {
  console.log("Successfully connected to the WebSocket server.");
});

locationClient.onError((error) => {
  console.error("Error occurred:", error);
});

locationClient.onLocationUpdate((locationData) => {
  console.log("Location data sent:", locationData);
});

// Start sending live location
locationClient.start();

// If you want to stop sending the location after some time, you can use stop():
setTimeout(() => {
  locationClient.stop();
  console.log("Stopped sending location updates.");
}, 30000); // Stop after 30 seconds

Explanation:

  • The locationClient.start() method starts sending the user's live location every 5 seconds (or whatever interval you set).
  • The locationClient.stop() method can be called to stop sending location updates.
  • The WebSocket connection sends the location data as a JSON object with latitude, longitude, and timestamp.
  • Event handlers (onConnect, onError, onLocationUpdate) allow you to handle the connection status, errors, and successful data sends.

Configuration Options

  • websocketUrl: Required — The URL of the WebSocket server to send location updates to.
  • updateInterval: Optional — The time interval (in milliseconds) at which location data will be sent to the server. Default is 5000ms (5 seconds).

Example Project

For a full example of how to integrate the live-location-client into a web project, visit the example project repo.

License

This package is licensed under the MIT License.

Contributing

Feel free to open issues or pull requests for bug fixes, features, or improvements.

Contact

For any questions, you can reach out to [email protected].

Key Additions:

  • Example Usage: Provides a full example to show how to use the package in a web application.
  • Code Walkthrough: Each part of the code example is explained in simple terms to make it easy for users to understand the flow.

Make sure to replace ws://your-websocket-url with your actual WebSocket URL and update any placeholders as per your specific project needs.