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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@locativemedia/locative-audio-service

v0.0.26

Published

Library that supports building auditory locative media experiences using 3d spatial audio without having to face implementation challenges.

Downloads

4

Readme

@locativemedia/locative-audio-service

NPM version License-mit

The sole purpose of this library is to provide an API that supports building auditory locative media experiences using 3d spatial audio without having to face the implementation challenges. This library has no UI components and is highly configurable. It takes into account and mitigates limitations and cross browser compatibility challenges. In addition it handles CPU-challenges and throttles certain API usages to better accommodate the limited resources available on a mobile device. Finally the library can play multiple spatial audio sources at the same time taking into account the geolocation and device orientation of the listener.

Overview

This library provides a service that makes it easy to build locative media experiences in the browser.

Installation

Installing the library is as easy as npm installing it:

npm install @locativemedia/locative-audio-service

Usage

Start by constructing the LocativeAudioService.

const locativeAudioService = new LocativeAudioService(config)

The config given to the constructor can include the following properties:

export interface ILocativeAudioServiceConfig {
	maxFindDistanceInM: number;

	// If given, environmental sounds will play
	// based on the geographical location of the target
	environmentAudio?: {
		// A token that is compatible with Google's Maps API.
		googleAuthToken: string;

		// An array of Google Maps metadata tags to play.
		files: {
			kind: MapsMetadataKind;
			path: string;
		}[];
		// A number between 0 and 1, indicating the amplitude. May be undefined
		volume?: number;
	};

	// If given, an ambient sound will play at all times during a session,
	// unaffected by any change to geolocation data.
	ambientAudio?: {
		path: string;
		volume?: number;
	};

	// An empty sound to place when the library is initialized.
	// This is done in order to conquer the AudioContext
	emptyAudio: {
		path: string;
	};

	// If given, audio won't abruptly start and stop,
	// but rather fade in/out depending on the given settings
	fadeOptions?: {
		fade: boolean;
		duration: number;
	};
}

Now, the library has to be initialized in direct response to a user gesture due to auto-play policies in modern browsers:

// Invoke 'initialize()' as direct response to a
// user gesture such as a 'click' event.
locativeAudioService.initialize();

To become familiar with some of the things this library can do, a few examples will be presented.

Example 1

An augmented environment represents the distance and angle between two entities such as a user and his or her target. We can visualize this by observing all changes to the augmented environment and rendering them to the DOM:

const element = document.querySelector("#something");
// Visualize the current angle difference by rotating some visual element by as many degrees
locativeAudioService.onAugmentedEnvironmentChanged (environment => element.style.transform = "rotate(" + environment.angleDiff + "deg)");

API reference

  • dispose (): Promise<void>: Will clear all listeners for sensor data and reset the state.
  • setTarget (position: IPosition|null): void: Will use the given position data to update the augmented environment, including audio panning and amplitude.
  • startSession (): void: Will start audio playback. A target must be given before invoking this method.
  • stopSession (): void: Will stop audio playback.
  • onAugmentedEnvironmentChanged (subscriber: AugmentedEnvironmentSubscriber): ISubscription: The given callback will be invoked when the augmented environment changes
  • onDeviceOrientationChanged (subscriber: DeviceOrientationSubscriber): ISubscription: The given callback will be invoked when the orientation of the device changes
  • onCalibratedChanged (subscriber: CalibrationSubscriber): ISubscription: The given callback will be invoked when the calibration status of the device changes
  • onStatusChanged (subscriber: StatusSubscriber): ISubscription: The given callback will be invoked when the status of the LocativeAudioService changes.
  • onGeolocationChanged (subscriber: GeolocationSubscriber): ISubscription: The given callback will be invoked when the geolocation of the device changes.
  • onSessionStarted (subscriber: SessionSubscriber): ISubscription: The given callback will be invoked when the a new session starts.
  • onSessionStopped (subscriber: SessionSubscriber): ISubscription: The given callback will be invoked when an on-going session stops.