Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

audioplayr

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

audioplayr - npm Package Compare versions

Comparing version 0.7.7 to 0.8.0-beta0

lib/types.d.ts

4

lib/AudioPlayr.d.ts

@@ -1,6 +0,6 @@

import { IAudioPlayr, IAudioPlayrSettings, IPlaySettings } from "./IAudioPlayr";
import { IAudioPlayrSettings, IPlaySettings } from "./types";
/**
* Playback for persistent and on-demand sounds and themes.
*/
export declare class AudioPlayr implements IAudioPlayr {
export declare class AudioPlayr {
/**

@@ -7,0 +7,0 @@ * Creates a new sound.

@@ -1,38 +0,2 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
define(["require", "exports", "./Sound", "./Storage"], function (require, exports, Sound_1, Storage_1) {
define(["require", "exports", "./Sound"], function (require, exports, Sound_1) {
"use strict";

@@ -47,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

*/
var defaultNameTransform = function (name) { return name; };
const defaultNameTransform = (name) => name;
/**
* Playback for persistent and on-demand sounds and themes.
*/
var AudioPlayr = /** @class */ (function () {
class AudioPlayr {
/**

@@ -58,3 +22,3 @@ * Initializes a new instance of the AudioPlayr class.

*/
function AudioPlayr(settings) {
constructor(settings) {
/**

@@ -66,3 +30,3 @@ * Created sounds, keyed by name.

this.nameTransform = settings.nameTransform || defaultNameTransform;
this.storage = settings.storage || new Storage_1.DefaultStorage();
this.storage = settings.storage;
}

@@ -74,8 +38,5 @@ /**

*/
AudioPlayr.prototype.getMuted = function () {
var mutedRaw = this.storage.getItem(Storage_1.AudioSetting.Muted);
return mutedRaw === undefined || mutedRaw === null
? false
: JSON.parse(mutedRaw);
};
getMuted() {
return !!this.storage.getMuted();
}
/**

@@ -86,8 +47,6 @@ * Gets the global sound volume in [0, 1].

*/
AudioPlayr.prototype.getVolume = function () {
var volumeRaw = this.storage.getItem(Storage_1.AudioSetting.Volume);
return volumeRaw === undefined || volumeRaw === null
? 1
: JSON.parse(volumeRaw);
};
getVolume() {
var _a;
return (_a = this.storage.getVolume()) !== null && _a !== void 0 ? _a : 1;
}
/**

@@ -98,19 +57,6 @@ * Sets whether this is muted.

*/
AudioPlayr.prototype.setMuted = function (muted) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.storage.setItem(Storage_1.AudioSetting.Muted, JSON.stringify(muted));
return [4 /*yield*/, Promise.all(Object.keys(this.sounds).map(function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.sounds[name].setGlobalMuted(muted)];
}); }); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
async setMuted(muted) {
this.storage.setMuted(muted);
await Promise.all(Object.keys(this.sounds).map(async (name) => this.sounds[name].setGlobalMuted(muted)));
}
/**

@@ -121,22 +67,9 @@ * Sets the global sound volume in [0, 1].

*/
AudioPlayr.prototype.setVolume = function (volume) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (volume < 0 || volume > 1) {
throw new Error("Volume must be within [0, 1].");
}
this.storage.setItem(Storage_1.AudioSetting.Volume, volume);
return [4 /*yield*/, Promise.all(Object.keys(this.sounds).map(function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.sounds[name].setGlobalVolume(volume)];
}); }); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
async setVolume(volume) {
if (volume < 0 || volume > 1) {
throw new Error("Volume must be within [0, 1].");
}
this.storage.setVolume(volume);
await Promise.all(Object.keys(this.sounds).map(async (name) => this.sounds[name].setGlobalVolume(volume)));
}
/**

@@ -149,31 +82,17 @@ * Plays a sound.

*/
AudioPlayr.prototype.play = function (name, settings) {
if (settings === void 0) { settings = {}; }
return __awaiter(this, void 0, void 0, function () {
var alias, sound;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
name = this.nameTransform(name);
alias = settings.alias === undefined
? name
: this.nameTransform(settings.alias);
if (!{}.hasOwnProperty.call(this.sounds, alias)) return [3 /*break*/, 2];
return [4 /*yield*/, this.sounds[alias].stop()];
case 1:
_a.sent();
_a.label = 2;
case 2:
sound = (this.sounds[alias] = this.createSound(name, {
globalMuted: this.getMuted(),
globalVolume: this.getVolume(),
localMuted: settings.muted === undefined ? false : settings.muted,
localVolume: settings.volume === undefined ? 1 : settings.volume,
loop: settings.loop === undefined ? false : settings.loop,
}));
return [2 /*return*/, sound.play()];
}
});
});
};
async play(name, settings = {}) {
name = this.nameTransform(name);
const alias = settings.alias === undefined ? name : this.nameTransform(settings.alias);
if ({}.hasOwnProperty.call(this.sounds, alias)) {
await this.sounds[alias].stop();
}
const sound = (this.sounds[alias] = this.createSound(name, {
globalMuted: this.getMuted(),
globalVolume: this.getVolume(),
localMuted: settings.muted === undefined ? false : settings.muted,
localVolume: settings.volume === undefined ? 1 : settings.volume,
loop: settings.loop === undefined ? false : settings.loop,
}));
return sound.play();
}
/**

@@ -184,17 +103,5 @@ * Pauses all sounds.

*/
AudioPlayr.prototype.pauseAll = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(Object.keys(this.sounds).map(function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.sounds[name].pause()];
}); }); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
async pauseAll() {
await Promise.all(Object.keys(this.sounds).map(async (name) => this.sounds[name].pause()));
}
/**

@@ -205,17 +112,5 @@ * Un-pauses (plays) all sounds.

*/
AudioPlayr.prototype.resumeAll = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(Object.keys(this.sounds).map(function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.sounds[name].play()];
}); }); }))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
async resumeAll() {
await Promise.all(Object.keys(this.sounds).map(async (name) => this.sounds[name].play()));
}
/**

@@ -226,18 +121,6 @@ * Stops all sounds.

*/
AudioPlayr.prototype.stopAll = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(Object.keys(this.sounds).map(function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, this.sounds[name].stop()];
}); }); }))];
case 1:
_a.sent();
this.sounds = {};
return [2 /*return*/];
}
});
});
};
async stopAll() {
await Promise.all(Object.keys(this.sounds).map(async (name) => this.sounds[name].stop()));
this.sounds = {};
}
/**

@@ -250,3 +133,3 @@ * Checks whether a sound under the alias exists.

*/
AudioPlayr.prototype.hasSound = function (alias, name) {
hasSound(alias, name) {
alias = this.nameTransform(alias);

@@ -256,9 +139,7 @@ if (!{}.hasOwnProperty.call(this.sounds, alias)) {

}
return (name === undefined ||
this.sounds[alias].name === this.nameTransform(name));
};
return AudioPlayr;
}());
return name === undefined || this.sounds[alias].name === this.nameTransform(name);
}
}
exports.AudioPlayr = AudioPlayr;
});
//# sourceMappingURL=AudioPlayr.js.map
import * as sinon from "sinon";
import { AudioPlayr } from "./AudioPlayr";
import { IAudioPlayrSettings } from "./IAudioPlayr";
import { IAudioPlayrSettings } from "./types";
import { AudioElementSound, ISound } from "./Sound";
import { DefaultStorage } from "./Storage";
export declare const stubAudioPlayr: (settings?: IAudioPlayrSettings) => {
export declare const stubAudioPlayr: (settings?: Partial<IAudioPlayrSettings>) => {
audioPlayer: AudioPlayr;
createSound: sinon.SinonSpy<[string], sinon.SinonStubbedInstance<AudioElementSound>>;
getCreatedSound: (name: string) => sinon.SinonStubbedInstance<ISound>;
storage: DefaultStorage;
storage: {
getMuted: () => boolean;
getVolume: () => number;
setMuted: (value: boolean) => boolean;
setVolume: (value: number) => number;
};
};
//# sourceMappingURL=fakes.test.d.ts.map
import { ICreateSound } from "./Sound";
import { IAudioSettingsStorage } from "./Storage";
/**

@@ -11,2 +11,3 @@ * Settings to play a sound.

alias?: string;
/**

@@ -16,2 +17,3 @@ * Whether it should loop (by default, false).

loop?: boolean;
/**

@@ -21,2 +23,3 @@ * Whether this sound is muted (by default, false).

muted?: boolean;
/**

@@ -27,2 +30,3 @@ * Initial volume for this sound (by default, 1).

}
/**

@@ -34,4 +38,15 @@ * Transforms a sound name into a file name.

*/
export declare type INameTransform = (name: string) => string;
export type INameTransform = (name: string) => string;
/**
* Stores mute and volume status locally.
*/
export interface IAudioSettingsStorage {
getItem(name: "muted"): boolean | undefined;
getItem(name: "volume"): number | undefined;
setItem(name: "muted", value: boolean): void;
setItem(name: "volume", value: number): void;
}
/**
* Settings to initialize a new instance of an IAudioPlayr.

@@ -44,2 +59,3 @@ */

createSound?: ICreateSound;
/**

@@ -49,70 +65,7 @@ * Transforms provided names into file names.

nameTransform?: INameTransform;
/**
* Stores mute and volume status locally.
*/
storage?: IAudioSettingsStorage;
storage: IAudioSettingsStorage;
}
/**
* Playback for persistent and on-demand sounds and themes.
*/
export interface IAudioPlayr {
/**
* Gets whether this is muted.
*
* @returns Whether this is now muted.
*/
getMuted(): boolean;
/**
* Gets the global sound volume in [0, 1].
*
* @returns Global sound volume in [0, 1].
*/
getVolume(): number;
/**
* Sets whether this is muted.
*
* @param muted Whether this is now muted.
*/
setMuted(muted: boolean): Promise<void>;
/**
* Sets the global sound volume in [0, 1].
*
* @param volume New global sound volume in [0, 1].
*/
setVolume(volume: number): Promise<void>;
/**
* Plays a sound.
*
* @param name Name of a sound.
* @param settings Any settings for the sound.
* @returns A Promise for playing the sound.
*/
play(name: string, settings?: IPlaySettings): Promise<void>;
/**
* Pauses all sounds.
*
* @returns A Promise for pausing all sounds.
*/
pauseAll(): Promise<void>;
/**
* Un-pauses (plays) all sounds.
*
* @returns A Promise for resuming.
*/
resumeAll(): Promise<void>;
/**
* Stops all sounds and any theme.
*
* @returns A Promise for stopping all sounds.
*/
stopAll(): Promise<void>;
/**
* Checks whether a sound under the alias exists.
*
* @param alias Alias to check under.
* @param name Name the sound must have, if not the same as alias.
* @returns Whether a sound exists under the alias.
*/
hasSound(alias: string, name?: string): boolean;
}
//# sourceMappingURL=IAudioPlayr.d.ts.map
export * from "./AudioPlayr";
export * from "./IAudioPlayr";
export * from "./Sound";
export * from "./Storage";
export * from "./types";
export * from "./wrapNativeStorage";
//# sourceMappingURL=index.d.ts.map

