@audiowalk/sdk 1.1.2 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./player/player-controller";
2
+ export * from "./storage/local-storage";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./player/player-controller";
2
+ export * from "./storage/local-storage";
@@ -19,15 +19,16 @@ export declare class PlayerController {
19
19
  readonly progress: import("rxjs").Observable<number>;
20
20
  readonly status: BehaviorSubject<PlayerStatus | null>;
21
21
  readonly playing: import("rxjs").Observable<boolean>;
22
- private file?;
22
+ private localStorage;
23
23
  constructor(playerElement: HTMLAudioElement, options?: PlayerControllerOptions);
24
- open(file: string, metadata: MediaMetadataInit): void;
24
+ open(file: string): Promise<void>;
25
+ setMetadata(metadata: MediaMetadataInit): void;
25
26
  close(): void;
26
27
  play(): void;
27
28
  pause(): void;
28
29
  seekTo(seconds: number): void;
29
- back(): void;
30
- forward(): void;
30
+ back(seconds?: number): void;
31
+ forward(seconds?: number): void;
31
32
  private savePosition;
32
33
  private log;
33
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"player-controller.d.ts","sourceRoot":"","sources":["../../src/player/player-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAsB,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpE,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC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,0BAAkC;IAC7D,SAAgB,SAAS,0BAAkC;IAC3D,SAAgB,QAAQ,oCAEtB;IAEF,SAAgB,MAAM,uCAAkD;IAExE,SAAgB,OAAO,qCAA2D;IAElF,OAAO,CAAC,YAAY,CAAsB;gBAEb,aAAa,EAAE,gBAAgB,EAAU,OAAO,GAAE,uBAA4B;IAmErG,IAAI,CAAC,IAAI,EAAE,MAAM;IASvB,WAAW,CAAC,QAAQ,EAAE,iBAAiB;IAIvC,KAAK;IAYL,IAAI;IAOJ,KAAK;IAML,MAAM,CAAC,OAAO,EAAE,MAAM;IAOtB,IAAI,CAAC,OAAO,GAAE,MAAW;IAOzB,OAAO,CAAC,OAAO,GAAE,MAAW;YAQd,YAAY;IAK1B,OAAO,CAAC,GAAG;CAOZ"}
@@ -1,4 +1,5 @@
1
1
  import { BehaviorSubject, combineLatest, map, Subject } from "rxjs";
2
+ import { LocalStorage } from "../storage/local-storage";
2
3
  export var PlayerStatus;
3
4
  (function (PlayerStatus) {
4
5
  PlayerStatus["playing"] = "playing";
@@ -16,7 +17,7 @@ export class PlayerController {
16
17
  progress = combineLatest([this.currentTime, this.totalTime]).pipe(map(([currentTime, totalTime]) => currentTime / totalTime));
17
18
  status = new BehaviorSubject(null);
18
19
  playing = this.status.pipe(map((status) => status === "playing"));
19
- file;
20
+ localStorage = new LocalStorage();
20
21
  constructor(playerElement, options = {}) {
21
22
  this.playerElement = playerElement;
22
23
  this.options = options;
@@ -29,7 +30,7 @@ export class PlayerController {
29
30
  navigator.mediaSession.setActionHandler("seekto", (details) => {
30
31
  // The fastSeek dictionary member will be true if the seek action is being called
31
32
  // multiple times as part of a sequence and this is not the last call in that sequence.
32
- if (details.fastSeek !== true && details.seekTime)
33
+ if (details.fastSeek !== true && details.seekTime !== undefined)
33
34
  this.seekTo(details.seekTime);
34
35
  });
35
36
  this.status.subscribe((status) => {
@@ -65,7 +66,7 @@ export class PlayerController {
65
66
  });
66
67
  this.playerElement.addEventListener("timeupdate", () => {
67
68
  navigator.mediaSession.setPositionState({
68
- duration: this.playerElement.duration,
69
+ duration: Number.isNaN(this.playerElement.duration) ? 0 : this.playerElement.duration,
69
70
  playbackRate: this.playerElement.playbackRate,
70
71
  position: this.playerElement.currentTime,
71
72
  });
@@ -76,17 +77,18 @@ export class PlayerController {
76
77
  this.savePosition(this.playerElement.currentTime);
77
78
  });
78
79
  }
79
- open(file, metadata) {
80
- this.file = file;
81
- navigator.mediaSession.metadata = new MediaMetadata(metadata);
82
- const position = localStorage.getItem(`progress-${this.file}`);
80
+ async open(file) {
81
+ this.playerElement.src = file;
82
+ const position = await this.localStorage.get(`progress-${this.playerElement.src}`);
83
83
  if (position && this.options.autoSave)
84
84
  this.playerElement.currentTime = parseFloat(position);
85
85
  if (this.options.playOnInit)
86
- this.playerElement.play();
86
+ await this.playerElement.play();
87
+ }
88
+ setMetadata(metadata) {
89
+ navigator.mediaSession.metadata = new MediaMetadata(metadata);
87
90
  }
88
91
  close() {
89
- this.file = undefined;
90
92
  this.playerElement.pause();
91
93
  this.playerElement.src = "";
92
94
  navigator.mediaSession.setActionHandler("play", null);
@@ -97,40 +99,40 @@ export class PlayerController {
97
99
  navigator.mediaSession.metadata = null;
98
100
  }
99
101
  play() {
100
- if (!this.file)
102
+ if (!this.playerElement.src)
101
103
  throw new Error("No file opened");
102
104
  this.log("Called play");
103
105
  this.playerElement?.play();
104
106
  }
105
107
  pause() {
106
- if (!this.file)
108
+ if (!this.playerElement.src)
107
109
  throw new Error("No file opened");
108
110
  this.log("Called pause");
109
111
  this.playerElement?.pause();
110
112
  }
111
113
  seekTo(seconds) {
112
- if (!this.file)
114
+ if (!this.playerElement.src)
113
115
  throw new Error("No file opened");
114
116
  this.log("Called seekTo");
115
117
  this.playerElement.currentTime = seconds;
116
118
  }
117
- back() {
118
- if (!this.file)
119
+ back(seconds = 10) {
120
+ if (!this.playerElement.src)
119
121
  throw new Error("No file opened");
120
122
  const position = this.playerElement.currentTime;
121
- this.seekTo(Math.max(position - 10, 0));
123
+ this.seekTo(Math.max(position - seconds, 0));
122
124
  }
123
- forward() {
124
- if (!this.file)
125
+ forward(seconds = 10) {
126
+ if (!this.playerElement.src)
125
127
  throw new Error("No file opened");
126
128
  const position = this.playerElement.currentTime;
127
129
  const duration = this.playerElement.duration;
128
- this.seekTo(duration && duration > 0 ? Math.min(position + 10, duration) : position + 10);
130
+ this.seekTo(duration && duration > 0 ? Math.min(position + seconds, duration) : position + seconds);
129
131
  }
130
- savePosition(currentTime) {
131
- if (!this.file)
132
+ async savePosition(currentTime) {
133
+ if (!this.playerElement.src)
132
134
  return;
133
- localStorage.setItem(`progress-${this.file}`, String(currentTime));
135
+ await this.localStorage.set(`progress-${this.playerElement.src}`, String(currentTime));
134
136
  }
135
137
  log(message) {
136
138
  const time = this.playerElement?.currentTime ? Math.round(this.playerElement?.currentTime) : null;
@@ -0,0 +1,11 @@
1
+ export interface LocalStorageOptions {
2
+ prefix?: string;
3
+ }
4
+ export declare class LocalStorage {
5
+ private options;
6
+ constructor(options?: Partial<LocalStorageOptions>);
7
+ get(key: string): Promise<string | null>;
8
+ set(key: string, value: any): Promise<void>;
9
+ private getPrefixedKey;
10
+ }
11
+ //# sourceMappingURL=local-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/storage/local-storage.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,YAAY;IACX,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAExD,GAAG,CAAC,GAAG,EAAE,MAAM;IAIf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;IAIjC,OAAO,CAAC,cAAc;CAQvB"}
@@ -0,0 +1,19 @@
1
+ export class LocalStorage {
2
+ options;
3
+ constructor(options = {}) {
4
+ this.options = options;
5
+ }
6
+ async get(key) {
7
+ return window.localStorage.getItem(this.getPrefixedKey(key));
8
+ }
9
+ async set(key, value) {
10
+ return window.localStorage.setItem(this.getPrefixedKey(key), value);
11
+ }
12
+ getPrefixedKey(key) {
13
+ const keyParts = ["audiowalk"];
14
+ if (this.options.prefix)
15
+ keyParts.push(this.options.prefix);
16
+ keyParts.push(key);
17
+ return keyParts.join("-");
18
+ }
19
+ }
package/package.json CHANGED
@@ -1,23 +1,11 @@
1
1
  {
2
2
  "name": "@audiowalk/sdk",
3
- "version": "1.1.2",
3
+ "version": "1.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/audiowalk-cz/components.git"
7
7
  },
8
- "exports": {
9
- ".": {
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.js"
12
- },
13
- "./package.json": "./package.json",
14
- "./angular": {
15
- "types": "./angular/dist/index.d.ts",
16
- "esm2022": "./angular/dist/esm2022/audiowalk-components.mjs",
17
- "esm": "./angular/dist/esm2022/audiowalk-components.mjs",
18
- "default": "./angular/dist/fesm2022/audiowalk-components.mjs"
19
- }
20
- },
8
+ "exports": "./dist/index.js",
21
9
  "files": [
22
10
  "dist",
23
11
  "angular/dist"
@@ -25,9 +13,7 @@
25
13
  "type": "module",
26
14
  "scripts": {
27
15
  "dev": "tsc -w",
28
- "build": "concurrently --kill-others-on-fail --names core,angular \"npm run build:core\" \"npm run build:angular\"",
29
- "build:core": "tsc",
30
- "build:angular": "cd angular && npm run build",
16
+ "build": "tsc",
31
17
  "prepublishOnly": "npm run build",
32
18
  "release:patch": "git switch master && npm version patch && git switch release && git merge master --ff-only && git push --follow-tags && git switch master && git push",
33
19
  "release:minor": "git switch master && npm version minor && git switch release && git merge master --ff-only && git push --follow-tags && git switch master && git push",
@@ -1,3 +0,0 @@
1
- # Audiowalk/Components
2
-
3
- Angular components for building audiowalk apps
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './main';
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXVkaW93YWxrLWFuZ3VsYXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYXVkaW93YWxrLWFuZ3VsYXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLFFBQVEsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9tYWluJztcbiJdfQ==
@@ -1,2 +0,0 @@
1
- export const DUMMY_EXPORT = 5;
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sQ0FBQyxNQUFNLFlBQVksR0FBRyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY29uc3QgRFVNTVlfRVhQT1JUID0gNTtcbiJdfQ==
@@ -1,8 +0,0 @@
1
- const DUMMY_EXPORT = 5;
2
-
3
- /**
4
- * Generated bundle index. Do not edit.
5
- */
6
-
7
- export { DUMMY_EXPORT };
8
- //# sourceMappingURL=audiowalk-angular.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"audiowalk-angular.mjs","sources":["../../src/main.ts","../../src/audiowalk-angular.ts"],"sourcesContent":["export const DUMMY_EXPORT = 5;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './main';\n"],"names":[],"mappings":"AAAO,MAAM,YAAY,GAAG;;ACA5B;;AAEG;;;;"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- /// <amd-module name="@audiowalk/angular" />
5
- export * from './main';
@@ -1 +0,0 @@
1
- export declare const DUMMY_EXPORT = 5;