@audiowalk/sdk 1.0.0 → 1.0.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/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@audiowalk/sdk",
3
- "version": "1.0.0",
4
- "description": "",
3
+ "version": "1.0.2",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/audiowalk-cz/components.git"
7
+ },
5
8
  "main": "dist/index.js",
6
9
  "scripts": {
7
10
  "dev": "tsc -w",
8
- "build": "tsc"
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
13
+ "release:patch": "npm version patch && git push && npm publish --access public"
9
14
  },
10
15
  "author": "",
11
16
  "license": "ISC",
@@ -15,4 +20,4 @@
15
20
  "dependencies": {
16
21
  "rxjs": "^7.8.1"
17
22
  }
18
- }
23
+ }
@@ -1,36 +0,0 @@
1
- name: Publish NPM package
2
-
3
- on:
4
- push:
5
- branches:
6
- - release
7
-
8
- jobs:
9
- publish:
10
- runs-on: ubuntu-latest
11
- permissions:
12
- contents: read
13
- packages: write
14
-
15
- steps:
16
- - name: Checkout code
17
- uses: actions/checkout@v4
18
-
19
- - name: Setup Node.js
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: "22.x"
23
- registry-url: "https://registry.npmjs.org"
24
- cache: "npm"
25
- cache-dependency-path: package-lock.json
26
-
27
- - name: Install dependencies
28
- run: npm ci
29
-
30
- - name: Build
31
- run: npm run build
32
-
33
- - name: Publish
34
- run: npm publish --access public
35
- env:
36
- NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH_TOKEN}}
package/dist/main.d.ts DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=main.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
package/dist/main.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,5 +0,0 @@
1
- /// <reference no-default-lib="true"/>
2
- /// <reference lib="esnext" />
3
- /// <reference lib="webworker" />
4
- export type {};
5
- //# sourceMappingURL=service-worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service-worker.d.ts","sourceRoot":"","sources":["../src/service-worker.ts"],"names":[],"mappings":";;;AAIA,YAAY,EAAE,CAAC"}
@@ -1,58 +0,0 @@
1
- "use strict";
2
- /// <reference lib="esnext" />
3
- /// <reference lib="webworker" />
4
- /// <reference no-default-lib="true"/>
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- function install() {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const res = yield fetch("audiowalk.json");
18
- const config = yield res.json();
19
- const cache = yield caches.open(`audiowalk-v${config.version}`);
20
- });
21
- }
22
- function clearCache() {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const keys = yield caches.keys();
25
- yield Promise.all(keys.map((key) => caches.delete(key)));
26
- });
27
- }
28
- function updateCache() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const res = yield fetch("audiowalk.json");
31
- const config = yield res.json();
32
- const cache = yield caches.open(`audiowalk-v${config.version}`);
33
- const keys = yield cache.keys();
34
- });
35
- }
36
- function checkUpdate() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const res = yield fetch("audiowalk.json");
39
- const config = yield res.json();
40
- const cache = yield caches.open(`audiowalk-v${config.version}`);
41
- });
42
- }
43
- function checkCache() {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return false;
46
- });
47
- }
48
- self.addEventListener("install", (event) => { });
49
- self.addEventListener("fetch", (event) => {
50
- const request = event.request;
51
- event.respondWith(caches.match(request).then((response) => {
52
- return response || fetch(request);
53
- }));
54
- });
55
- self.addEventListener("activate", (event) => { });
56
- self.addEventListener("message", (event) => {
57
- // TODO: Implement message handler
58
- });
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./player/player-controller";
@@ -1,169 +0,0 @@
1
- import { BehaviorSubject, combineLatest, map, Subject } from "rxjs";
2
-
3
- export interface PlayerControllerOptions {
4
- playOnInit?: boolean;
5
- autoSave?: boolean;
6
- }
7
-
8
- export enum PlayerStatus {
9
- "playing" = "playing",
10
- "paused" = "paused",
11
- "ended" = "ended",
12
- }
13
-
14
- export class PlayerController {
15
- public readonly onPlay = new Subject<void>();
16
- public readonly onPause = new Subject<void>();
17
- public readonly onStop = new Subject<void>();
18
-
19
- public readonly currentTime = new BehaviorSubject<number>(0);
20
- public readonly totalTime = new BehaviorSubject<number>(0);
21
- public readonly progress = combineLatest([this.currentTime, this.totalTime]).pipe(
22
- map(([currentTime, totalTime]) => currentTime / totalTime)
23
- );
24
-
25
- public readonly status = new BehaviorSubject<PlayerStatus | null>(null);
26
-
27
- public readonly playing = this.status.pipe(map((status) => status === "playing"));
28
-
29
- private file?: string;
30
-
31
- constructor(private readonly playerElement: HTMLAudioElement, private options: PlayerControllerOptions = {}) {
32
- navigator.mediaSession.setActionHandler("play", () => this.play());
33
- navigator.mediaSession.setActionHandler("pause", () => this.pause());
34
- navigator.mediaSession.setActionHandler("seekbackward", () => this.back());
35
- navigator.mediaSession.setActionHandler("seekforward", () => this.forward());
36
- navigator.mediaSession.setActionHandler("previoustrack", () => this.back());
37
- navigator.mediaSession.setActionHandler("nexttrack", () => this.forward());
38
- navigator.mediaSession.setActionHandler("seekto", (details) => {
39
- // The fastSeek dictionary member will be true if the seek action is being called
40
- // multiple times as part of a sequence and this is not the last call in that sequence.
41
- if (details.fastSeek !== true && details.seekTime) this.seekTo(details.seekTime);
42
- });
43
-
44
- this.status.subscribe((status) => {
45
- switch (status) {
46
- case "playing":
47
- navigator.mediaSession.playbackState = "playing";
48
- break;
49
- case "paused":
50
- navigator.mediaSession.playbackState = "paused";
51
- break;
52
-
53
- default:
54
- case "ended":
55
- navigator.mediaSession.playbackState = "none";
56
- break;
57
- }
58
- });
59
-
60
- this.playerElement.addEventListener("play", () => {
61
- this.onPlay.next();
62
- this.status.next(PlayerStatus.playing);
63
- });
64
-
65
- this.playerElement.addEventListener("pause", () => {
66
- this.onPause.next();
67
- this.status.next(PlayerStatus.paused);
68
- });
69
-
70
- this.playerElement.addEventListener("ended", () => {
71
- this.onStop.next();
72
- this.status.next(PlayerStatus.ended);
73
- });
74
-
75
- this.playerElement.addEventListener("loadedmetadata", (event) => {
76
- if (this.playerElement.duration) {
77
- this.totalTime.next(this.playerElement.duration);
78
- }
79
- });
80
-
81
- this.playerElement.addEventListener("timeupdate", () => {
82
- navigator.mediaSession.setPositionState({
83
- duration: this.playerElement.duration,
84
- playbackRate: this.playerElement.playbackRate,
85
- position: this.playerElement.currentTime,
86
- });
87
-
88
- this.currentTime.next(this.playerElement.currentTime);
89
-
90
- if (this.playerElement.duration) {
91
- this.totalTime.next(this.playerElement.duration);
92
- }
93
-
94
- this.savePosition(this.playerElement.currentTime);
95
- });
96
- }
97
-
98
- open(file: string, metadata: MediaMetadataInit) {
99
- this.file = file;
100
-
101
- navigator.mediaSession.metadata = new MediaMetadata(metadata);
102
-
103
- const position = localStorage.getItem(`progress-${this.file}`);
104
- if (position && this.options.autoSave) this.playerElement.currentTime = parseFloat(position);
105
-
106
- if (this.options.playOnInit) this.playerElement.play();
107
- }
108
-
109
- close() {
110
- this.file = undefined;
111
- this.playerElement.pause();
112
- this.playerElement.src = "";
113
-
114
- navigator.mediaSession.setActionHandler("play", null);
115
- navigator.mediaSession.setActionHandler("pause", null);
116
- navigator.mediaSession.setActionHandler("previoustrack", null);
117
- navigator.mediaSession.setActionHandler("nexttrack", null);
118
- navigator.mediaSession.playbackState = "none";
119
- navigator.mediaSession.metadata = null;
120
- }
121
-
122
- play() {
123
- if (!this.file) throw new Error("No file opened");
124
-
125
- this.log("Called play");
126
- this.playerElement?.play();
127
- }
128
-
129
- pause() {
130
- if (!this.file) throw new Error("No file opened");
131
- this.log("Called pause");
132
- this.playerElement?.pause();
133
- }
134
-
135
- seekTo(seconds: number) {
136
- if (!this.file) throw new Error("No file opened");
137
-
138
- this.log("Called seekTo");
139
- this.playerElement.currentTime = seconds;
140
- }
141
-
142
- back() {
143
- if (!this.file) throw new Error("No file opened");
144
-
145
- const position = this.playerElement.currentTime;
146
- this.seekTo(Math.max(position - 10, 0));
147
- }
148
-
149
- forward() {
150
- if (!this.file) throw new Error("No file opened");
151
-
152
- const position = this.playerElement.currentTime;
153
- const duration = this.playerElement.duration;
154
- this.seekTo(duration && duration > 0 ? Math.min(position + 10, duration) : position + 10);
155
- }
156
-
157
- private savePosition(currentTime: number) {
158
- if (!this.file) return;
159
- localStorage.setItem(`progress-${this.file}`, String(currentTime));
160
- }
161
-
162
- private log(message: string) {
163
- const time = this.playerElement?.currentTime ? Math.round(this.playerElement?.currentTime) : null;
164
-
165
- if (time) message += ` @${time}s`;
166
-
167
- console.log(`[PlayerController] ${message}`);
168
- }
169
- }