@@ -11,10 +11,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

};
define(["require", "exports", "./AudioPlayr", "./IAudioPlayr", "./Sound", "./Storage"], function (require, exports, AudioPlayr_1, IAudioPlayr_1, Sound_1, Storage_1) {
define(["require", "exports", "./AudioPlayr", "./Sound", "./types", "./wrapNativeStorage"], function (require, exports, AudioPlayr_1, Sound_1, types_1, wrapNativeStorage_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(AudioPlayr_1, exports);
__exportStar(IAudioPlayr_1, exports);
__exportStar(Sound_1, exports);
__exportStar(Storage_1, exports);
__exportStar(types_1, exports);
__exportStar(wrapNativeStorage_1, exports);
});
//# sourceMappingURL=index.js.map

@@ -1,48 +0,1 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
define(["require", "exports"], function (require, exports) {

@@ -55,3 +8,3 @@ "use strict";

*/
var defaultSoundSettings = {
const defaultSoundSettings = {
globalMuted: false,

@@ -66,3 +19,3 @@ globalVolume: 1,

*/
var AudioElementSound = /** @class */ (function () {
class AudioElementSound {
/**

@@ -74,12 +27,10 @@ * Initializes a new instance of the AudioElementSound class.

*/
function AudioElementSound(name, settings) {
constructor(name, settings) {
this.name = name;
this.settings = __assign(__assign({}, defaultSoundSettings), settings);
this.settings = Object.assign(Object.assign({}, defaultSoundSettings), settings);
this.element = document.createElement("audio");
this.element.src = name;
this.element.loop = this.settings.loop;
this.element.muted =
this.settings.globalMuted || this.settings.localMuted;
this.element.volume =
this.settings.globalVolume * this.settings.localVolume;
this.element.muted = this.settings.globalMuted || this.settings.localMuted;
this.element.volume = this.settings.globalVolume * this.settings.localVolume;
}

@@ -91,10 +42,5 @@ /**

*/
AudioElementSound.prototype.pause = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.element.pause();
return [2 /*return*/];
});
});
};
async pause() {
this.element.pause();
}
/**

@@ -105,9 +51,5 @@ * Plays the sound.

*/
AudioElementSound.prototype.play = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.element.play()];
});
});
};
async play() {
return this.element.play();
}
/**

@@ -119,10 +61,5 @@ * Sets whether this should loop.

*/
AudioElementSound.prototype.setLoop = function (loop) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.element.loop = loop;
return [2 /*return*/];
});
});
};
async setLoop(loop) {
this.element.loop = loop;
}
/**

@@ -134,12 +71,6 @@ * Sets whether this is muted.

*/
AudioElementSound.prototype.setGlobalMuted = function (muted) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.settings.globalMuted = muted;
this.element.muted =
this.settings.globalMuted || this.settings.localMuted;
return [2 /*return*/];
});
});
};
async setGlobalMuted(muted) {
this.settings.globalMuted = muted;
this.element.muted = this.settings.globalMuted || this.settings.localMuted;
}
/**

@@ -151,12 +82,6 @@ * Sets a new global volume in [0, 1].

*/
AudioElementSound.prototype.setGlobalVolume = function (volume) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.settings.globalVolume = volume;
this.element.volume =
this.settings.globalVolume * this.settings.localVolume;
return [2 /*return*/];
});
});
};
async setGlobalVolume(volume) {
this.settings.globalVolume = volume;
this.element.volume = this.settings.globalVolume * this.settings.localVolume;
}
/**

@@ -167,30 +92,17 @@ * Plays the sound.

*/
AudioElementSound.prototype.stop = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.pause()];
case 1:
_a.sent();
this.element.currentTime = 0;
return [2 /*return*/];
}
});
});
};
/**
* Creates a new AudioElementSound.
*
* @param name Name of the sound.
* @param settings Any settings for the sound.
* @returns A new sound.
*/
AudioElementSound.create = function (name, settings) {
if (settings === void 0) { settings = {}; }
return new AudioElementSound(name, settings);
};
return AudioElementSound;
}());
async stop() {
await this.pause();
this.element.currentTime = 0;
}
}
exports.AudioElementSound = AudioElementSound;
/**
* Creates a new AudioElementSound.
*
* @param name Name of the sound.
* @param settings Any settings for the sound.
* @returns A new sound.
*/
AudioElementSound.create = (name, settings = {}) => new AudioElementSound(name, settings);
});
//# sourceMappingURL=Sound.js.map

@@ -22,4 +22,4 @@ define(["require", "exports"], function (require, exports) {

*/
var DefaultStorage = /** @class */ (function () {
function DefaultStorage() {
class DefaultStorage {
constructor() {
/**

@@ -36,5 +36,5 @@ * Stored values.

*/
DefaultStorage.prototype.getItem = function (name) {
getItem(name) {
return this.values[name];
};
}
/**

@@ -46,9 +46,8 @@ * Sets a stored value.

*/
DefaultStorage.prototype.setItem = function (name, value) {
setItem(name, value) {
this.values[name] = value;
};
return DefaultStorage;
}());
}
}
exports.DefaultStorage = DefaultStorage;
});
//# sourceMappingURL=Storage.js.map

@@ -10,5 +10,5 @@ {

},
"description": "An audio playback manager for persistent and on-demand themes and sounds.",
"description": "Audio playback manager for persistent and on-demand themes and sounds.",
"devDependencies": {
"shenanigans-manager": "^0.3.2"
"shenanigans-manager": "^0.3.0"
},

@@ -22,8 +22,10 @@ "license": "MIT",

"scripts": {
"clean": "rm -rf lib *.tsbuildinfo",
"compile": "tsc -b",
"hydrate": "node ../shenanigans-manager/bin/shenanigans-manager hydrate-package-json && yarn run test:setup",
"hydrate": "yarn shenanigans-manager hydrate",
"link": "yarn link",
"publish:ci": "yarn shenanigans-manager publish-if-updated",
"test": "yarn run test:setup && yarn run test:run",
"test:run": "mocha-headless-chrome --file test/index.html",
"test:setup": "node ../shenanigans-manager/bin/shenanigans-manager generate-tests"
"test:setup": "yarn shenanigans-manager generate-tests"
},

@@ -34,4 +36,3 @@ "shenanigans": {

"types": "./lib/index.d.ts",
"version": "0.7.7",
"gitHead": "6379309b5ea381578fd84b96778fde081a937209"
}
"version": "0.8.0-beta0"
}

@@ -5,7 +5,8 @@ <!-- Top -->

[![Greenkeeper badge](https://badges.greenkeeper.io/FullScreenShenanigans/AudioPlayr.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/FullScreenShenanigans/AudioPlayr.svg?branch=master)](https://travis-ci.org/FullScreenShenanigans/AudioPlayr)
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io)
![TypeScript: Strict](https://img.shields.io/badge/typescript-strict-brightgreen.svg)
[![NPM version](https://badge.fury.io/js/audioplayr.svg)](http://badge.fury.io/js/audioplayr)
[![Join the chat at https://gitter.im/FullScreenShenanigans/community](https://badges.gitter.im/FullScreenShenanigans/community.svg)](https://gitter.im/FullScreenShenanigans/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
An audio playback manager for persistent and on-demand themes and sounds.
Audio playback manager for persistent and on-demand themes and sounds.

@@ -35,2 +36,3 @@ <!-- /Top -->

nameTransform: (name: string) => `Sounds/${name}.mp3`,
storage: new ItemsHoldr(),
});

@@ -46,9 +48,18 @@

By default, mute and volume settings aren't kept from state to state.
You can pass a `storage` parameter to an `AudioPlayr` to keep them locally.
It should be an object with `getItem(name: string): string` and `setItem(name: string, value: string)` members, such as `localStorage`.
You must pass a `storage` parameter to an `AudioPlayr` to keep muted and volume stored locally.
It should have the following methods:
- `getMuted(): boolean`
- `getVolume(): boolean`
- `setMuted(value: boolean)`
- `setVolume(value: number)`
You can use the provided `wrapNativeStorage` method to have that come from `localStorage`:
```typescript
import { AudioPlayr, wrapNativeStorage } from "audioplayr";
const audioPlayer = new AudioPlayr({
storage: localStorage,
storage: wrapNativeStorage(localStorage),
});

@@ -59,7 +70,5 @@ ```

- `"muted"`: Whether sounds are muted.
- `"volume"`: Global sound volume.
- `"muted"`
- `"volume"`
See [`Storage.ts`](./src/Storage.ts) for the `AudioSetting` enum and `IAudioSettingsStorage` interface.
### `play`

@@ -188,28 +197,8 @@

After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo/):
This repository is a portion of the [EightBittr monorepo](https://raw.githubusercontent.com/FullScreenShenanigans/EightBittr).
See its [docs/Development.md](../../docs/Development.md) for details on how to get started. 💖
```
git clone https://github.com/<your-name-here>/AudioPlayr
cd AudioPlayr
npm install
yarn run setup
yarn run verify
```
### Running Tests
- `yarn run setup` creates a few auto-generated setup files locally.
- `yarn run verify` builds, lints, and runs tests.
### Building
```shell
yarn run watch
```
Source files are written under `src/` in TypeScript and compile in-place to JavaScript files.
`yarn run watch` will directly run the TypeScript compiler on source files in watch mode.
Use it in the background while developing to keep the compiled files up-to-date.
#### Running Tests
```shell
yarn run test

@@ -221,6 +210,7 @@ ```

Whenever you add, remove, or rename a `*.test.t*` file under `src/`, `watch` will re-run `yarn run test:setup` to regenerate the list of static test files in `test/index.html`.
You can open that file in a browser to debug through the tests.
You can open that file in a browser to debug through the tests, or run `yarn test:run` to run them in headless Chrome.
<!-- Maps -->
<!-- /Maps -->
<!-- /Development -->

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc